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/ninja-fo.../includes/Integrat.../EDD
File: class-extension-updater.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
/**
[1] Fix | Delete
* This class handles all the update-related stuff for extensions, including adding a license section to the license tab.
[2] Fix | Delete
* It accepts two args: Product Name and Version.
[3] Fix | Delete
*
[4] Fix | Delete
* @param $product_name string
[5] Fix | Delete
* @param $version string
[6] Fix | Delete
* @since 2.2.47
[7] Fix | Delete
* @return void
[8] Fix | Delete
*/
[9] Fix | Delete
class NF_Extension_Updater
[10] Fix | Delete
{
[11] Fix | Delete
public $product_nice_name = '';
[12] Fix | Delete
public $product_name = '';
[13] Fix | Delete
public $version = '';
[14] Fix | Delete
public $store_url = 'https://ninjaforms.com/update-check/';
[15] Fix | Delete
public $file = '';
[16] Fix | Delete
public $author = '';
[17] Fix | Delete
public $error = '';
[18] Fix | Delete
private $_last_error;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Constructor function
[22] Fix | Delete
*
[23] Fix | Delete
* @since 2.2.47
[24] Fix | Delete
* @updated 3.0
[25] Fix | Delete
* @return void
[26] Fix | Delete
*/
[27] Fix | Delete
public function __construct( $product_name, $version, $author, $file, $slug = '' )
[28] Fix | Delete
{
[29] Fix | Delete
$this->product_nice_name = $product_name;
[30] Fix | Delete
if ( $slug == '' ) {
[31] Fix | Delete
$this->product_name = strtolower( $product_name );
[32] Fix | Delete
$this->product_name = preg_replace( "/[^a-zA-Z]+/", "", $this->product_name );
[33] Fix | Delete
} else {
[34] Fix | Delete
$this->product_name = $slug;
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
$this->version = $version;
[38] Fix | Delete
$this->file = $file;
[39] Fix | Delete
$this->author = $author;
[40] Fix | Delete
[41] Fix | Delete
$this->auto_update();
[42] Fix | Delete
[43] Fix | Delete
add_filter( 'ninja_forms_settings_licenses_addons', array( $this, 'register' ) );
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Function that adds the license entry fields to the license tab.
[48] Fix | Delete
*
[49] Fix | Delete
* @updated 3.0
[50] Fix | Delete
* @param array $licenses
[51] Fix | Delete
* @return array $licenses
[52] Fix | Delete
*/
[53] Fix | Delete
function register( $licenses ) {
[54] Fix | Delete
$licenses[] = $this;
[55] Fix | Delete
return $licenses;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/*
[59] Fix | Delete
*
[60] Fix | Delete
* Function that activates our license
[61] Fix | Delete
*
[62] Fix | Delete
* @since 2.2.47
[63] Fix | Delete
* @return void
[64] Fix | Delete
*/
[65] Fix | Delete
function activate_license( $license_key ) {
[66] Fix | Delete
[67] Fix | Delete
// data to send in our API request
[68] Fix | Delete
$api_params = array(
[69] Fix | Delete
'edd_action'=> 'activate_license',
[70] Fix | Delete
'license' => $license_key,
[71] Fix | Delete
'item_name' => urlencode( $this->product_nice_name ), // the name of our product in EDD
[72] Fix | Delete
'url' => home_url()
[73] Fix | Delete
);
[74] Fix | Delete
[75] Fix | Delete
// Call the custom API.
[76] Fix | Delete
$response = wp_remote_post( $this->store_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
[77] Fix | Delete
[78] Fix | Delete
$this->maybe_debug( $response );
[79] Fix | Delete
[80] Fix | Delete
// make sure the response came back okay
[81] Fix | Delete
if ( is_wp_error( $response ) )
[82] Fix | Delete
return false;
[83] Fix | Delete
[84] Fix | Delete
// decode the license data
[85] Fix | Delete
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
[86] Fix | Delete
[87] Fix | Delete
if ( 'invalid' == $license_data->license ) {
[88] Fix | Delete
$error = '<span style="color: red;">' . esc_html__( 'Could not activate license. Please verify your license key', 'ninja-forms' ) . '</span>';
[89] Fix | Delete
[90] Fix | Delete
if ( isset ( $_REQUEST[ 'nf_debug' ] ) && 1 == absint( $_REQUEST[ 'nf_debug' ] ) ) {
[91] Fix | Delete
// Add an error to our admin notice if nf_debug is turned on.
[92] Fix | Delete
add_filter( 'nf_admin_notices', array( $this, 'show_license_error_notice' ) );
[93] Fix | Delete
$this->_last_error = var_export( $license_data, true );
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
Ninja_Forms()->logger()->emergency( var_export( $license_data, true ) );
[97] Fix | Delete
[98] Fix | Delete
} else {
[99] Fix | Delete
$error = '';
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
Ninja_Forms()->update_setting( $this->product_name . '_license', $license_key );
[103] Fix | Delete
Ninja_Forms()->update_setting( $this->product_name . '_license_error', $error );
[104] Fix | Delete
Ninja_Forms()->update_setting( $this->product_name . '_license_status', $license_data->license );
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
public function show_license_error_notice( $notices ) {
[108] Fix | Delete
$notices[ 'license_error' ] = array(
[109] Fix | Delete
'title' => esc_html__( 'License Activation Error', 'ninja-forms' ),
[110] Fix | Delete
'msg' => '<pre>' . $this->_last_error . '</pre>',
[111] Fix | Delete
'int' => 0,
[112] Fix | Delete
'ignore_spam' => true,
[113] Fix | Delete
);
[114] Fix | Delete
[115] Fix | Delete
return $notices;
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
/*
[119] Fix | Delete
*
[120] Fix | Delete
* Function that deactivates our license if the user clicks the "Deactivate License" button.
[121] Fix | Delete
*
[122] Fix | Delete
* @since 2.2.47
[123] Fix | Delete
* @return void
[124] Fix | Delete
*/
[125] Fix | Delete
[126] Fix | Delete
function deactivate_license() {
[127] Fix | Delete
[128] Fix | Delete
$license = Ninja_Forms()->get_setting( $this->product_name . '_license' );
[129] Fix | Delete
[130] Fix | Delete
// data to send in our API request
[131] Fix | Delete
$api_params = array(
[132] Fix | Delete
'edd_action'=> 'deactivate_license',
[133] Fix | Delete
'license' => $license,
[134] Fix | Delete
'item_name' => urlencode( $this->product_nice_name ), // the name of our product in EDD
[135] Fix | Delete
'url' => home_url()
[136] Fix | Delete
);
[137] Fix | Delete
[138] Fix | Delete
// Call the custom API.
[139] Fix | Delete
$response = wp_remote_post( $this->store_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
[140] Fix | Delete
[141] Fix | Delete
$this->maybe_debug( $response );
[142] Fix | Delete
[143] Fix | Delete
// make sure the response came back okay
[144] Fix | Delete
if ( is_wp_error( $response ) )
[145] Fix | Delete
return false;
[146] Fix | Delete
[147] Fix | Delete
Ninja_Forms()->update_setting( $this->product_name.'_license_error', '' );
[148] Fix | Delete
Ninja_Forms()->update_setting( $this->product_name.'_license_status', 'invalid' );
[149] Fix | Delete
Ninja_Forms()->update_setting( $this->product_name.'_license', '' );
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* Function that runs all of our auto-update functionality
[154] Fix | Delete
*
[155] Fix | Delete
* @since 2.2.47
[156] Fix | Delete
* @updates 3.0
[157] Fix | Delete
* @return void
[158] Fix | Delete
*/
[159] Fix | Delete
function auto_update() {
[160] Fix | Delete
[161] Fix | Delete
$edd_updater = new EDD_SL_Plugin_Updater( $this->store_url, $this->file, array(
[162] Fix | Delete
'author' => $this->author, // author of this plugin
[163] Fix | Delete
'version' => $this->version, // current version number
[164] Fix | Delete
'item_name' => $this->product_nice_name, // name of this plugin
[165] Fix | Delete
'license' => Ninja_Forms()->get_setting( $this->product_name.'_license' ), // license key
[166] Fix | Delete
)
[167] Fix | Delete
);
[168] Fix | Delete
[169] Fix | Delete
// Hook into the "after plugin row" display for this Ninja Forms add-on.
[170] Fix | Delete
add_action( 'after_plugin_row_' . plugin_basename( $this->file ), array( $this, 'maybe_prevent_update_notice' ), 9, 3 );
[171] Fix | Delete
// Filter that expects either a bool false to continue install or a WP_Error to prevent installation of an update.
[172] Fix | Delete
add_filter( 'upgrader_pre_install', array( $this, 'maybe_prevent_install' ), 10, 2 );
[173] Fix | Delete
} // function auto_update
[174] Fix | Delete
[175] Fix | Delete
/**
[176] Fix | Delete
* Function that maybe prevents a plugin update from installing if the php version is not high enough.
[177] Fix | Delete
*
[178] Fix | Delete
* @since 3.4.24
[179] Fix | Delete
* @param bool $default false
[180] Fix | Delete
* @param array $extra array sent by the filter we're using.
[181] Fix | Delete
* @return bool/WP_ERROR $default if we bail early, WP_ERROR if we don't.
[182] Fix | Delete
*/
[183] Fix | Delete
public function maybe_prevent_install( $default, $extra )
[184] Fix | Delete
{
[185] Fix | Delete
// If the plugin being installed isn't this one, bail.
[186] Fix | Delete
$plugin = plugin_basename( $this->file );
[187] Fix | Delete
[188] Fix | Delete
if(!isset($extra['plugin']) || $plugin != $extra[ 'plugin' ] ) {
[189] Fix | Delete
return $default;
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
// Grab our WP Updates transient so that we can check the minimum PHP version
[193] Fix | Delete
$update_transient = get_option( '_site_transient_update_plugins' );
[194] Fix | Delete
// Check to see if we have a php_requires setting for our update.
[195] Fix | Delete
$php_requires = isset( $update_transient->response[ $plugin ]->php_requires ) ? $update_transient->response[ $plugin ]->php_requires : false;
[196] Fix | Delete
[197] Fix | Delete
// If we don't have a php_requires setting or our php version meets the php_requires setting, bail.
[198] Fix | Delete
if( empty( $php_requires ) || version_compare( PHP_VERSION, $php_requires, '>=' ) ) {
[199] Fix | Delete
return $default;
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
return new WP_Error( 'php_minimum_version', sprintf( esc_html__( 'The new version requires at least PHP %s, and your PHP version is %s.', 'ninja-forms' ), $php_requires, PHP_VERSION ), esc_html__( 'Please contact your host to upgrade your site\'s PHP version.' ) );
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
/**
[206] Fix | Delete
* Check to see if this plugin update has a minimum PHP version.
[207] Fix | Delete
* If it does, make sure that we meet it.
[208] Fix | Delete
* If we don't meet it, then show the user an error message with a link to WordPress.org's minimum requirements page.
[209] Fix | Delete
*
[210] Fix | Delete
* @since 3.4.24
[211] Fix | Delete
* @param string $plugin_file plugin file for the row we're looking at
[212] Fix | Delete
* @param array $plugin_data update data from the WordPress plugin update check
[213] Fix | Delete
* @param string $plugin_status is this plugin active, inactive, etc.
[214] Fix | Delete
* @return void
[215] Fix | Delete
*/
[216] Fix | Delete
public function maybe_prevent_update_notice( $plugin_file, $plugin_data, $plugin_status )
[217] Fix | Delete
{
[218] Fix | Delete
$php_requires = isset( $plugin_data[ 'php_requires' ] ) ? $plugin_data[ 'php_requires' ] : '';
[219] Fix | Delete
[220] Fix | Delete
// Return early if the current PHP version is equal to or greater than the PHP version required by the new version of this add-on.
[221] Fix | Delete
if ( version_compare( PHP_VERSION, $php_requires, '>=' ) ) {
[222] Fix | Delete
return false;
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
remove_action( 'after_plugin_row_' . plugin_basename( $this->file ), 'wp_plugin_update_row', 10 );
[226] Fix | Delete
[227] Fix | Delete
echo '<tr class="update-error">
[228] Fix | Delete
<td colspan="5" style="background-color:#fef7f1;">
[229] Fix | Delete
<div class="update-message notice inline notice-error notice-alt" style="margin: 10px 0 5px;">
[230] Fix | Delete
<p>
[231] Fix | Delete
' . sprintf( esc_html__( 'An update is available for %s, however, you are not able to update at this time.', 'ninja-forms' ), 'Ninja Forms - ' . $this->product_nice_name ) . '
[232] Fix | Delete
<br />
[233] Fix | Delete
<strong>' . sprintf( esc_html__( 'The new version requires at least PHP %s, and your PHP version is %s.', 'ninja-forms' ), $php_requires, PHP_VERSION ) . '</strong>
[234] Fix | Delete
<br />
[235] Fix | Delete
' . sprintf( esc_html__( 'Please contact your host to upgrade your site\'s PHP version. %sRead more about updating your PHP version and WordPress%s.' ), '<a href="https://wordpress.org/about/requirements/" target="_blank">', '</a>' ) . '
[236] Fix | Delete
</p>
[237] Fix | Delete
</div>
[238] Fix | Delete
</td>
[239] Fix | Delete
</tr>';
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
/**
[243] Fix | Delete
* Return whether or not this license is valid.
[244] Fix | Delete
*
[245] Fix | Delete
* @access public
[246] Fix | Delete
* @since 2.9
[247] Fix | Delete
* @return bool
[248] Fix | Delete
*/
[249] Fix | Delete
public function is_valid() {
[250] Fix | Delete
return ( 'valid' == Ninja_Forms()->get_setting( $this->product_name.'_license_status' ) );
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* Get any error messages for this license field.
[255] Fix | Delete
*
[256] Fix | Delete
* @access public
[257] Fix | Delete
* @since 2.9
[258] Fix | Delete
* @return string $error
[259] Fix | Delete
*/
[260] Fix | Delete
public function get_error() {
[261] Fix | Delete
return Ninja_Forms()->get_setting( $this->product_name . '_license_error' );
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
private function maybe_debug( $data, $key = 'debug' )
[265] Fix | Delete
{
[266] Fix | Delete
if ( isset ( $_GET[ $key ] ) && 'true' == $_GET[ $key ] ) {
[267] Fix | Delete
echo '<pre>'; var_dump( $data ); echo '</pre>';
[268] Fix | Delete
die();
[269] Fix | Delete
}
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
} // End Class NF_Extension_Updater
[273] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function