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
File: class-yoast-plugin-conflict.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPSEO plugin file.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\Admin
[4] Fix | Delete
* @since 1.7.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Base class for handling plugin conflicts.
[9] Fix | Delete
*/
[10] Fix | Delete
class Yoast_Plugin_Conflict {
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* The plugins must be grouped per section.
[14] Fix | Delete
*
[15] Fix | Delete
* It's possible to check for each section if there are conflicting plugins.
[16] Fix | Delete
*
[17] Fix | Delete
* @var array
[18] Fix | Delete
*/
[19] Fix | Delete
protected $plugins = [];
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* All the current active plugins will be stored in this private var.
[23] Fix | Delete
*
[24] Fix | Delete
* @var array
[25] Fix | Delete
*/
[26] Fix | Delete
protected $all_active_plugins = [];
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* After searching for active plugins that are in $this->plugins the active plugins will be stored in this
[30] Fix | Delete
* property.
[31] Fix | Delete
*
[32] Fix | Delete
* @var array
[33] Fix | Delete
*/
[34] Fix | Delete
protected $active_conflicting_plugins = [];
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Property for holding instance of itself.
[38] Fix | Delete
*
[39] Fix | Delete
* @var Yoast_Plugin_Conflict
[40] Fix | Delete
*/
[41] Fix | Delete
protected static $instance;
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* For the use of singleton pattern. Create instance of itself and return this instance.
[45] Fix | Delete
*
[46] Fix | Delete
* @param string $class_name Give the classname to initialize. If classname is
[47] Fix | Delete
* false (empty) it will use it's own __CLASS__.
[48] Fix | Delete
*
[49] Fix | Delete
* @return Yoast_Plugin_Conflict
[50] Fix | Delete
*/
[51] Fix | Delete
public static function get_instance( $class_name = '' ) {
[52] Fix | Delete
[53] Fix | Delete
if ( is_null( self::$instance ) ) {
[54] Fix | Delete
if ( ! is_string( $class_name ) || $class_name === '' ) {
[55] Fix | Delete
$class_name = self::class;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
self::$instance = new $class_name();
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
return self::$instance;
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Setting instance, all active plugins and search for active plugins.
[66] Fix | Delete
*
[67] Fix | Delete
* Protected constructor to prevent creating a new instance of the
[68] Fix | Delete
* *Singleton* via the `new` operator from outside this class.
[69] Fix | Delete
*/
[70] Fix | Delete
protected function __construct() {
[71] Fix | Delete
// Set active plugins.
[72] Fix | Delete
$this->all_active_plugins = get_option( 'active_plugins' );
[73] Fix | Delete
[74] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
[75] Fix | Delete
if ( isset( $_GET['action'] ) && is_string( $_GET['action'] ) ) {
[76] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information and only comparing the variable in a condition.
[77] Fix | Delete
$action = wp_unslash( $_GET['action'] );
[78] Fix | Delete
if ( $action === 'deactivate' ) {
[79] Fix | Delete
$this->remove_deactivated_plugin();
[80] Fix | Delete
}
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
// Search for active plugins.
[84] Fix | Delete
$this->search_active_plugins();
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Check if there are conflicting plugins for given $plugin_section.
[89] Fix | Delete
*
[90] Fix | Delete
* @param string $plugin_section Type of plugin conflict (such as Open Graph or sitemap).
[91] Fix | Delete
*
[92] Fix | Delete
* @return bool
[93] Fix | Delete
*/
[94] Fix | Delete
public function check_for_conflicts( $plugin_section ) {
[95] Fix | Delete
[96] Fix | Delete
static $sections_checked;
[97] Fix | Delete
[98] Fix | Delete
// Return early if there are no active conflicting plugins at all.
[99] Fix | Delete
if ( empty( $this->active_conflicting_plugins ) ) {
[100] Fix | Delete
return false;
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
if ( $sections_checked === null ) {
[104] Fix | Delete
$sections_checked = [];
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
if ( ! in_array( $plugin_section, $sections_checked, true ) ) {
[108] Fix | Delete
$sections_checked[] = $plugin_section;
[109] Fix | Delete
return ( ! empty( $this->active_conflicting_plugins[ $plugin_section ] ) );
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
return false;
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* Checks for given $plugin_sections for conflicts.
[117] Fix | Delete
*
[118] Fix | Delete
* @param array $plugin_sections Set of sections.
[119] Fix | Delete
*
[120] Fix | Delete
* @return void
[121] Fix | Delete
*/
[122] Fix | Delete
public function check_plugin_conflicts( $plugin_sections ) {
[123] Fix | Delete
foreach ( $plugin_sections as $plugin_section => $readable_plugin_section ) {
[124] Fix | Delete
// Check for conflicting plugins and show error if there are conflicts.
[125] Fix | Delete
if ( $this->check_for_conflicts( $plugin_section ) ) {
[126] Fix | Delete
$this->set_error( $plugin_section, $readable_plugin_section );
[127] Fix | Delete
}
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
// List of all active sections.
[131] Fix | Delete
$sections = array_keys( $plugin_sections );
[132] Fix | Delete
// List of all sections.
[133] Fix | Delete
$all_plugin_sections = array_keys( $this->plugins );
[134] Fix | Delete
[135] Fix | Delete
/*
[136] Fix | Delete
* Get all sections that are inactive.
[137] Fix | Delete
* These plugins need to be cleared.
[138] Fix | Delete
*
[139] Fix | Delete
* This happens when Sitemaps or OpenGraph implementations toggle active/disabled.
[140] Fix | Delete
*/
[141] Fix | Delete
$inactive_sections = array_diff( $all_plugin_sections, $sections );
[142] Fix | Delete
if ( ! empty( $inactive_sections ) ) {
[143] Fix | Delete
foreach ( $inactive_sections as $section ) {
[144] Fix | Delete
array_walk( $this->plugins[ $section ], [ $this, 'clear_error' ] );
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
// For active sections clear errors for inactive plugins.
[149] Fix | Delete
foreach ( $sections as $section ) {
[150] Fix | Delete
// By default, clear errors for all plugins of the section.
[151] Fix | Delete
$inactive_plugins = $this->plugins[ $section ];
[152] Fix | Delete
[153] Fix | Delete
// If there are active plugins, filter them from being cleared.
[154] Fix | Delete
if ( isset( $this->active_conflicting_plugins[ $section ] ) ) {
[155] Fix | Delete
$inactive_plugins = array_diff( $this->plugins[ $section ], $this->active_conflicting_plugins[ $section ] );
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
array_walk( $inactive_plugins, [ $this, 'clear_error' ] );
[159] Fix | Delete
}
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
/**
[163] Fix | Delete
* Setting an error on the screen.
[164] Fix | Delete
*
[165] Fix | Delete
* @param string $plugin_section Type of conflict group (such as Open Graph or sitemap).
[166] Fix | Delete
* @param string $readable_plugin_section This is the value for the translation.
[167] Fix | Delete
*
[168] Fix | Delete
* @return void
[169] Fix | Delete
*/
[170] Fix | Delete
protected function set_error( $plugin_section, $readable_plugin_section ) {
[171] Fix | Delete
[172] Fix | Delete
$notification_center = Yoast_Notification_Center::get();
[173] Fix | Delete
[174] Fix | Delete
foreach ( $this->active_conflicting_plugins[ $plugin_section ] as $plugin_file ) {
[175] Fix | Delete
[176] Fix | Delete
$plugin_name = $this->get_plugin_name( $plugin_file );
[177] Fix | Delete
[178] Fix | Delete
$error_message = '';
[179] Fix | Delete
/* translators: %1$s: 'Facebook & Open Graph' plugin name(s) of possibly conflicting plugin(s), %2$s to Yoast SEO */
[180] Fix | Delete
$error_message .= '<p>' . sprintf( __( 'The %1$s plugin might cause issues when used in conjunction with %2$s.', 'wordpress-seo' ), '<em>' . $plugin_name . '</em>', 'Yoast SEO' ) . '</p>';
[181] Fix | Delete
$error_message .= '<p>' . sprintf( $readable_plugin_section, 'Yoast SEO', $plugin_name ) . '</p>';
[182] Fix | Delete
[183] Fix | Delete
/* translators: %s: 'Facebook' plugin name of possibly conflicting plugin */
[184] Fix | Delete
$error_message .= '<a class="button button-primary" href="' . wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=all', 'deactivate-plugin_' . $plugin_file ) . '">' . sprintf( __( 'Deactivate %s', 'wordpress-seo' ), $this->get_plugin_name( $plugin_file ) ) . '</a> ';
[185] Fix | Delete
[186] Fix | Delete
$identifier = $this->get_notification_identifier( $plugin_file );
[187] Fix | Delete
[188] Fix | Delete
// Add the message to the notifications center.
[189] Fix | Delete
$notification_center->add_notification(
[190] Fix | Delete
new Yoast_Notification(
[191] Fix | Delete
$error_message,
[192] Fix | Delete
[
[193] Fix | Delete
'type' => Yoast_Notification::ERROR,
[194] Fix | Delete
'id' => 'wpseo-conflict-' . $identifier,
[195] Fix | Delete
]
[196] Fix | Delete
)
[197] Fix | Delete
);
[198] Fix | Delete
}
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
/**
[202] Fix | Delete
* Clear the notification for a plugin.
[203] Fix | Delete
*
[204] Fix | Delete
* @param string $plugin_file Clear the optional notification for this plugin.
[205] Fix | Delete
*
[206] Fix | Delete
* @return void
[207] Fix | Delete
*/
[208] Fix | Delete
public function clear_error( $plugin_file ) {
[209] Fix | Delete
$identifier = $this->get_notification_identifier( $plugin_file );
[210] Fix | Delete
[211] Fix | Delete
$notification_center = Yoast_Notification_Center::get();
[212] Fix | Delete
$notification_center->remove_notification_by_id( 'wpseo-conflict-' . $identifier );
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
/**
[216] Fix | Delete
* Loop through the $this->plugins to check if one of the plugins is active.
[217] Fix | Delete
*
[218] Fix | Delete
* This method will store the active plugins in $this->active_plugins.
[219] Fix | Delete
*
[220] Fix | Delete
* @return void
[221] Fix | Delete
*/
[222] Fix | Delete
protected function search_active_plugins() {
[223] Fix | Delete
foreach ( $this->plugins as $plugin_section => $plugins ) {
[224] Fix | Delete
$this->check_plugins_active( $plugins, $plugin_section );
[225] Fix | Delete
}
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
/**
[229] Fix | Delete
* Loop through plugins and check if each plugin is active.
[230] Fix | Delete
*
[231] Fix | Delete
* @param array $plugins Set of plugins.
[232] Fix | Delete
* @param string $plugin_section Type of conflict group (such as Open Graph or sitemap).
[233] Fix | Delete
*
[234] Fix | Delete
* @return void
[235] Fix | Delete
*/
[236] Fix | Delete
protected function check_plugins_active( $plugins, $plugin_section ) {
[237] Fix | Delete
foreach ( $plugins as $plugin ) {
[238] Fix | Delete
if ( $this->check_plugin_is_active( $plugin ) ) {
[239] Fix | Delete
$this->add_active_plugin( $plugin_section, $plugin );
[240] Fix | Delete
}
[241] Fix | Delete
}
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
/**
[245] Fix | Delete
* Check if given plugin exists in array with all_active_plugins.
[246] Fix | Delete
*
[247] Fix | Delete
* @param string $plugin Plugin basename string.
[248] Fix | Delete
*
[249] Fix | Delete
* @return bool
[250] Fix | Delete
*/
[251] Fix | Delete
protected function check_plugin_is_active( $plugin ) {
[252] Fix | Delete
return in_array( $plugin, $this->all_active_plugins, true );
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
/**
[256] Fix | Delete
* Add plugin to the list of active plugins.
[257] Fix | Delete
*
[258] Fix | Delete
* This method will check first if key $plugin_section exists, if not it will create an empty array
[259] Fix | Delete
* If $plugin itself doesn't exist it will be added.
[260] Fix | Delete
*
[261] Fix | Delete
* @param string $plugin_section Type of conflict group (such as Open Graph or sitemap).
[262] Fix | Delete
* @param string $plugin Plugin basename string.
[263] Fix | Delete
*
[264] Fix | Delete
* @return void
[265] Fix | Delete
*/
[266] Fix | Delete
protected function add_active_plugin( $plugin_section, $plugin ) {
[267] Fix | Delete
if ( ! array_key_exists( $plugin_section, $this->active_conflicting_plugins ) ) {
[268] Fix | Delete
$this->active_conflicting_plugins[ $plugin_section ] = [];
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
if ( ! in_array( $plugin, $this->active_conflicting_plugins[ $plugin_section ], true ) ) {
[272] Fix | Delete
$this->active_conflicting_plugins[ $plugin_section ][] = $plugin;
[273] Fix | Delete
}
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
/**
[277] Fix | Delete
* Search in $this->plugins for the given $plugin.
[278] Fix | Delete
*
[279] Fix | Delete
* If there is a result it will return the plugin category.
[280] Fix | Delete
*
[281] Fix | Delete
* @param string $plugin Plugin basename string.
[282] Fix | Delete
*
[283] Fix | Delete
* @return int|string
[284] Fix | Delete
*/
[285] Fix | Delete
protected function find_plugin_category( $plugin ) {
[286] Fix | Delete
foreach ( $this->plugins as $plugin_section => $plugins ) {
[287] Fix | Delete
if ( in_array( $plugin, $plugins, true ) ) {
[288] Fix | Delete
return $plugin_section;
[289] Fix | Delete
}
[290] Fix | Delete
}
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
/**
[294] Fix | Delete
* Get plugin name from file.
[295] Fix | Delete
*
[296] Fix | Delete
* @param string $plugin Plugin path relative to plugins directory.
[297] Fix | Delete
*
[298] Fix | Delete
* @return string|bool Plugin name or false when no name is set.
[299] Fix | Delete
*/
[300] Fix | Delete
protected function get_plugin_name( $plugin ) {
[301] Fix | Delete
$plugin_details = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
[302] Fix | Delete
[303] Fix | Delete
if ( $plugin_details['Name'] !== '' ) {
[304] Fix | Delete
return $plugin_details['Name'];
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
return false;
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
/**
[311] Fix | Delete
* When being in the deactivation process the currently deactivated plugin has to be removed.
[312] Fix | Delete
*
[313] Fix | Delete
* @return void
[314] Fix | Delete
*/
[315] Fix | Delete
private function remove_deactivated_plugin() {
[316] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: On the deactivation screen the nonce is already checked by WordPress itself.
[317] Fix | Delete
if ( ! isset( $_GET['plugin'] ) || ! is_string( $_GET['plugin'] ) ) {
[318] Fix | Delete
return;
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: On the deactivation screen the nonce is already checked by WordPress itself.
[322] Fix | Delete
$deactivated_plugin = sanitize_text_field( wp_unslash( $_GET['plugin'] ) );
[323] Fix | Delete
$key_to_remove = array_search( $deactivated_plugin, $this->all_active_plugins, true );
[324] Fix | Delete
[325] Fix | Delete
if ( $key_to_remove !== false ) {
[326] Fix | Delete
unset( $this->all_active_plugins[ $key_to_remove ] );
[327] Fix | Delete
}
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
/**
[331] Fix | Delete
* Get the identifier from the plugin file.
[332] Fix | Delete
*
[333] Fix | Delete
* @param string $plugin_file Plugin file to get Identifier from.
[334] Fix | Delete
*
[335] Fix | Delete
* @return string
[336] Fix | Delete
*/
[337] Fix | Delete
private function get_notification_identifier( $plugin_file ) {
[338] Fix | Delete
return md5( $plugin_file );
[339] Fix | Delete
}
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function