ate_site_option( 'rank_math_pro_google_updates', $versions_result['g_updates'] );
}
$stored = get_site_transient( 'rank_math_pro_updates' );
if (
! $force_check
&& ! empty( $stored )
&& version_compare( $stored_versions['new_version'], RANK_MATH_PRO_VERSION, '<=' )
&& ! $this->new_beta_version_available( $stored_versions )
) {
return $stored;
}
if ( ! empty( $this->requested['version'] ) ) {
return ( false === $stored ? [] : $stored );
}
$params = [
'site_url' => is_multisite() ? network_site_url() : home_url(),
'product_slug' => $this->slug,
'new_api' => 2,
'v' => RANK_MATH_PRO_VERSION,
];
$this->maybe_add_auth_params( $params );
$api_url = add_query_arg( 'v', RANK_MATH_PRO_VERSION, $this->api_url . '/updateCheck/' );
$response = wp_remote_post(
$api_url,
[
'timeout' => defined( 'DOING_CRON' ) && DOING_CRON ? 30 : 10,
'body' => $params,
]
);
$this->requested['version'] = true;
if ( is_wp_error( $response ) ) {
return false;
}
$response_body = wp_remote_retrieve_body( $response );
$result = json_decode( $response_body, true );
if ( ! is_array( $result ) || ! isset( $result['new_version'] ) ) {
return false;
}
set_site_transient( 'rank_math_pro_updates', $result, 3600 * 12 );
return $result;
}
/**
* Checks the license manager to see if there is an update available for this product.
*
* @param bool $force_check Disregard cached data & always re-fetch.
* @param string $locale Requested locale. Optional. Default: site locale.
* @return object|bool If there is an update, returns the license information.
* Otherwise returns false.
*/
public function fetch_plugin_info( $force_check = false, $locale = '' ) {
if ( ! $locale ) {
$locale = get_locale();
}
$stored = get_site_transient( 'rank_math_pro_info_' . $locale );
if ( ! $force_check && ! empty( $stored ) ) {
return $stored;
}
if ( ! empty( $this->requested['info'] ) ) {
return ( false === $stored ? (object) [] : $stored );
}
$params = [
'product_slug' => $this->slug,
'locale' => $locale,
'site_url' => is_multisite() ? network_site_url() : home_url(),
];
$this->maybe_add_auth_params( $params );
// Send the request.
$response = wp_remote_post(
$this->api_url . '/pluginInfo/',
[
'timeout' => defined( 'DOING_CRON' ) && DOING_CRON ? 30 : 10,
'body' => $params,
]
);
$this->requested['info'] = true;
if ( is_wp_error( $response ) ) {
return false;
}
$response_body = wp_remote_retrieve_body( $response );
// We do assoc=true and then cast to object to keep sub-items as array.
$result = (object) json_decode( $response_body, true );
if ( ! is_object( $result ) ) {
return false;
}
set_site_transient( 'rank_math_pro_info_' . $locale, $result, 3600 * 3 );
return $result;
}
/**
* Add username & api key if the site is connected.
*
* @param array $params Params passed by reference.
* @return void
*/
private function maybe_add_auth_params( &$params ) {
$registered = Admin_Helper::get_registration_data();
if ( $registered && isset( $registered['username'] ) && isset( $registered['api_key'] ) ) {
$params['username'] = $registered['username'];
$params['api_key'] = $registered['api_key'];
}
}
/**
* Add additional text to notice if download is not available and account is connected.
*
* @param array $plugin_data An array of plugin metadata.
* @param object $response An array of metadata about the available plugin update.
* @return void
*/
public function in_plugin_update_message( $plugin_data, $response ) {
if ( current_user_can( 'update_plugins' ) ) {
if ( empty( $response->package ) && isset( $response->unavailability_reason ) ) {
$message = $this->get_update_message( $response->unavailability_reason );
echo ' ' . wp_kses_post( $message ) . '';
}
}
}
/**
* Get unavailability reason message.
*
* @param string $reason Unavailability reason ID, like 'not_connected'.
* @param mixed $default Default text to return when specified ID has no message attached to it.
* @return string
*/
public function get_update_message( $reason = '', $default = null ) {
if ( is_null( $default ) ) {
$default = '';
}
$unavailability_reasons = [
'update_free' => __( 'Please update the free version before updating Rank Math SEO PRO.', 'rank-math-pro' ),
'not_subscribed' => sprintf(
/* translators: 1: Plugin name, 2: Pricing Link's opening HTML anchor tag, 3: Pricing Link's closing HTML anchor tag. */
__( 'It seems that you don\'t have an active subscription for %1$s. Please see %2$sdetails and pricing%3$s.', 'rank-math-pro' ),
'Rank Math SEO PRO',
'',
''
),
'not_connected' => sprintf(
/* translators: 1: Link's opening HTML anchor tag, 2: Link's closing HTML anchor tag. */
__( 'Please %1$s connect Rank Math SEO PRO %2$s for automatic updates.', 'rank-math-pro' ),
'',
''
),
];
$unavailability_reasons = $this->do_filter( 'updates/unavailability_reasons', $unavailability_reasons );
if ( isset( $unavailability_reasons[ $reason ] ) ) {
return $unavailability_reasons[ $reason ];
}
return $default;
}
/**
* Toggle auto updates option.
* Hooked to run when the option is changed in the free version.
*
* @param string $toggle New status.
* @return void
*/
public function toggle_auto_update( $toggle ) {
$auto_updates = (array) get_site_option( 'auto_update_plugins', [] );
if ( ! empty( $toggle ) && 'off' !== $toggle ) {
$auto_updates[] = 'seo-by-rank-math-pro/rank-math-pro.php';
update_site_option( 'auto_update_plugins', array_unique( $auto_updates ) );
return;
}
update_site_option( 'auto_update_plugins', array_diff( $auto_updates, [ 'seo-by-rank-math-pro/rank-math-pro.php' ] ) );
}
/**
* Don't auto-update if it's a beta version.
*
* @param bool $update Whether to update the plugin or not.
* @param array $item The update plugin object.
*
* @return bool
*/
public function auto_update_plugin( $update, $item ) {
// Show auto-updates control on Plugins page.
if ( did_action( 'load-plugins.php' ) ) {
return $update;
}
if ( $this->is_rm_pro_update( $item ) && $this->is_beta_update( $item ) ) {
return false;
}
return $update;
}
/**
* Check if updatable object is RM.
*
* @param object $item Updatable object.
* @return boolean
*/
public function is_rm_pro_update( $item ) {
return isset( $item->slug ) &&
'seo-by-rank-math-pro' === $item->slug &&
isset( $item->new_version );
}
/**
* Check if given version is beta.
*
* @param object $item Update data.
* @return boolean
*/
public function is_beta_update( $item ) {
return ( is_object( $item ) && isset( $item->new_version ) && false !== stripos( $item->new_version, 'beta' ) );
}
/**
* Hide "update scheduled in X hours" message if update is a beta version because we don't auto-update those.
*
* @param string $html HTML string.
* @param string $plugin_file Plugin file relative to the plugin directory.
* @param array $plugin_data Plugin update data.
* @return string
*/
public function plugin_auto_update_setting_html( $html, $plugin_file, $plugin_data ) {
if ( 'seo-by-rank-math-pro/rank-math-pro.php' !== $plugin_file ) {
return $html;
}
if ( ! empty( $plugin_data['is_beta'] ) ) {
$html = str_replace( 'class="auto-update-time"', 'class="auto-update-time hidden"', $html );
}
return $html;
}
/**
* Set should_send to true if Pro update is available, to send the notification email.
* Notification feature is only available if auto-updates are disabled.
*
* @param boolean $should_send Original should_send value.
* @param mixed $transient update_plugins site ransient value.
* @return boolean
*/
public function should_send_update_notification( $should_send, $transient ) {
if ( $this->get_auto_update_setting() ) {
return $should_send;
}
if ( ! $this->is_update_available( $transient ) ) {
return $should_send;
}
$new_version = $transient->response['seo-by-rank-math-pro/rank-math-pro.php']->new_version;
// Now let's check if we've already sent this email.
$sent = get_option( 'rank_math_update_notifications_sent', [ 'pro' => [ 'new_version' => '1.0' ] ] );
if ( ! isset( $sent['pro'] ) ) {
$sent['pro'] = [ 'new_version' => '1.0' ];
}
if ( version_compare( $sent['pro']['new_version'], $new_version, '>=' ) ) {
return $should_send;
}
return true;
}
/**
* Add Pro to notification product list if an update is available.
*
* @param array $products Products data array.
* @param mixed $transient Transient value.
* @return array
*/
public function update_notification_products( $products, $transient ) {
if ( $this->get_auto_update_setting() ) {
return $products;
}
if ( ! $this->is_update_available( $transient ) ) {
return $products;
}
$products['pro'] = [
'name' => __( 'Rank Math PRO', 'rank-math-pro' ),
'old_version' => RANK_MATH_PRO_VERSION,
'new_version' => $transient->response['seo-by-rank-math-pro/rank-math-pro.php']->new_version,
'changelog' => KB::get( 'changelog', 'PRO Update Popup Chagelog Link' ),
];
return $products;
}
/**
* Check if update is available for the PRO version.
*
* @param mixed $transient The update_plugins transient value.
* @return boolean
*/
public function is_update_available( $transient ) {
if ( ! is_object( $transient )
|| empty( $transient->response )
|| empty( $transient->response['seo-by-rank-math-pro/rank-math-pro.php'] )
|| empty( $transient->response['seo-by-rank-math-pro/rank-math-pro.php']->new_version )
) {
return false;
}
return true;
}
/**
* Get Auto update setting status.
*
* @return bool
*/
public function get_auto_update_setting() {
return in_array( 'seo-by-rank-math-pro/rank-math-pro.php', (array) get_site_option( 'auto_update_plugins', [] ), true );
}
/**
* Connect auto-update toggles: if we enable it for the Pro, then Free should be enabled too,
* and if we disable it for Free then it should be disabled for the Pro too.
*
* @param string $option Option name.
* @param mixed $value Option value.
* @param mixed $old_value Previous option value before the change.
* @param int $network_id Network ID.
* @return void
*/
public function connect_auto_update_toggles( $option, $value, $old_value, $network_id ) {
$this->remove_action( 'update_site_option_auto_update_plugins', 'connect_auto_update_toggles', 20 );
if ( ! is_array( $value ) ) {
return;
}
$free_file = 'seo-by-rank-math/rank-math.php';
$pro_file = 'seo-by-rank-math-pro/rank-math-pro.php';
// If we just enabled it for Rank Math SEO Pro.
if ( in_array( $pro_file, $value, true ) && ! in_array( $pro_file, $old_value, true ) && ! in_array( $free_file, $value, true ) ) {
$value[] = $free_file;
update_site_option( $option, $value );
return;
}
// If we just disabled it for Rank Math SEO Free.
if ( ! in_array( $free_file, $value, true ) && in_array( $free_file, $old_value, true ) && in_array( $pro_file, $value, true ) ) {
$value = array_diff( $value, [ $pro_file ] );
update_site_option( $option, $value );
return;
}
}
}
Fatal error: Uncaught Error: Class 'RankMathPro\Plugin_Update\Plugin_Update' not found in /home/candoodesigncom/public_html/wp-content/plugins/seo-by-rank-math-pro/rank-math-pro.php:382
Stack trace:
#0 /home/candoodesigncom/public_html/wp-includes/class-wp-hook.php(324): RankMathPro->init('')
#1 /home/candoodesigncom/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#2 /home/candoodesigncom/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#3 /home/candoodesigncom/public_html/wp-settings.php(555): do_action('plugins_loaded')
#4 /home/candoodesigncom/public_html/wp-config.php(100): require_once('/home/candoodes...')
#5 /home/candoodesigncom/public_html/wp-load.php(50): require_once('/home/candoodes...')
#6 /home/candoodesigncom/public_html/wp-blog-header.php(13): require_once('/home/candoodes...')
#7 /home/candoodesigncom/public_html/index.php(17): require('/home/candoodes...')
#8 {main}
thrown in /home/candoodesigncom/public_html/wp-content/plugins/seo-by-rank-math-pro/rank-math-pro.php on line 382