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/wp-conte.../plugins/content-.../inc/freemius/includes
File: fs-essential-functions.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* IMPORTANT:
[2] Fix | Delete
* This file will be loaded based on the order of the plugins/themes load.
[3] Fix | Delete
* If there's a theme and a plugin using Freemius, the plugin's essential
[4] Fix | Delete
* file will always load first.
[5] Fix | Delete
*
[6] Fix | Delete
* @package Freemius
[7] Fix | Delete
* @copyright Copyright (c) 2015, Freemius, Inc.
[8] Fix | Delete
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
[9] Fix | Delete
* @since 1.1.5
[10] Fix | Delete
*/
[11] Fix | Delete
[12] Fix | Delete
if ( ! function_exists( 'fs_normalize_path' ) ) {
[13] Fix | Delete
if ( function_exists( 'wp_normalize_path' ) ) {
[14] Fix | Delete
/**
[15] Fix | Delete
* Normalize a filesystem path.
[16] Fix | Delete
*
[17] Fix | Delete
* Replaces backslashes with forward slashes for Windows systems, and ensures
[18] Fix | Delete
* no duplicate slashes exist.
[19] Fix | Delete
*
[20] Fix | Delete
* @param string $path Path to normalize.
[21] Fix | Delete
*
[22] Fix | Delete
* @return string Normalized path.
[23] Fix | Delete
*/
[24] Fix | Delete
function fs_normalize_path( $path ) {
[25] Fix | Delete
return wp_normalize_path( $path );
[26] Fix | Delete
}
[27] Fix | Delete
} else {
[28] Fix | Delete
function fs_normalize_path( $path ) {
[29] Fix | Delete
$path = str_replace( '\\', '/', $path );
[30] Fix | Delete
$path = preg_replace( '|/+|', '/', $path );
[31] Fix | Delete
[32] Fix | Delete
return $path;
[33] Fix | Delete
}
[34] Fix | Delete
}
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-2.2.1.php';
[38] Fix | Delete
[39] Fix | Delete
#region Core Redirect (copied from BuddyPress) -----------------------------------------
[40] Fix | Delete
[41] Fix | Delete
if ( ! function_exists( 'fs_redirect' ) ) {
[42] Fix | Delete
/**
[43] Fix | Delete
* Redirects to another page, with a workaround for the IIS Set-Cookie bug.
[44] Fix | Delete
*
[45] Fix | Delete
* @link http://support.microsoft.com/kb/q176113/
[46] Fix | Delete
* @since 1.5.1
[47] Fix | Delete
* @uses apply_filters() Calls 'wp_redirect' hook on $location and $status.
[48] Fix | Delete
*
[49] Fix | Delete
* @param string $location The path to redirect to.
[50] Fix | Delete
* @param bool $exit If true, exit after redirect (Since 1.2.1.5).
[51] Fix | Delete
* @param int $status Status code to use.
[52] Fix | Delete
*
[53] Fix | Delete
* @return bool False if $location is not set
[54] Fix | Delete
*/
[55] Fix | Delete
function fs_redirect( $location, $exit = true, $status = 302 ) {
[56] Fix | Delete
global $is_IIS;
[57] Fix | Delete
[58] Fix | Delete
$file = '';
[59] Fix | Delete
$line = '';
[60] Fix | Delete
if ( headers_sent($file, $line) ) {
[61] Fix | Delete
if ( WP_FS__DEBUG_SDK && class_exists( 'FS_Admin_Notices' ) ) {
[62] Fix | Delete
$notices = FS_Admin_Notices::instance( 'global' );
[63] Fix | Delete
[64] Fix | Delete
$notices->add( "Freemius failed to redirect the page because the headers have been already sent from line <b><code>{$line}</code></b> in file <b><code>{$file}</code></b>. If it's unexpected, it usually happens due to invalid space and/or EOL character(s).", 'Oops...', 'error' );
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
return false;
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
if ( defined( 'DOING_AJAX' ) ) {
[71] Fix | Delete
// Don't redirect on AJAX calls.
[72] Fix | Delete
return false;
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
if ( ! $location ) // allows the wp_redirect filter to cancel a redirect
[76] Fix | Delete
{
[77] Fix | Delete
return false;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
$location = fs_sanitize_redirect( $location );
[81] Fix | Delete
[82] Fix | Delete
if ( $is_IIS ) {
[83] Fix | Delete
header( "Refresh: 0;url=$location" );
[84] Fix | Delete
} else {
[85] Fix | Delete
if ( php_sapi_name() != 'cgi-fcgi' ) {
[86] Fix | Delete
status_header( $status );
[87] Fix | Delete
} // This causes problems on IIS and some FastCGI setups
[88] Fix | Delete
header( "Location: $location" );
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
if ( $exit ) {
[92] Fix | Delete
exit();
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
return true;
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
if ( ! function_exists( 'fs_sanitize_redirect' ) ) {
[99] Fix | Delete
/**
[100] Fix | Delete
* Sanitizes a URL for use in a redirect.
[101] Fix | Delete
*
[102] Fix | Delete
* @since 2.3
[103] Fix | Delete
*
[104] Fix | Delete
* @param string $location
[105] Fix | Delete
*
[106] Fix | Delete
* @return string redirect-sanitized URL
[107] Fix | Delete
*/
[108] Fix | Delete
function fs_sanitize_redirect( $location ) {
[109] Fix | Delete
$location = preg_replace( '|[^a-z0-9-~+_.?#=&;,/:%!]|i', '', $location );
[110] Fix | Delete
$location = fs_kses_no_null( $location );
[111] Fix | Delete
[112] Fix | Delete
// remove %0d and %0a from location
[113] Fix | Delete
$strip = array( '%0d', '%0a' );
[114] Fix | Delete
$found = true;
[115] Fix | Delete
while ( $found ) {
[116] Fix | Delete
$found = false;
[117] Fix | Delete
foreach ( (array) $strip as $val ) {
[118] Fix | Delete
while ( strpos( $location, $val ) !== false ) {
[119] Fix | Delete
$found = true;
[120] Fix | Delete
$location = str_replace( $val, '', $location );
[121] Fix | Delete
}
[122] Fix | Delete
}
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
return $location;
[126] Fix | Delete
}
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
if ( ! function_exists( 'fs_kses_no_null' ) ) {
[130] Fix | Delete
/**
[131] Fix | Delete
* Removes any NULL characters in $string.
[132] Fix | Delete
*
[133] Fix | Delete
* @since 1.0.0
[134] Fix | Delete
*
[135] Fix | Delete
* @param string $string
[136] Fix | Delete
*
[137] Fix | Delete
* @return string
[138] Fix | Delete
*/
[139] Fix | Delete
function fs_kses_no_null( $string ) {
[140] Fix | Delete
$string = preg_replace( '/\0+/', '', $string );
[141] Fix | Delete
$string = preg_replace( '/(\\\\0)+/', '', $string );
[142] Fix | Delete
[143] Fix | Delete
return $string;
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
#endregion Core Redirect (copied from BuddyPress) -----------------------------------------
[149] Fix | Delete
[150] Fix | Delete
if ( ! function_exists( 'fs_get_ip' ) ) {
[151] Fix | Delete
/**
[152] Fix | Delete
* Get server IP.
[153] Fix | Delete
*
[154] Fix | Delete
* @since 2.5.1 This method returns the server IP.
[155] Fix | Delete
*
[156] Fix | Delete
* @author Vova Feldman (@svovaf)
[157] Fix | Delete
* @since 1.1.2
[158] Fix | Delete
*
[159] Fix | Delete
* @return string|null
[160] Fix | Delete
*/
[161] Fix | Delete
function fs_get_ip() {
[162] Fix | Delete
return empty( $_SERVER[ 'SERVER_ADDR' ] ) ?
[163] Fix | Delete
null :
[164] Fix | Delete
$_SERVER[ 'SERVER_ADDR' ];
[165] Fix | Delete
}
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
if ( ! function_exists( 'fs_find_caller_plugin_file' ) ) {
[169] Fix | Delete
/**
[170] Fix | Delete
* Leverage backtrace to find caller plugin main file path.
[171] Fix | Delete
*
[172] Fix | Delete
* @author Vova Feldman (@svovaf)
[173] Fix | Delete
* @since 1.0.6
[174] Fix | Delete
*
[175] Fix | Delete
* @return string
[176] Fix | Delete
*/
[177] Fix | Delete
function fs_find_caller_plugin_file() {
[178] Fix | Delete
/**
[179] Fix | Delete
* All the code below will be executed once on activation.
[180] Fix | Delete
* If the user changes the main plugin's file name, the file_exists()
[181] Fix | Delete
* will catch it.
[182] Fix | Delete
*/
[183] Fix | Delete
if ( ! function_exists( 'get_plugins' ) ) {
[184] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/plugin.php';
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
$all_plugins = fs_get_plugins( true );
[188] Fix | Delete
$all_plugins_paths = array();
[189] Fix | Delete
[190] Fix | Delete
// Get active plugin's main files real full names (might be symlinks).
[191] Fix | Delete
foreach ( $all_plugins as $relative_path => $data ) {
[192] Fix | Delete
$all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
$plugin_file = null;
[196] Fix | Delete
for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
[197] Fix | Delete
if ( empty( $bt[ $i ]['file'] ) ) {
[198] Fix | Delete
continue;
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) {
[202] Fix | Delete
$plugin_file = $bt[ $i ]['file'];
[203] Fix | Delete
break;
[204] Fix | Delete
}
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
if ( is_null( $plugin_file ) ) {
[208] Fix | Delete
// Throw an error to the developer in case of some edge case dev environment.
[209] Fix | Delete
wp_die(
[210] Fix | Delete
'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.',
[211] Fix | Delete
'Error',
[212] Fix | Delete
array( 'back_link' => true )
[213] Fix | Delete
);
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
return $plugin_file;
[217] Fix | Delete
}
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-1.1.7.1.php';
[221] Fix | Delete
[222] Fix | Delete
if ( ! function_exists( 'fs_update_sdk_newest_version' ) ) {
[223] Fix | Delete
/**
[224] Fix | Delete
* Update SDK newest version reference.
[225] Fix | Delete
*
[226] Fix | Delete
* @author Vova Feldman (@svovaf)
[227] Fix | Delete
* @since 1.1.6
[228] Fix | Delete
*
[229] Fix | Delete
* @param string $sdk_relative_path
[230] Fix | Delete
* @param string|bool $plugin_file
[231] Fix | Delete
*
[232] Fix | Delete
* @global $fs_active_plugins
[233] Fix | Delete
*/
[234] Fix | Delete
function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) {
[235] Fix | Delete
/**
[236] Fix | Delete
* If there is a plugin running an older version of FS (1.2.1 or below), the `fs_update_sdk_newest_version()`
[237] Fix | Delete
* function in the older version will be used instead of this one. But since the older version is using
[238] Fix | Delete
* the `is_plugin_active` function to check if a plugin is active, passing the theme's `plugin_path` to the
[239] Fix | Delete
* `is_plugin_active` function will return false since the path is not a plugin path, so `in_activation` will be
[240] Fix | Delete
* `true` for theme modules and the upgrading of the SDK version to 1.2.2 or newer version will work fine.
[241] Fix | Delete
*
[242] Fix | Delete
* Future versions that will call this function will use the proper logic here instead of just relying on the
[243] Fix | Delete
* `is_plugin_active` function to fail for themes.
[244] Fix | Delete
*
[245] Fix | Delete
* @author Leo Fajardo (@leorw)
[246] Fix | Delete
* @since 1.2.2
[247] Fix | Delete
*/
[248] Fix | Delete
[249] Fix | Delete
global $fs_active_plugins;
[250] Fix | Delete
[251] Fix | Delete
$newest_sdk = $fs_active_plugins->plugins[ $sdk_relative_path ];
[252] Fix | Delete
[253] Fix | Delete
if ( ! is_string( $plugin_file ) ) {
[254] Fix | Delete
$plugin_file = plugin_basename( fs_find_caller_plugin_file() );
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
if ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) {
[258] Fix | Delete
if ( ! function_exists( 'is_plugin_active' ) ) {
[259] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/plugin.php';
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
$in_activation = ( ! is_plugin_active( $plugin_file ) );
[263] Fix | Delete
} else {
[264] Fix | Delete
$theme = wp_get_theme();
[265] Fix | Delete
$in_activation = ( $newest_sdk->plugin_path == $theme->stylesheet );
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
$fs_active_plugins->newest = (object) array(
[269] Fix | Delete
'plugin_path' => $plugin_file,
[270] Fix | Delete
'sdk_path' => $sdk_relative_path,
[271] Fix | Delete
'version' => $newest_sdk->version,
[272] Fix | Delete
'in_activation' => $in_activation,
[273] Fix | Delete
'timestamp' => time(),
[274] Fix | Delete
);
[275] Fix | Delete
[276] Fix | Delete
// Update DB with latest SDK version and path.
[277] Fix | Delete
update_option( 'fs_active_plugins', $fs_active_plugins );
[278] Fix | Delete
}
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
if ( ! function_exists( 'fs_newest_sdk_plugin_first' ) ) {
[282] Fix | Delete
/**
[283] Fix | Delete
* Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first.
[284] Fix | Delete
*
[285] Fix | Delete
* @author Vova Feldman (@svovaf)
[286] Fix | Delete
* @since 1.1.6
[287] Fix | Delete
*
[288] Fix | Delete
* @return bool Was plugin order changed. Return false if plugin was loaded first anyways.
[289] Fix | Delete
*
[290] Fix | Delete
* @global $fs_active_plugins
[291] Fix | Delete
*/
[292] Fix | Delete
function fs_newest_sdk_plugin_first() {
[293] Fix | Delete
global $fs_active_plugins;
[294] Fix | Delete
[295] Fix | Delete
/**
[296] Fix | Delete
* @todo Multi-site network activated plugin are always loaded prior to site plugins so if there's a plugin activated in the network mode that has an older version of the SDK of another plugin which is site activated that has new SDK version, the fs-essential-functions.php will be loaded from the older SDK. Same thing about MU plugins (loaded even before network activated plugins).
[297] Fix | Delete
*
[298] Fix | Delete
* @link https://github.com/Freemius/wordpress-sdk/issues/26
[299] Fix | Delete
*/
[300] Fix | Delete
[301] Fix | Delete
$newest_sdk_plugin_path = $fs_active_plugins->newest->plugin_path;
[302] Fix | Delete
[303] Fix | Delete
$active_plugins = get_option( 'active_plugins', array() );
[304] Fix | Delete
$updated_active_plugins = array( $newest_sdk_plugin_path );
[305] Fix | Delete
[306] Fix | Delete
$plugin_found = false;
[307] Fix | Delete
$is_first_path = true;
[308] Fix | Delete
[309] Fix | Delete
foreach ( $active_plugins as $key => $plugin_path ) {
[310] Fix | Delete
if ( $plugin_path === $newest_sdk_plugin_path ) {
[311] Fix | Delete
if ( $is_first_path ) {
[312] Fix | Delete
// if it's the first plugin already, no need to continue
[313] Fix | Delete
return false;
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
$plugin_found = true;
[317] Fix | Delete
[318] Fix | Delete
// Skip the plugin (it is already added as the 1st item of $updated_active_plugins).
[319] Fix | Delete
continue;
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
$updated_active_plugins[] = $plugin_path;
[323] Fix | Delete
[324] Fix | Delete
if ( $is_first_path ) {
[325] Fix | Delete
$is_first_path = false;
[326] Fix | Delete
}
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
if ( $plugin_found ) {
[330] Fix | Delete
update_option( 'active_plugins', $updated_active_plugins );
[331] Fix | Delete
[332] Fix | Delete
return true;
[333] Fix | Delete
}
[334] Fix | Delete
[335] Fix | Delete
if ( is_multisite() ) {
[336] Fix | Delete
// Plugin is network active.
[337] Fix | Delete
$network_active_plugins = get_site_option( 'active_sitewide_plugins', array() );
[338] Fix | Delete
[339] Fix | Delete
if ( isset( $network_active_plugins[ $newest_sdk_plugin_path ] ) ) {
[340] Fix | Delete
reset( $network_active_plugins );
[341] Fix | Delete
if ( $newest_sdk_plugin_path === key( $network_active_plugins ) ) {
[342] Fix | Delete
// Plugin is already activated first on the network level.
[343] Fix | Delete
return false;
[344] Fix | Delete
} else {
[345] Fix | Delete
$time = $network_active_plugins[ $newest_sdk_plugin_path ];
[346] Fix | Delete
[347] Fix | Delete
// Remove plugin from its current position.
[348] Fix | Delete
unset( $network_active_plugins[ $newest_sdk_plugin_path ] );
[349] Fix | Delete
[350] Fix | Delete
// Set it to be included first.
[351] Fix | Delete
$network_active_plugins = array( $newest_sdk_plugin_path => $time ) + $network_active_plugins;
[352] Fix | Delete
[353] Fix | Delete
update_site_option( 'active_sitewide_plugins', $network_active_plugins );
[354] Fix | Delete
[355] Fix | Delete
return true;
[356] Fix | Delete
}
[357] Fix | Delete
}
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
return false;
[361] Fix | Delete
}
[362] Fix | Delete
}
[363] Fix | Delete
[364] Fix | Delete
if ( ! function_exists( 'fs_fallback_to_newest_active_sdk' ) ) {
[365] Fix | Delete
/**
[366] Fix | Delete
* Go over all Freemius SDKs in the system and find and "remember"
[367] Fix | Delete
* the newest SDK which is associated with an active plugin.
[368] Fix | Delete
*
[369] Fix | Delete
* @author Vova Feldman (@svovaf)
[370] Fix | Delete
* @since 1.1.6
[371] Fix | Delete
*
[372] Fix | Delete
* @global $fs_active_plugins
[373] Fix | Delete
*/
[374] Fix | Delete
function fs_fallback_to_newest_active_sdk() {
[375] Fix | Delete
global $fs_active_plugins;
[376] Fix | Delete
[377] Fix | Delete
/**
[378] Fix | Delete
* @var object $newest_sdk_data
[379] Fix | Delete
*/
[380] Fix | Delete
$newest_sdk_data = null;
[381] Fix | Delete
$newest_sdk_path = null;
[382] Fix | Delete
[383] Fix | Delete
foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) {
[384] Fix | Delete
if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' )
[385] Fix | Delete
) {
[386] Fix | Delete
// If plugin inactive or SDK starter file doesn't exist, remove SDK reference.
[387] Fix | Delete
if ( 'plugin' === $data->type ) {
[388] Fix | Delete
$is_module_active = is_plugin_active( $data->plugin_path );
[389] Fix | Delete
} else {
[390] Fix | Delete
$active_theme = wp_get_theme();
[391] Fix | Delete
$is_module_active = ( $data->plugin_path === $active_theme->get_template() );
[392] Fix | Delete
}
[393] Fix | Delete
[394] Fix | Delete
$is_sdk_exists = file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) );
[395] Fix | Delete
[396] Fix | Delete
if ( ! $is_module_active || ! $is_sdk_exists ) {
[397] Fix | Delete
unset( $fs_active_plugins->plugins[ $sdk_relative_path ] );
[398] Fix | Delete
[399] Fix | Delete
// No need to store the data since it will be stored in fs_update_sdk_newest_version()
[400] Fix | Delete
// or explicitly with update_option().
[401] Fix | Delete
} else {
[402] Fix | Delete
$newest_sdk_data = $data;
[403] Fix | Delete
$newest_sdk_path = $sdk_relative_path;
[404] Fix | Delete
}
[405] Fix | Delete
}
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
if ( is_null( $newest_sdk_data ) ) {
[409] Fix | Delete
// Couldn't find any SDK reference.
[410] Fix | Delete
$fs_active_plugins = new stdClass();
[411] Fix | Delete
update_option( 'fs_active_plugins', $fs_active_plugins );
[412] Fix | Delete
} else {
[413] Fix | Delete
fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
[414] Fix | Delete
}
[415] Fix | Delete
}
[416] Fix | Delete
}
[417] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function