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.../httpdocs/clone/wp-conte.../plugins/wordpres.../src/integrat.../watchers
File: addon-update-watcher.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations\Watchers;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
[4] Fix | Delete
use Yoast\WP\SEO\Integrations\Integration_Interface;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Enables Yoast add-on auto updates when Yoast SEO is enabled and the other way around.
[8] Fix | Delete
*
[9] Fix | Delete
* Also removes the auto-update toggles from the Yoast SEO add-ons.
[10] Fix | Delete
*/
[11] Fix | Delete
class Addon_Update_Watcher implements Integration_Interface {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* ID string used by WordPress to identify the free plugin.
[15] Fix | Delete
*
[16] Fix | Delete
* @var string
[17] Fix | Delete
*/
[18] Fix | Delete
public const WPSEO_FREE_PLUGIN_ID = 'wordpress-seo/wp-seo.php';
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* A list of Yoast add-on identifiers.
[22] Fix | Delete
*
[23] Fix | Delete
* @var string[]
[24] Fix | Delete
*/
[25] Fix | Delete
public const ADD_ON_PLUGIN_FILES = [
[26] Fix | Delete
'wordpress-seo-premium/wp-seo-premium.php',
[27] Fix | Delete
'wpseo-video/video-seo.php',
[28] Fix | Delete
'wpseo-local/local-seo.php', // When installing Local through a released zip, the path is different from the path on a dev environment.
[29] Fix | Delete
'wpseo-woocommerce/wpseo-woocommerce.php',
[30] Fix | Delete
'wpseo-news/wpseo-news.php',
[31] Fix | Delete
'acf-content-analysis-for-yoast-seo/yoast-acf-analysis.php', // When installing ACF for Yoast through a released zip, the path is different from the path on a dev environment.
[32] Fix | Delete
];
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Registers the hooks.
[36] Fix | Delete
*
[37] Fix | Delete
* @return void
[38] Fix | Delete
*/
[39] Fix | Delete
public function register_hooks() {
[40] Fix | Delete
\add_action( 'add_site_option_auto_update_plugins', [ $this, 'call_toggle_auto_updates_with_empty_array' ], 10, 2 );
[41] Fix | Delete
\add_action( 'update_site_option_auto_update_plugins', [ $this, 'toggle_auto_updates_for_add_ons' ], 10, 3 );
[42] Fix | Delete
\add_filter( 'plugin_auto_update_setting_html', [ $this, 'replace_auto_update_toggles_of_addons' ], 10, 2 );
[43] Fix | Delete
\add_action( 'activated_plugin', [ $this, 'maybe_toggle_auto_updates_for_new_install' ] );
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Returns the conditionals based on which this loadable should be active.
[48] Fix | Delete
*
[49] Fix | Delete
* @return string[] The conditionals.
[50] Fix | Delete
*/
[51] Fix | Delete
public static function get_conditionals() {
[52] Fix | Delete
return [ Admin_Conditional::class ];
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Replaces the auto-update toggle links for the Yoast add-ons
[57] Fix | Delete
* with a text explaining that toggling the Yoast SEO auto-update setting
[58] Fix | Delete
* automatically toggles the one for the setting for the add-ons as well.
[59] Fix | Delete
*
[60] Fix | Delete
* @param string $old_html The old HTML.
[61] Fix | Delete
* @param string $plugin The plugin.
[62] Fix | Delete
*
[63] Fix | Delete
* @return string The new HTML, with the auto-update toggle link replaced.
[64] Fix | Delete
*/
[65] Fix | Delete
public function replace_auto_update_toggles_of_addons( $old_html, $plugin ) {
[66] Fix | Delete
if ( ! \is_string( $old_html ) ) {
[67] Fix | Delete
return $old_html;
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
$not_a_yoast_addon = ! \in_array( $plugin, self::ADD_ON_PLUGIN_FILES, true );
[71] Fix | Delete
[72] Fix | Delete
if ( $not_a_yoast_addon ) {
[73] Fix | Delete
return $old_html;
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
$auto_updated_plugins = \get_site_option( 'auto_update_plugins' );
[77] Fix | Delete
[78] Fix | Delete
if ( $this->are_auto_updates_enabled( self::WPSEO_FREE_PLUGIN_ID, $auto_updated_plugins ) ) {
[79] Fix | Delete
return \sprintf(
[80] Fix | Delete
'<em>%s</em>',
[81] Fix | Delete
\sprintf(
[82] Fix | Delete
/* Translators: %1$s resolves to Yoast SEO. */
[83] Fix | Delete
\esc_html__( 'Auto-updates are enabled based on this setting for %1$s.', 'wordpress-seo' ),
[84] Fix | Delete
'Yoast SEO'
[85] Fix | Delete
)
[86] Fix | Delete
);
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
return \sprintf(
[90] Fix | Delete
'<em>%s</em>',
[91] Fix | Delete
\sprintf(
[92] Fix | Delete
/* Translators: %1$s resolves to Yoast SEO. */
[93] Fix | Delete
\esc_html__( 'Auto-updates are disabled based on this setting for %1$s.', 'wordpress-seo' ),
[94] Fix | Delete
'Yoast SEO'
[95] Fix | Delete
)
[96] Fix | Delete
);
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Handles the situation where the auto_update_plugins option did not previously exist.
[101] Fix | Delete
*
[102] Fix | Delete
* @param string $option The name of the option that is being created.
[103] Fix | Delete
* @param array|mixed $value The new (and first) value of the option that is being created.
[104] Fix | Delete
*
[105] Fix | Delete
* @return void
[106] Fix | Delete
*/
[107] Fix | Delete
public function call_toggle_auto_updates_with_empty_array( $option, $value ) {
[108] Fix | Delete
if ( $option !== 'auto_update_plugins' ) {
[109] Fix | Delete
return;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
$this->toggle_auto_updates_for_add_ons( $option, $value, [] );
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* Enables premium auto updates when free are enabled and the other way around.
[117] Fix | Delete
*
[118] Fix | Delete
* @param string $option The name of the option that has been updated.
[119] Fix | Delete
* @param array $new_value The new value of the `auto_update_plugins` option.
[120] Fix | Delete
* @param array $old_value The old value of the `auto_update_plugins` option.
[121] Fix | Delete
*
[122] Fix | Delete
* @return void
[123] Fix | Delete
*/
[124] Fix | Delete
public function toggle_auto_updates_for_add_ons( $option, $new_value, $old_value ) {
[125] Fix | Delete
if ( $option !== 'auto_update_plugins' ) {
[126] Fix | Delete
// If future versions of WordPress change this filter's behavior, our behavior should stay consistent.
[127] Fix | Delete
return;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
if ( ! \is_array( $old_value ) || ! \is_array( $new_value ) ) {
[131] Fix | Delete
return;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
$auto_updates_are_enabled = $this->are_auto_updates_enabled( self::WPSEO_FREE_PLUGIN_ID, $new_value );
[135] Fix | Delete
$auto_updates_were_enabled = $this->are_auto_updates_enabled( self::WPSEO_FREE_PLUGIN_ID, $old_value );
[136] Fix | Delete
[137] Fix | Delete
if ( $auto_updates_are_enabled === $auto_updates_were_enabled ) {
[138] Fix | Delete
// Auto-updates for Yoast SEO have stayed the same, so have neither been enabled or disabled.
[139] Fix | Delete
return;
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
$auto_updates_have_been_enabled = $auto_updates_are_enabled && ! $auto_updates_were_enabled;
[143] Fix | Delete
[144] Fix | Delete
if ( $auto_updates_have_been_enabled ) {
[145] Fix | Delete
$this->enable_auto_updates_for_addons( $new_value );
[146] Fix | Delete
return;
[147] Fix | Delete
}
[148] Fix | Delete
else {
[149] Fix | Delete
$this->disable_auto_updates_for_addons( $new_value );
[150] Fix | Delete
return;
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
if ( ! $auto_updates_are_enabled ) {
[154] Fix | Delete
return;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
$auto_updates_have_been_removed = false;
[158] Fix | Delete
foreach ( self::ADD_ON_PLUGIN_FILES as $addon ) {
[159] Fix | Delete
if ( ! $this->are_auto_updates_enabled( $addon, $new_value ) ) {
[160] Fix | Delete
$auto_updates_have_been_removed = true;
[161] Fix | Delete
break;
[162] Fix | Delete
}
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
if ( $auto_updates_have_been_removed ) {
[166] Fix | Delete
$this->enable_auto_updates_for_addons( $new_value );
[167] Fix | Delete
}
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
/**
[171] Fix | Delete
* Trigger a change in the auto update detection whenever a new Yoast addon is activated.
[172] Fix | Delete
*
[173] Fix | Delete
* @param string $plugin The plugin that is activated.
[174] Fix | Delete
*
[175] Fix | Delete
* @return void
[176] Fix | Delete
*/
[177] Fix | Delete
public function maybe_toggle_auto_updates_for_new_install( $plugin ) {
[178] Fix | Delete
$not_a_yoast_addon = ! \in_array( $plugin, self::ADD_ON_PLUGIN_FILES, true );
[179] Fix | Delete
[180] Fix | Delete
if ( $not_a_yoast_addon ) {
[181] Fix | Delete
return;
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
$enabled_auto_updates = \get_site_option( 'auto_update_plugins' );
[185] Fix | Delete
$this->toggle_auto_updates_for_add_ons( 'auto_update_plugins', $enabled_auto_updates, [] );
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
/**
[189] Fix | Delete
* Enables auto-updates for all addons.
[190] Fix | Delete
*
[191] Fix | Delete
* @param string[] $auto_updated_plugins The current list of auto-updated plugins.
[192] Fix | Delete
*
[193] Fix | Delete
* @return void
[194] Fix | Delete
*/
[195] Fix | Delete
protected function enable_auto_updates_for_addons( $auto_updated_plugins ) {
[196] Fix | Delete
$plugins = \array_unique( \array_merge( $auto_updated_plugins, self::ADD_ON_PLUGIN_FILES ) );
[197] Fix | Delete
\update_site_option( 'auto_update_plugins', $plugins );
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* Disables auto-updates for all addons.
[202] Fix | Delete
*
[203] Fix | Delete
* @param string[] $auto_updated_plugins The current list of auto-updated plugins.
[204] Fix | Delete
*
[205] Fix | Delete
* @return void
[206] Fix | Delete
*/
[207] Fix | Delete
protected function disable_auto_updates_for_addons( $auto_updated_plugins ) {
[208] Fix | Delete
$plugins = \array_values( \array_diff( $auto_updated_plugins, self::ADD_ON_PLUGIN_FILES ) );
[209] Fix | Delete
\update_site_option( 'auto_update_plugins', $plugins );
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
/**
[213] Fix | Delete
* Checks whether auto updates for a plugin are enabled.
[214] Fix | Delete
*
[215] Fix | Delete
* @param string $plugin_id The plugin ID.
[216] Fix | Delete
* @param array $auto_updated_plugins The array of auto updated plugins.
[217] Fix | Delete
*
[218] Fix | Delete
* @return bool Whether auto updates for a plugin are enabled.
[219] Fix | Delete
*/
[220] Fix | Delete
protected function are_auto_updates_enabled( $plugin_id, $auto_updated_plugins ) {
[221] Fix | Delete
if ( $auto_updated_plugins === false || ! \is_array( $auto_updated_plugins ) ) {
[222] Fix | Delete
return false;
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
return \in_array( $plugin_id, $auto_updated_plugins, true );
[226] Fix | Delete
}
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function