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/string-l.../includes/Extensio.../SearchRe...
File: class-replace.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Base class for the Replace feature.
[2] Fix | Delete
*/
[3] Fix | Delete
[4] Fix | Delete
namespace StringLocator\Extension\SearchReplace;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Replace class.
[8] Fix | Delete
*/
[9] Fix | Delete
class Replace {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Class constructor.
[13] Fix | Delete
*/
[14] Fix | Delete
public function __construct() {
[15] Fix | Delete
add_action( 'string_locator_search_results_tablenav_controls', array( $this, 'add_replace_button' ) );
[16] Fix | Delete
add_action( 'string_locator_search_results_tablenav_controls', array( $this, 'output_replace_form' ) );
[17] Fix | Delete
add_action( 'string_locator_instawp_tablenav_controls', array( $this, 'add_instawp_stage_button' ) );
[18] Fix | Delete
[19] Fix | Delete
add_action( 'admin_enqueue_scripts', array( $this, 'maybe_enqueue_assets' ) );
[20] Fix | Delete
[21] Fix | Delete
add_action( 'string_locator_search_templates', array( $this, 'add_replace_response_template' ) );
[22] Fix | Delete
[23] Fix | Delete
add_action( 'wp_ajax_install_activate_plugin', array( $this, 'install_activate_plugin_callback' ) );
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Add error notice template.
[28] Fix | Delete
*
[29] Fix | Delete
* @return void
[30] Fix | Delete
*/
[31] Fix | Delete
public function add_replace_response_template() {
[32] Fix | Delete
require_once STRING_LOCATOR_PLUGIN_DIR . '/includes/Extension/SearchReplace/template/error-notice.php';
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Conditionally register assets on the appropriate pages within wp-admin.
[37] Fix | Delete
*
[38] Fix | Delete
* @param string $hook The hook name for the page being loaded.
[39] Fix | Delete
*
[40] Fix | Delete
* @return void
[41] Fix | Delete
*/
[42] Fix | Delete
public function maybe_enqueue_assets( $hook ) {
[43] Fix | Delete
// Break out early if we are not on a String Locator page
[44] Fix | Delete
if ( 'tools_page_string-locator' !== $hook && 'toplevel_page_string-locator' !== $hook ) {
[45] Fix | Delete
return;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
$replace = STRING_LOCATOR_PLUGIN_DIR . 'build/string-locator-replace.asset.php';
[49] Fix | Delete
[50] Fix | Delete
$replace = file_exists( $replace ) ? require $replace : array( 'version' => false );
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* String Locator Styles and Scripts.
[54] Fix | Delete
*/
[55] Fix | Delete
wp_enqueue_style( 'string-locator-replace', trailingslashit( STRING_LOCATOR_PLUGIN_URL ) . 'build/string-locator-replace.css', array(), $replace['version'] );
[56] Fix | Delete
wp_enqueue_script( 'string-locator-replace', trailingslashit( STRING_LOCATOR_PLUGIN_URL ) . 'build/string-locator-replace.js', array(), $replace['version'], true );
[57] Fix | Delete
[58] Fix | Delete
wp_localize_script(
[59] Fix | Delete
'string-locator-replace',
[60] Fix | Delete
'stringLocatorReplace',
[61] Fix | Delete
array(
[62] Fix | Delete
'rest_nonce' => wp_create_nonce( 'wp_rest' ),
[63] Fix | Delete
'replace_nonce' => wp_create_nonce( 'string-locator-replace' ),
[64] Fix | Delete
'url' => array(
[65] Fix | Delete
'replace' => get_rest_url( null, 'string-locator/v1/replace' ),
[66] Fix | Delete
),
[67] Fix | Delete
'string' => array(
[68] Fix | Delete
'replace_started' => __( 'Running replacemenets...', 'string-locator' ),
[69] Fix | Delete
'button_show' => __( 'Show replacement controls', 'string-locator' ),
[70] Fix | Delete
'button_hide' => __( 'Hide replacement controls', 'string-locator' ),
[71] Fix | Delete
'confirm_all' => __( 'Are you sure you want to replace all strings?', 'string-locator' ),
[72] Fix | Delete
),
[73] Fix | Delete
)
[74] Fix | Delete
);
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Instawp installation event handle script
[78] Fix | Delete
* */
[79] Fix | Delete
wp_enqueue_script( 'string-locator-instawp', trailingslashit( STRING_LOCATOR_PLUGIN_URL ) . 'build/string-locator-instawp.js', array( 'jquery', 'updates' ), $replace['version'], false );
[80] Fix | Delete
wp_localize_script(
[81] Fix | Delete
'string-locator-instawp',
[82] Fix | Delete
'instawp_activate',
[83] Fix | Delete
array( 'nonce' => wp_create_nonce( 'string-locator-activate-instawp' ) )
[84] Fix | Delete
);
[85] Fix | Delete
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* Output a toggle button to display the replacement form.
[90] Fix | Delete
*
[91] Fix | Delete
* @return void
[92] Fix | Delete
*/
[93] Fix | Delete
public function add_replace_button() {
[94] Fix | Delete
printf(
[95] Fix | Delete
'<button type="button" class="button button-link" id="string-locator-toggle-replace-controls" aria-expanded="false" aria-controls="string-locator-replace-form">%s</button>',
[96] Fix | Delete
esc_html__( 'Show replacement controls', 'string-locator' )
[97] Fix | Delete
);
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* Output a button to display the create staging site.
[102] Fix | Delete
*
[103] Fix | Delete
* @return void
[104] Fix | Delete
*/
[105] Fix | Delete
public function add_instawp_stage_button() {
[106] Fix | Delete
self::install_plugin_button( 'instawp-connect', 'instawp-connect.php', 'InstaWP Connect', array(), __( 'Go to InstaWP &rarr;', 'string-locator' ), __( 'Activate InstaWP', 'string-locator' ), __( 'Create a Staging Site (powered by InstaWP)', 'string-locator' ) );
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
public static function install_plugin_button( $plugin_slug, $plugin_file, $plugin_name, $classes = array(), $activated = '', $activate = '', $install = '' ) {
[110] Fix | Delete
if ( current_user_can( 'install_plugins' ) && current_user_can( 'activate_plugins' ) ) {
[111] Fix | Delete
if ( is_plugin_active( $plugin_slug . '/' . $plugin_file ) ) {
[112] Fix | Delete
// The plugin is already active.
[113] Fix | Delete
// $instawp_connect = menu_page_url( 'instawp-connect', false );
[114] Fix | Delete
$instawp_connect = menu_page_url( 'instawp', false );
[115] Fix | Delete
$button = array(
[116] Fix | Delete
'message' => esc_attr__( 'Create a Staging Site', 'string-locator' ),
[117] Fix | Delete
'url' => $instawp_connect,
[118] Fix | Delete
'classes' => array( 'string-locator-instawp-button', 'disabled' ),
[119] Fix | Delete
);
[120] Fix | Delete
[121] Fix | Delete
if ( '' !== $activated ) {
[122] Fix | Delete
$button['message'] = esc_attr( $activated );
[123] Fix | Delete
[124] Fix | Delete
$button['target'] = "onclick=\"window.open('{$instawp_connect}', '_blank');\"";
[125] Fix | Delete
}
[126] Fix | Delete
$button['logo-img'] = '<span class="btn-logo-inline"><img src="' . esc_url( plugins_url( 'views/assets/instawp-logo.svg', STRING_LOCATOR_PLUGIN_FILE ) ) . '" alt="InstaWP logo"></span>';
[127] Fix | Delete
[128] Fix | Delete
} elseif ( self::is_plugin_installed( $plugin_slug ) ) {
[129] Fix | Delete
$url = self::is_plugin_installed( $plugin_slug );
[130] Fix | Delete
[131] Fix | Delete
// The plugin exists but isn't activated yet.
[132] Fix | Delete
$button = array(
[133] Fix | Delete
'message' => esc_attr__( 'Create a Staging Site', 'string-locator' ),
[134] Fix | Delete
// 'url' => $url,
[135] Fix | Delete
'url' => 'javascript:void 0;',
[136] Fix | Delete
'classes' => array( 'instawp-activate-now' ),
[137] Fix | Delete
);
[138] Fix | Delete
[139] Fix | Delete
$button['logo-img'] = '<span class="btn-logo-inline"><img src="' . esc_url( plugins_url( 'views/assets/instawp-logo.svg', STRING_LOCATOR_PLUGIN_FILE ) ) . '" alt="InstaWP logo"></span>';
[140] Fix | Delete
if ( '' !== $activate ) {
[141] Fix | Delete
$button['message'] = esc_attr( $activate );
[142] Fix | Delete
}
[143] Fix | Delete
} else {
[144] Fix | Delete
// The plugin doesn't exist.
[145] Fix | Delete
$url = wp_nonce_url(
[146] Fix | Delete
add_query_arg(
[147] Fix | Delete
array(
[148] Fix | Delete
'action' => 'install-plugin',
[149] Fix | Delete
'plugin' => $plugin_slug,
[150] Fix | Delete
),
[151] Fix | Delete
self_admin_url( 'update.php' )
[152] Fix | Delete
),
[153] Fix | Delete
'install-plugin_' . $plugin_slug
[154] Fix | Delete
);
[155] Fix | Delete
$button = array(
[156] Fix | Delete
'message' => esc_attr__( 'Create a Staging Site', 'string-locator' ),
[157] Fix | Delete
'url' => $url,
[158] Fix | Delete
'classes' => array( 'sl-instawp-install-now', 'install-now', 'install-' . $plugin_slug ),
[159] Fix | Delete
);
[160] Fix | Delete
[161] Fix | Delete
if ( '' !== $install ) {
[162] Fix | Delete
$button['message'] = esc_attr( $install );
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
$button['logo-img'] = '<span class="btn-logo-inline"><img src="' . esc_url( plugins_url( 'views/assets/instawp-logo.svg', STRING_LOCATOR_PLUGIN_FILE ) ) . '" alt="InstaWP logo"></span>';
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
if ( ! empty( $classes ) ) {
[169] Fix | Delete
$button['classes'] = array_merge( $button['classes'], $classes );
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
$button['classes'] = implode( ' ', $button['classes'] );
[173] Fix | Delete
[174] Fix | Delete
?>
[175] Fix | Delete
<span class="plugin-card-<?php echo esc_attr( $plugin_slug ); ?>" style="float: right; margin-top: 7px;">
[176] Fix | Delete
<?php echo ! empty( $button['logo-img'] ) ? $button['logo-img'] : ''; ?>
[177] Fix | Delete
<button href="<?php echo esc_url( $button['url'] ); ?>" class="<?php echo esc_attr( $button['classes'] ); ?>" data-originaltext="<?php echo esc_attr( $button['message'] ); ?>" data-name="<?php echo esc_attr( $plugin_name ); ?>" data-slug="<?php echo esc_attr( $plugin_slug ); ?>" aria-label="<?php echo esc_attr( $button['message'] ); ?>" <?php echo ! empty( $button['target'] ) ? $button['target'] : ''; ?>>
[178] Fix | Delete
<?php echo esc_html( $button['message'] ); ?>
[179] Fix | Delete
</button>
[180] Fix | Delete
</span>
[181] Fix | Delete
<?php
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
/**
[187] Fix | Delete
* Handle Ajax call to activate the function
[188] Fix | Delete
*
[189] Fix | Delete
*/
[190] Fix | Delete
public function install_activate_plugin_callback() {
[191] Fix | Delete
// for instawp-connect plugin only
[192] Fix | Delete
$plugin_slug = 'instawp-connect';
[193] Fix | Delete
[194] Fix | Delete
$plugin_slug_file = $plugin_slug . '/' . $plugin_slug . '.php';
[195] Fix | Delete
[196] Fix | Delete
// Verify the nonce
[197] Fix | Delete
if ( ! check_ajax_referer( 'string-locator-activate-instawp', 'nonce', false ) ) {
[198] Fix | Delete
wp_send_json_error( __( 'Invalid nonce.', 'string-locator' ) );
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
// Check if the current user has the required capability
[202] Fix | Delete
if ( ! current_user_can( 'activate_plugins' ) ) {
[203] Fix | Delete
wp_send_json_error( __( 'You do not have permission to perform this action.', 'string-locator' ) );
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
[207] Fix | Delete
[208] Fix | Delete
$result = activate_plugin( $plugin_slug_file );
[209] Fix | Delete
[210] Fix | Delete
if ( is_wp_error( $result ) ) {
[211] Fix | Delete
wp_send_json_error( $result->get_error_message() );
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
$instawp_link = menu_page_url( 'instawp', false );
[215] Fix | Delete
if ( empty( $instawp_link ) ) {
[216] Fix | Delete
$instawp_link = admin_url( 'tools.php?page=instawp' );
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
$response = array(
[220] Fix | Delete
'message' => __( 'Plugin installed and activated successfully.', 'string-locator' ),
[221] Fix | Delete
'href' => $instawp_link,
[222] Fix | Delete
'anchor_text' => __( 'Go to InstaWP →', 'string-locator' ),
[223] Fix | Delete
);
[224] Fix | Delete
[225] Fix | Delete
wp_send_json_success( $response );
[226] Fix | Delete
wp_die();
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
/**
[230] Fix | Delete
* Check if a plugin is installed and return the url to activate it if so.
[231] Fix | Delete
*
[232] Fix | Delete
* @param string $plugin_slug The plugin slug.
[233] Fix | Delete
*/
[234] Fix | Delete
private static function is_plugin_installed( $plugin_slug ) {
[235] Fix | Delete
if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) {
[236] Fix | Delete
$plugins = get_plugins( '/' . $plugin_slug );
[237] Fix | Delete
if ( ! empty( $plugins ) ) {
[238] Fix | Delete
$keys = array_keys( $plugins );
[239] Fix | Delete
$plugin_file = $plugin_slug . '/' . $keys[0];
[240] Fix | Delete
$url = wp_nonce_url(
[241] Fix | Delete
add_query_arg(
[242] Fix | Delete
array(
[243] Fix | Delete
'action' => 'activate',
[244] Fix | Delete
'plugin' => $plugin_file,
[245] Fix | Delete
),
[246] Fix | Delete
admin_url( 'plugins.php' )
[247] Fix | Delete
),
[248] Fix | Delete
'activate-plugin_' . $plugin_file
[249] Fix | Delete
);
[250] Fix | Delete
return $url;
[251] Fix | Delete
}
[252] Fix | Delete
}
[253] Fix | Delete
return false;
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* Output the replacement form.
[258] Fix | Delete
*
[259] Fix | Delete
* @return void
[260] Fix | Delete
*/
[261] Fix | Delete
public function output_replace_form() {
[262] Fix | Delete
$instawp_plugin = 'instawp-connect';
[263] Fix | Delete
include_once __DIR__ . '/views/replace-form.php';
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
new Replace();
[269] Fix | Delete
[270] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function