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/wordpres.../src/integrat.../admin
File: workouts-integration.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations\Admin;
[2] Fix | Delete
[3] Fix | Delete
use WPSEO_Addon_Manager;
[4] Fix | Delete
use WPSEO_Admin_Asset_Manager;
[5] Fix | Delete
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
[6] Fix | Delete
use Yoast\WP\SEO\Helpers\Options_Helper;
[7] Fix | Delete
use Yoast\WP\SEO\Helpers\Product_Helper;
[8] Fix | Delete
use Yoast\WP\SEO\Integrations\Integration_Interface;
[9] Fix | Delete
use Yoast\WP\SEO\Presenters\Admin\Notice_Presenter;
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* WorkoutsIntegration class
[13] Fix | Delete
*/
[14] Fix | Delete
class Workouts_Integration implements Integration_Interface {
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* The admin asset manager.
[18] Fix | Delete
*
[19] Fix | Delete
* @var WPSEO_Admin_Asset_Manager
[20] Fix | Delete
*/
[21] Fix | Delete
private $admin_asset_manager;
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* The addon manager.
[25] Fix | Delete
*
[26] Fix | Delete
* @var WPSEO_Addon_Manager
[27] Fix | Delete
*/
[28] Fix | Delete
private $addon_manager;
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* The options helper.
[32] Fix | Delete
*
[33] Fix | Delete
* @var Options_Helper
[34] Fix | Delete
*/
[35] Fix | Delete
private $options_helper;
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* The product helper.
[39] Fix | Delete
*
[40] Fix | Delete
* @var Product_Helper
[41] Fix | Delete
*/
[42] Fix | Delete
private $product_helper;
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* {@inheritDoc}
[46] Fix | Delete
*/
[47] Fix | Delete
public static function get_conditionals() {
[48] Fix | Delete
return [ Admin_Conditional::class ];
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Workouts_Integration constructor.
[53] Fix | Delete
*
[54] Fix | Delete
* @param WPSEO_Addon_Manager $addon_manager The addon manager.
[55] Fix | Delete
* @param WPSEO_Admin_Asset_Manager $admin_asset_manager The admin asset manager.
[56] Fix | Delete
* @param Options_Helper $options_helper The options helper.
[57] Fix | Delete
* @param Product_Helper $product_helper The product helper.
[58] Fix | Delete
*/
[59] Fix | Delete
public function __construct(
[60] Fix | Delete
WPSEO_Addon_Manager $addon_manager,
[61] Fix | Delete
WPSEO_Admin_Asset_Manager $admin_asset_manager,
[62] Fix | Delete
Options_Helper $options_helper,
[63] Fix | Delete
Product_Helper $product_helper
[64] Fix | Delete
) {
[65] Fix | Delete
$this->addon_manager = $addon_manager;
[66] Fix | Delete
$this->admin_asset_manager = $admin_asset_manager;
[67] Fix | Delete
$this->options_helper = $options_helper;
[68] Fix | Delete
$this->product_helper = $product_helper;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* {@inheritDoc}
[73] Fix | Delete
*/
[74] Fix | Delete
public function register_hooks() {
[75] Fix | Delete
\add_filter( 'wpseo_submenu_pages', [ $this, 'add_submenu_page' ], 8 );
[76] Fix | Delete
\add_filter( 'wpseo_submenu_pages', [ $this, 'remove_old_submenu_page' ], 10 );
[77] Fix | Delete
\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ], 11 );
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Adds the workouts submenu page.
[82] Fix | Delete
*
[83] Fix | Delete
* @param array $submenu_pages The Yoast SEO submenu pages.
[84] Fix | Delete
*
[85] Fix | Delete
* @return array The filtered submenu pages.
[86] Fix | Delete
*/
[87] Fix | Delete
public function add_submenu_page( $submenu_pages ) {
[88] Fix | Delete
$submenu_pages[] = [
[89] Fix | Delete
'wpseo_dashboard',
[90] Fix | Delete
'',
[91] Fix | Delete
\__( 'Workouts', 'wordpress-seo' ) . ' <span class="yoast-badge yoast-premium-badge"></span>',
[92] Fix | Delete
'edit_others_posts',
[93] Fix | Delete
'wpseo_workouts',
[94] Fix | Delete
[ $this, 'render_target' ],
[95] Fix | Delete
];
[96] Fix | Delete
[97] Fix | Delete
return $submenu_pages;
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* Removes the workouts submenu page from older Premium versions
[102] Fix | Delete
*
[103] Fix | Delete
* @param array $submenu_pages The Yoast SEO submenu pages.
[104] Fix | Delete
*
[105] Fix | Delete
* @return array The filtered submenu pages.
[106] Fix | Delete
*/
[107] Fix | Delete
public function remove_old_submenu_page( $submenu_pages ) {
[108] Fix | Delete
if ( ! $this->should_update_premium() ) {
[109] Fix | Delete
return $submenu_pages;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
// Copy only the Workouts page item that comes first in the array.
[113] Fix | Delete
$result_submenu_pages = [];
[114] Fix | Delete
$workouts_page_encountered = false;
[115] Fix | Delete
foreach ( $submenu_pages as $item ) {
[116] Fix | Delete
if ( $item[4] !== 'wpseo_workouts' || ! $workouts_page_encountered ) {
[117] Fix | Delete
$result_submenu_pages[] = $item;
[118] Fix | Delete
}
[119] Fix | Delete
if ( $item[4] === 'wpseo_workouts' ) {
[120] Fix | Delete
$workouts_page_encountered = true;
[121] Fix | Delete
}
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
return $result_submenu_pages;
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Enqueue the workouts app.
[129] Fix | Delete
*
[130] Fix | Delete
* @return void
[131] Fix | Delete
*/
[132] Fix | Delete
public function enqueue_assets() {
[133] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Date is not processed or saved.
[134] Fix | Delete
if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'wpseo_workouts' ) {
[135] Fix | Delete
return;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
if ( $this->should_update_premium() ) {
[139] Fix | Delete
\wp_dequeue_script( 'yoast-seo-premium-workouts' );
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
$this->admin_asset_manager->enqueue_style( 'workouts' );
[143] Fix | Delete
[144] Fix | Delete
$workouts_option = $this->get_workouts_option();
[145] Fix | Delete
[146] Fix | Delete
$this->admin_asset_manager->enqueue_script( 'workouts' );
[147] Fix | Delete
$this->admin_asset_manager->localize_script(
[148] Fix | Delete
'workouts',
[149] Fix | Delete
'wpseoWorkoutsData',
[150] Fix | Delete
[
[151] Fix | Delete
'workouts' => $workouts_option,
[152] Fix | Delete
'homeUrl' => \home_url(),
[153] Fix | Delete
'pluginUrl' => \esc_url( \plugins_url( '', \WPSEO_FILE ) ),
[154] Fix | Delete
'toolsPageUrl' => \esc_url( \admin_url( 'admin.php?page=wpseo_tools' ) ),
[155] Fix | Delete
'usersPageUrl' => \esc_url( \admin_url( 'users.php' ) ),
[156] Fix | Delete
'firstTimeConfigurationUrl' => \esc_url( \admin_url( 'admin.php?page=wpseo_dashboard#top#first-time-configuration' ) ),
[157] Fix | Delete
'isPremium' => $this->product_helper->is_premium(),
[158] Fix | Delete
'upsellText' => $this->get_upsell_text(),
[159] Fix | Delete
'upsellLink' => $this->get_upsell_link(),
[160] Fix | Delete
]
[161] Fix | Delete
);
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
/**
[165] Fix | Delete
* Renders the target for the React to mount to.
[166] Fix | Delete
*
[167] Fix | Delete
* @return void
[168] Fix | Delete
*/
[169] Fix | Delete
public function render_target() {
[170] Fix | Delete
if ( $this->should_update_premium() ) {
[171] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in get_update_premium_notice.
[172] Fix | Delete
echo $this->get_update_premium_notice();
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
echo '<div id="wpseo-workouts-container-free" class="yoast"></div>';
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
/**
[179] Fix | Delete
* Gets the workouts option.
[180] Fix | Delete
*
[181] Fix | Delete
* @return mixed|null Returns workouts option if found, null if not.
[182] Fix | Delete
*/
[183] Fix | Delete
private function get_workouts_option() {
[184] Fix | Delete
$workouts_option = $this->options_helper->get( 'workouts_data' );
[185] Fix | Delete
[186] Fix | Delete
// This filter is documented in src/routes/workouts-route.php.
[187] Fix | Delete
return \apply_filters( 'Yoast\WP\SEO\workouts_options', $workouts_option );
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
/**
[191] Fix | Delete
* Returns the notification to show when Premium needs to be updated.
[192] Fix | Delete
*
[193] Fix | Delete
* @return string The notification to update Premium.
[194] Fix | Delete
*/
[195] Fix | Delete
private function get_update_premium_notice() {
[196] Fix | Delete
$url = $this->get_upsell_link();
[197] Fix | Delete
[198] Fix | Delete
if ( $this->has_premium_subscription_expired() ) {
[199] Fix | Delete
/* translators: %s: expands to 'Yoast SEO Premium'. */
[200] Fix | Delete
$title = \sprintf( \__( 'Renew your subscription of %s', 'wordpress-seo' ), 'Yoast SEO Premium' );
[201] Fix | Delete
$copy = \sprintf(
[202] Fix | Delete
/* translators: %s: expands to 'Yoast SEO Premium'. */
[203] Fix | Delete
\esc_html__(
[204] Fix | Delete
'Accessing the latest workouts requires an updated version of %s (at least 17.7), but it looks like your subscription has expired. Please renew your subscription to update and gain access to all the latest features.',
[205] Fix | Delete
'wordpress-seo'
[206] Fix | Delete
),
[207] Fix | Delete
'Yoast SEO Premium'
[208] Fix | Delete
);
[209] Fix | Delete
$button = '<a class="yoast-button yoast-button-upsell yoast-button--small" href="' . \esc_url( $url ) . '" target="_blank">'
[210] Fix | Delete
. \esc_html__( 'Renew your subscription', 'wordpress-seo' )
[211] Fix | Delete
/* translators: Hidden accessibility text. */
[212] Fix | Delete
. '<span class="screen-reader-text">' . \__( '(Opens in a new browser tab)', 'wordpress-seo' ) . '</span>'
[213] Fix | Delete
. '<span aria-hidden="true" class="yoast-button-upsell__caret"></span>'
[214] Fix | Delete
. '</a>';
[215] Fix | Delete
}
[216] Fix | Delete
elseif ( $this->has_premium_subscription_activated() ) {
[217] Fix | Delete
/* translators: %s: expands to 'Yoast SEO Premium'. */
[218] Fix | Delete
$title = \sprintf( \__( 'Update to the latest version of %s', 'wordpress-seo' ), 'Yoast SEO Premium' );
[219] Fix | Delete
$copy = \sprintf(
[220] Fix | Delete
/* translators: 1: expands to 'Yoast SEO Premium', 2: Link start tag to the page to update Premium, 3: Link closing tag. */
[221] Fix | Delete
\esc_html__( 'It looks like you\'re running an outdated version of %1$s, please %2$supdate to the latest version (at least 17.7)%3$s to gain access to our updated workouts section.', 'wordpress-seo' ),
[222] Fix | Delete
'Yoast SEO Premium',
[223] Fix | Delete
'<a href="' . \esc_url( $url ) . '">',
[224] Fix | Delete
'</a>'
[225] Fix | Delete
);
[226] Fix | Delete
$button = null;
[227] Fix | Delete
}
[228] Fix | Delete
else {
[229] Fix | Delete
/* translators: %s: expands to 'Yoast SEO Premium'. */
[230] Fix | Delete
$title = \sprintf( \__( 'Activate your subscription of %s', 'wordpress-seo' ), 'Yoast SEO Premium' );
[231] Fix | Delete
$url_button = 'https://yoa.st/workouts-activate-notice-help';
[232] Fix | Delete
$copy = \sprintf(
[233] Fix | Delete
/* translators: 1: expands to 'Yoast SEO Premium', 2: Link start tag to the page to update Premium, 3: Link closing tag. */
[234] Fix | Delete
\esc_html__( 'It looks like you’re running an outdated and unactivated version of %1$s, please activate your subscription in %2$sMyYoast%3$s and update to the latest version (at least 17.7) to gain access to our updated workouts section.', 'wordpress-seo' ),
[235] Fix | Delete
'Yoast SEO Premium',
[236] Fix | Delete
'<a href="' . \esc_url( $url ) . '">',
[237] Fix | Delete
'</a>'
[238] Fix | Delete
);
[239] Fix | Delete
$button = '<a class="yoast-button yoast-button--primary yoast-button--small" href="' . \esc_url( $url_button ) . '" target="_blank">'
[240] Fix | Delete
. \esc_html__( 'Get help activating your subscription', 'wordpress-seo' )
[241] Fix | Delete
/* translators: Hidden accessibility text. */
[242] Fix | Delete
. '<span class="screen-reader-text">' . \__( '(Opens in a new browser tab)', 'wordpress-seo' ) . '</span>'
[243] Fix | Delete
. '</a>';
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
$notice = new Notice_Presenter(
[247] Fix | Delete
$title,
[248] Fix | Delete
$copy,
[249] Fix | Delete
null,
[250] Fix | Delete
$button
[251] Fix | Delete
);
[252] Fix | Delete
[253] Fix | Delete
return $notice->present();
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* Check whether Premium should be updated.
[258] Fix | Delete
*
[259] Fix | Delete
* @return bool Returns true when Premium is enabled and the version is below 17.7.
[260] Fix | Delete
*/
[261] Fix | Delete
private function should_update_premium() {
[262] Fix | Delete
$premium_version = $this->product_helper->get_premium_version();
[263] Fix | Delete
return $premium_version !== null && \version_compare( $premium_version, '17.7-RC1', '<' );
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
/**
[267] Fix | Delete
* Check whether the Premium subscription has expired.
[268] Fix | Delete
*
[269] Fix | Delete
* @return bool Returns true when Premium subscription has expired.
[270] Fix | Delete
*/
[271] Fix | Delete
private function has_premium_subscription_expired() {
[272] Fix | Delete
$subscription = $this->addon_manager->get_subscription( WPSEO_Addon_Manager::PREMIUM_SLUG );
[273] Fix | Delete
[274] Fix | Delete
return ( isset( $subscription->expiry_date ) && ( \strtotime( $subscription->expiry_date ) - \time() ) < 0 );
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
/**
[278] Fix | Delete
* Check whether the Premium subscription is activated.
[279] Fix | Delete
*
[280] Fix | Delete
* @return bool Returns true when Premium subscription is activated.
[281] Fix | Delete
*/
[282] Fix | Delete
private function has_premium_subscription_activated() {
[283] Fix | Delete
return $this->addon_manager->has_valid_subscription( WPSEO_Addon_Manager::PREMIUM_SLUG );
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
/**
[287] Fix | Delete
* Returns the upsell/update copy to show in the card buttons.
[288] Fix | Delete
*
[289] Fix | Delete
* @return string Returns a string with the upsell/update copy for the card buttons.
[290] Fix | Delete
*/
[291] Fix | Delete
private function get_upsell_text() {
[292] Fix | Delete
if ( ! $this->product_helper->is_premium() || ! $this->should_update_premium() ) {
[293] Fix | Delete
// Use the default defined in the component.
[294] Fix | Delete
return '';
[295] Fix | Delete
}
[296] Fix | Delete
if ( $this->has_premium_subscription_expired() ) {
[297] Fix | Delete
return \sprintf(
[298] Fix | Delete
/* translators: %s: expands to 'Yoast SEO Premium'. */
[299] Fix | Delete
\__( 'Renew %s', 'wordpress-seo' ),
[300] Fix | Delete
'Yoast SEO Premium'
[301] Fix | Delete
);
[302] Fix | Delete
}
[303] Fix | Delete
if ( $this->has_premium_subscription_activated() ) {
[304] Fix | Delete
return \sprintf(
[305] Fix | Delete
/* translators: %s: expands to 'Yoast SEO Premium'. */
[306] Fix | Delete
\__( 'Update %s', 'wordpress-seo' ),
[307] Fix | Delete
'Yoast SEO Premium'
[308] Fix | Delete
);
[309] Fix | Delete
}
[310] Fix | Delete
return \sprintf(
[311] Fix | Delete
/* translators: %s: expands to 'Yoast SEO Premium'. */
[312] Fix | Delete
\__( 'Activate %s', 'wordpress-seo' ),
[313] Fix | Delete
'Yoast SEO Premium'
[314] Fix | Delete
);
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
/**
[318] Fix | Delete
* Returns the upsell/update link to show in the card buttons.
[319] Fix | Delete
*
[320] Fix | Delete
* @return string Returns a string with the upsell/update link for the card buttons.
[321] Fix | Delete
*/
[322] Fix | Delete
private function get_upsell_link() {
[323] Fix | Delete
if ( ! $this->product_helper->is_premium() || ! $this->should_update_premium() ) {
[324] Fix | Delete
// Use the default defined in the component.
[325] Fix | Delete
return '';
[326] Fix | Delete
}
[327] Fix | Delete
if ( $this->has_premium_subscription_expired() ) {
[328] Fix | Delete
return 'https://yoa.st/workout-renew-notice';
[329] Fix | Delete
}
[330] Fix | Delete
if ( $this->has_premium_subscription_activated() ) {
[331] Fix | Delete
return \wp_nonce_url( \self_admin_url( 'update.php?action=upgrade-plugin&plugin=wordpress-seo-premium/wp-seo-premium.php' ), 'upgrade-plugin_wordpress-seo-premium/wp-seo-premium.php' );
[332] Fix | Delete
}
[333] Fix | Delete
return 'https://yoa.st/workouts-activate-notice-myyoast';
[334] Fix | Delete
}
[335] Fix | Delete
}
[336] Fix | Delete
[337] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function