| Server IP : 167.99.224.18 / Your IP : 216.73.216.136 Web Server : Apache/2.4.41 (Ubuntu) System : Linux wordpress-ubuntu-s-1vcpu-1gb-nyc1-01 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.0.25 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/wp-content/plugins-old/plausible-analytics/src/Admin/ |
Upload File : |
<?php
/**
* Plausible Analytics | Admin Actions.
*
* @since 1.0.0
* @package WordPress
* @subpackage Plausible Analytics
*/
namespace Plausible\Analytics\WP\Admin;
use Plausible\Analytics\WP\Helpers;
class Actions {
/**
* Constructor.
*
* @since 1.0.0
* @access public
* @return void
*/
public function __construct() {
add_action( 'admin_enqueue_scripts', [ $this, 'register_assets' ] );
add_action( 'admin_init', [ $this, 'maybe_redirect_to_wizard' ] );
}
/**
* Register Assets.
*
* @since 1.0.0
* @since 1.3.0 Don't load CSS admin-wide. JS needs to load admin-wide, since we're throwing admin-wide, dismissable notices.
* @access public
* @return void
*/
public function register_assets( $current_page ) {
if ( $current_page === 'settings_page_plausible_analytics' || $current_page === 'dashboard_page_plausible_analytics_statistics' ) {
wp_enqueue_style(
'plausible-admin',
PLAUSIBLE_ANALYTICS_PLUGIN_URL . 'assets/dist/css/plausible-admin.css',
'',
filemtime( PLAUSIBLE_ANALYTICS_PLUGIN_DIR . 'assets/dist/css/plausible-admin.css' ),
'all'
);
}
wp_register_script(
'plausible-admin',
PLAUSIBLE_ANALYTICS_PLUGIN_URL . 'assets/dist/js/plausible-admin.js',
'',
filemtime( PLAUSIBLE_ANALYTICS_PLUGIN_DIR . 'assets/dist/js/plausible-admin.js' ),
[ 'in_footer' => true ]
);
wp_localize_script( 'plausible-admin', 'plausible_analytics_i18n', [ 'connected' => __( 'Connected', 'plausible-analytics' ) ] );
wp_enqueue_script( 'plausible-admin' );
wp_add_inline_script( 'plausible-admin', 'var plausible_analytics_hosted_domain = "' . Helpers::get_hosted_domain_url() . '";' );
}
/**
* Redirect to Configuration Wizard on first boot.
*
* @return void
*/
public function maybe_redirect_to_wizard() {
// Make sure it only runs when requested by (an admin in) a browser.
if ( wp_doing_ajax() || wp_doing_cron() || ! current_user_can( 'manage_options' ) ) {
return;
}
// If we're already on the Settings page, there's no need to redirect.
if ( array_key_exists( 'page', $_GET ) && $_GET[ 'page' ] === 'plausible_analytics' ) {
return;
}
// Self-hosters should never be redirected to the settings screen, because the wizard isn't shown to them.
$wizard_done = get_option( 'plausible_analytics_wizard_done', false ) || ! empty( Helpers::get_settings()[ 'self_hosted_domain' ] );
if ( ! $wizard_done ) {
$url = admin_url( 'options-general.php?page=plausible_analytics#welcome_slide' );
wp_redirect( $url );
exit;
}
}
}