Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-conte.../plugins/wordpres.../admin/tracking
File: class-tracking.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPSEO plugin file.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\Admin\Tracking
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
use Yoast\WP\SEO\Analytics\Application\Missing_Indexables_Collector;
[7] Fix | Delete
use Yoast\WP\SEO\Analytics\Application\To_Be_Cleaned_Indexables_Collector;
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* This class handles the tracking routine.
[11] Fix | Delete
*/
[12] Fix | Delete
class WPSEO_Tracking implements WPSEO_WordPress_Integration {
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* The tracking option name.
[16] Fix | Delete
*
[17] Fix | Delete
* @var string
[18] Fix | Delete
*/
[19] Fix | Delete
protected $option_name = 'wpseo_tracking_last_request';
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* The limit for the option.
[23] Fix | Delete
*
[24] Fix | Delete
* @var int
[25] Fix | Delete
*/
[26] Fix | Delete
protected $threshold = 0;
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* The endpoint to send the data to.
[30] Fix | Delete
*
[31] Fix | Delete
* @var string
[32] Fix | Delete
*/
[33] Fix | Delete
protected $endpoint = '';
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* The current time.
[37] Fix | Delete
*
[38] Fix | Delete
* @var int
[39] Fix | Delete
*/
[40] Fix | Delete
private $current_time;
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* WPSEO_Tracking constructor.
[44] Fix | Delete
*
[45] Fix | Delete
* @param string $endpoint The endpoint to send the data to.
[46] Fix | Delete
* @param int $threshold The limit for the option.
[47] Fix | Delete
*/
[48] Fix | Delete
public function __construct( $endpoint, $threshold ) {
[49] Fix | Delete
if ( ! $this->tracking_enabled() ) {
[50] Fix | Delete
return;
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
$this->endpoint = $endpoint;
[54] Fix | Delete
$this->threshold = $threshold;
[55] Fix | Delete
$this->current_time = time();
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Registers all hooks to WordPress.
[60] Fix | Delete
*
[61] Fix | Delete
* @return void
[62] Fix | Delete
*/
[63] Fix | Delete
public function register_hooks() {
[64] Fix | Delete
if ( ! $this->tracking_enabled() ) {
[65] Fix | Delete
return;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
// Send tracking data on `admin_init`.
[69] Fix | Delete
add_action( 'admin_init', [ $this, 'send' ], 1 );
[70] Fix | Delete
[71] Fix | Delete
// Add an action hook that will be triggered at the specified time by `wp_schedule_single_event()`.
[72] Fix | Delete
add_action( 'wpseo_send_tracking_data_after_core_update', [ $this, 'send' ] );
[73] Fix | Delete
// Call `wp_schedule_single_event()` after a WordPress core update.
[74] Fix | Delete
add_action( 'upgrader_process_complete', [ $this, 'schedule_tracking_data_sending' ], 10, 2 );
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* Schedules a new sending of the tracking data after a WordPress core update.
[79] Fix | Delete
*
[80] Fix | Delete
* @param bool|WP_Upgrader $upgrader Optional. WP_Upgrader instance or false.
[81] Fix | Delete
* Depending on context, it might be a Theme_Upgrader,
[82] Fix | Delete
* Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader.
[83] Fix | Delete
* instance. Default false.
[84] Fix | Delete
* @param array $data Array of update data.
[85] Fix | Delete
*
[86] Fix | Delete
* @return void
[87] Fix | Delete
*/
[88] Fix | Delete
public function schedule_tracking_data_sending( $upgrader = false, $data = [] ) {
[89] Fix | Delete
// Return if it's not a WordPress core update.
[90] Fix | Delete
if ( ! $upgrader || ! isset( $data['type'] ) || $data['type'] !== 'core' ) {
[91] Fix | Delete
return;
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
/*
[95] Fix | Delete
* To uniquely identify the scheduled cron event, `wp_next_scheduled()`
[96] Fix | Delete
* needs to receive the same arguments as those used when originally
[97] Fix | Delete
* scheduling the event otherwise it will always return false.
[98] Fix | Delete
*/
[99] Fix | Delete
if ( ! wp_next_scheduled( 'wpseo_send_tracking_data_after_core_update', [ true ] ) ) {
[100] Fix | Delete
/*
[101] Fix | Delete
* Schedule sending of data tracking 6 hours after a WordPress core
[102] Fix | Delete
* update. Pass a `true` parameter for the callback `$force` argument.
[103] Fix | Delete
*/
[104] Fix | Delete
wp_schedule_single_event( ( time() + ( HOUR_IN_SECONDS * 6 ) ), 'wpseo_send_tracking_data_after_core_update', [ true ] );
[105] Fix | Delete
}
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
/**
[109] Fix | Delete
* Sends the tracking data.
[110] Fix | Delete
*
[111] Fix | Delete
* @param bool $force Whether to send the tracking data ignoring the two
[112] Fix | Delete
* weeks time threshold. Default false.
[113] Fix | Delete
*
[114] Fix | Delete
* @return void
[115] Fix | Delete
*/
[116] Fix | Delete
public function send( $force = false ) {
[117] Fix | Delete
if ( ! $this->should_send_tracking( $force ) ) {
[118] Fix | Delete
return;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
// Set a 'content-type' header of 'application/json'.
[122] Fix | Delete
$tracking_request_args = [
[123] Fix | Delete
'headers' => [
[124] Fix | Delete
'content-type:' => 'application/json',
[125] Fix | Delete
],
[126] Fix | Delete
];
[127] Fix | Delete
[128] Fix | Delete
$collector = $this->get_collector();
[129] Fix | Delete
[130] Fix | Delete
$request = new WPSEO_Remote_Request( $this->endpoint, $tracking_request_args );
[131] Fix | Delete
$request->set_body( $collector->get_as_json() );
[132] Fix | Delete
$request->send();
[133] Fix | Delete
[134] Fix | Delete
update_option( $this->option_name, $this->current_time, 'yes' );
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* Determines whether to send the tracking data.
[139] Fix | Delete
*
[140] Fix | Delete
* Returns false if tracking is disabled or the current page is one of the
[141] Fix | Delete
* admin plugins pages. Returns true when there's no tracking data stored or
[142] Fix | Delete
* the data was sent more than two weeks ago. The two weeks interval is set
[143] Fix | Delete
* when instantiating the class.
[144] Fix | Delete
*
[145] Fix | Delete
* @param bool $ignore_time_treshhold Whether to send the tracking data ignoring
[146] Fix | Delete
* the two weeks time treshhold. Default false.
[147] Fix | Delete
*
[148] Fix | Delete
* @return bool True when tracking data should be sent.
[149] Fix | Delete
*/
[150] Fix | Delete
protected function should_send_tracking( $ignore_time_treshhold = false ) {
[151] Fix | Delete
global $pagenow;
[152] Fix | Delete
[153] Fix | Delete
// Only send tracking on the main site of a multi-site instance. This returns true on non-multisite installs.
[154] Fix | Delete
if ( is_network_admin() || ! is_main_site() ) {
[155] Fix | Delete
return false;
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
// Because we don't want to possibly block plugin actions with our routines.
[159] Fix | Delete
if ( in_array( $pagenow, [ 'plugins.php', 'plugin-install.php', 'plugin-editor.php' ], true ) ) {
[160] Fix | Delete
return false;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
$last_time = get_option( $this->option_name );
[164] Fix | Delete
[165] Fix | Delete
// When tracking data haven't been sent yet or when sending data is forced.
[166] Fix | Delete
if ( ! $last_time || $ignore_time_treshhold ) {
[167] Fix | Delete
return true;
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
return $this->exceeds_treshhold( $this->current_time - $last_time );
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* Checks if the given amount of seconds exceeds the set threshold.
[175] Fix | Delete
*
[176] Fix | Delete
* @param int $seconds The amount of seconds to check.
[177] Fix | Delete
*
[178] Fix | Delete
* @return bool True when seconds is bigger than threshold.
[179] Fix | Delete
*/
[180] Fix | Delete
protected function exceeds_treshhold( $seconds ) {
[181] Fix | Delete
return ( $seconds > $this->threshold );
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
/**
[185] Fix | Delete
* Returns the collector for collecting the data.
[186] Fix | Delete
*
[187] Fix | Delete
* @return WPSEO_Collector The instance of the collector.
[188] Fix | Delete
*/
[189] Fix | Delete
public function get_collector() {
[190] Fix | Delete
$collector = new WPSEO_Collector();
[191] Fix | Delete
$collector->add_collection( new WPSEO_Tracking_Default_Data() );
[192] Fix | Delete
$collector->add_collection( new WPSEO_Tracking_Server_Data() );
[193] Fix | Delete
$collector->add_collection( new WPSEO_Tracking_Theme_Data() );
[194] Fix | Delete
$collector->add_collection( new WPSEO_Tracking_Plugin_Data() );
[195] Fix | Delete
$collector->add_collection( new WPSEO_Tracking_Settings_Data() );
[196] Fix | Delete
$collector->add_collection( new WPSEO_Tracking_Addon_Data() );
[197] Fix | Delete
$collector->add_collection( YoastSEO()->classes->get( Missing_Indexables_Collector::class ) );
[198] Fix | Delete
$collector->add_collection( YoastSEO()->classes->get( To_Be_Cleaned_Indexables_Collector::class ) );
[199] Fix | Delete
[200] Fix | Delete
return $collector;
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
/**
[204] Fix | Delete
* See if we should run tracking at all.
[205] Fix | Delete
*
[206] Fix | Delete
* @return bool True when we can track, false when we can't.
[207] Fix | Delete
*/
[208] Fix | Delete
private function tracking_enabled() {
[209] Fix | Delete
// Check if we're allowing tracking.
[210] Fix | Delete
$tracking = WPSEO_Options::get( 'tracking' );
[211] Fix | Delete
[212] Fix | Delete
if ( $tracking === false ) {
[213] Fix | Delete
return false;
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
// Save this state.
[217] Fix | Delete
if ( $tracking === null ) {
[218] Fix | Delete
/**
[219] Fix | Delete
* Filter: 'wpseo_enable_tracking' - Enables the data tracking of Yoast SEO Premium and add-ons.
[220] Fix | Delete
*
[221] Fix | Delete
* @param string $is_enabled The enabled state. Default is false.
[222] Fix | Delete
*/
[223] Fix | Delete
$tracking = apply_filters( 'wpseo_enable_tracking', false );
[224] Fix | Delete
[225] Fix | Delete
WPSEO_Options::set( 'tracking', $tracking );
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
if ( $tracking === false ) {
[229] Fix | Delete
return false;
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
if ( ! YoastSEO()->helpers->environment->is_production_mode() ) {
[233] Fix | Delete
return false;
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
return true;
[237] Fix | Delete
}
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function