diff --git a/code-snippets/disable-custom-endpoint.php b/code-snippets/disable-custom-endpoint.php new file mode 100644 index 0000000..fa5e963 --- /dev/null +++ b/code-snippets/disable-custom-endpoint.php @@ -0,0 +1,3 @@ +init(); - if ( class_exists( 'WP_CLI' ) ) { require __DIR__ . '/src/class-command.php'; \WP_CLI::add_command( 'koko-analytics', 'KokoAnalytics\Command' ); diff --git a/src/class-admin.php b/src/class-admin.php index 9aae0b3..dfac33c 100644 --- a/src/class-admin.php +++ b/src/class-admin.php @@ -134,8 +134,12 @@ public function maybe_run_endpoint_installer() return; } - $endpoint_installer = new Endpoint_Installer(); - $endpoint_installer->run(); + // do not run if KOKO_ANALYTICS_CUSTOM_ENDPOINT is defined + if ( defined( 'KOKO_ANALYTICS_CUSTOM_ENDPOINT' ) ) { + return; + } + + install_and_test_custom_endpoint(); } public function maybe_run_migrations() diff --git a/src/class-script-loader.php b/src/class-script-loader.php index d1e7212..33d6077 100644 --- a/src/class-script-loader.php +++ b/src/class-script-loader.php @@ -65,6 +65,10 @@ private function get_post_id() { } private function get_tracker_url() { + if ( defined( 'KOKO_ANALYTICS_CUSTOM_ENDPOINT' ) && KOKO_ANALYTICS_CUSTOM_ENDPOINT ) { + return site_url( KOKO_ANALYTICS_CUSTOM_ENDPOINT ); + } + // We should use site_url() here because we place the file in ABSPATH and other plugins may be filtering home_url (eg multilingual plugin) // In any case: what we use here should match what we test when creating the optimized endpoint file. return using_custom_endpoint() ? site_url( '/koko-analytics-collect.php' ) : admin_url( 'admin-ajax.php?action=koko_analytics_collect' ); diff --git a/src/functions.php b/src/functions.php index 3033c64..58c1101 100644 --- a/src/functions.php +++ b/src/functions.php @@ -173,5 +173,14 @@ function get_realtime_pageview_count( $since = null ) { } function using_custom_endpoint() { + if ( defined( 'KOKO_ANALYTICS_CUSTOM_ENDPOINT' ) ) { + return KOKO_ANALYTICS_CUSTOM_ENDPOINT; + } + return get_option( 'koko_analytics_use_custom_endpoint', false ); } + +function install_and_test_custom_endpoint() { + $endpoint_installer = new Endpoint_Installer(); + $endpoint_installer->run(); +}