Skip to content

Commit

Permalink
Added: self hosted shared link option. To do: write migration script.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan0sz committed Jan 30, 2024
1 parent ceec2c3 commit f23e2e7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
56 changes: 47 additions & 9 deletions src/Admin/Settings/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ class Page extends API {
public function __construct() {
$settings = Helpers::get_settings();
$domain = Helpers::get_domain();
$api_token = ! empty( $settings[ 'api_token' ] ) ? $settings[ 'api_token' ] : '';
$self_hosted_domain = defined(
'PLAUSIBLE_SELF_HOSTED_DOMAIN'
) ? PLAUSIBLE_SELF_HOSTED_DOMAIN : ( ! empty( $settings[ 'self_hosted_domain' ] ) ? $settings[ 'self_hosted_domain' ] : '' );
$excluded_pages = ! empty( $settings[ 'excluded_pages' ] ) ? $settings[ 'excluded_pages' ] : '';
$self_hosted_domain = defined( 'PLAUSIBLE_SELF_HOSTED_DOMAIN' ) ? PLAUSIBLE_SELF_HOSTED_DOMAIN : $settings[ 'self_hosted_domain' ];

$this->fields = [
'general' => [
Expand Down Expand Up @@ -64,7 +60,7 @@ public function __construct() {
'label' => esc_html__( 'API Token', 'plausible-analytics' ),
'slug' => 'api_token',
'type' => 'text',
'value' => $api_token,
'value' => $settings[ 'api_token' ],
],
[
'label' => esc_html__( 'Connect', 'plausible-analytics' ),
Expand Down Expand Up @@ -221,7 +217,7 @@ public function __construct() {
'label' => esc_html__( 'Excluded pages', 'plausible-analytics' ),
'slug' => 'excluded_pages',
'type' => 'textarea',
'value' => $excluded_pages,
'value' => $settings[ 'excluded_pages' ],
'placeholder' => esc_html__(
'E.g.',
'plausible-analytics'
Expand Down Expand Up @@ -296,12 +292,12 @@ public function __construct() {
'toggle' => '',
'fields' => [
[
'label' => esc_html__( 'Domain Name', 'plausible-analytics' ),
'label' => esc_html__( 'Domain name', 'plausible-analytics' ),
'slug' => 'self_hosted_domain',
'type' => 'text',
'value' => $self_hosted_domain,
'placeholder' => 'e.g. ' . Helpers::get_domain(),
'disabled' => ! empty( Helpers::get_settings()[ 'proxy_enabled' ] ),
'disabled' => Helpers::proxy_enabled(),
],
[
'label' => __( 'Save', 'plausible-analytics' ),
Expand All @@ -311,6 +307,42 @@ public function __construct() {
],
],
],
[
'label' => esc_html__( 'View stats in your WordPress dashboard', 'plausible-analytics' ),
'slug' => 'self_hosted_shared_link',
'type' => 'group',
'desc' => sprintf(
'<ol><li>' .
__(
'<a href="%s" target="_blank">Create a secure and private shared link</a> in your Plausible account.',
'plausible-analytics'
) .
'<li>' .
__( 'Paste the shared link in the text box to view your stats in your WordPress dashboard.', 'plausible-analytics' ) .
'</li>' .
'</li></ol>',
esc_url( 'https://plausible.io/wordpress-analytics-plugin#how-to-view-your-stats-directly-in-your-wordpress-dashboard' )
),
'fields' => [
[
'label' => esc_html__( 'Shared link', 'plausible-analytics' ),
'slug' => 'self_hosted_shared_link',
'type' => 'text',
'value' => $settings[ 'self_hosted_shared_link' ],
'placeholder' => sprintf(
wp_kses( __( 'E.g. https://plausible.io/share/%s?auth=XXXXXXXXXXXX', 'plausible-analytics' ), 'post' ),
$domain
),
'disabled' => Helpers::proxy_enabled(),
],
[
'label' => __( 'Save', 'plausible-analytics' ),
'slug' => 'save-self-hosted-shared-link',
'type' => 'button',
'disabled' => Helpers::proxy_enabled(),
],
],
],
],
];

Expand All @@ -320,6 +352,11 @@ public function __construct() {
'slug' => 'self_hosted_domain_notice',
'type' => 'hook',
];
$this->fields[ 'self-hosted' ][ 1 ][ 'fields' ][] = [
'label' => '',
'slug' => 'self_hosted_shared_link_notice',
'type' => 'hook',
];
}

$this->init();
Expand Down Expand Up @@ -368,6 +405,7 @@ private function init() {
add_action( 'plausible_analytics_settings_api_connect_button', [ $this, 'connect_button' ] );
add_action( 'plausible_analytics_settings_proxy_warning', [ $this, 'proxy_warning' ] );
add_action( 'plausible_analytics_settings_self_hosted_domain_notice', [ $this, 'self_hosted_warning' ] );
add_action( 'plausible_analytics_settings_self_hosted_shared_link_notice', [ $this, 'self_hosted_warning' ] );
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Includes/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static function get_settings() {
'expand_dashboard_access' => [],
'disable_toolbar_menu' => '',
'self_hosted_domain' => '',
'self_hosted_shared_link' => '',
];

$settings = get_option( 'plausible_analytics_settings', [] );
Expand Down

0 comments on commit f23e2e7

Please sign in to comment.