| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Integrations\Admin; |
| 4 |
|
| 5 |
use WPSEO_Admin_Utils; |
| 6 |
use WPSEO_Option; |
| 7 |
use WPSEO_Option_Tab; |
| 8 |
use WPSEO_Option_Tabs; |
| 9 |
use WPSEO_Shortlinker; |
| 10 |
use Yoast\WP\SEO\Conditionals\Admin_Conditional; |
| 11 |
use Yoast\WP\SEO\Helpers\Product_Helper; |
| 12 |
use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 13 |
use Yoast_Form; |
| 14 |
|
| 15 |
/** |
| 16 |
* Crawl_Settings_Integration class |
| 17 |
*/ |
| 18 |
class Crawl_Settings_Integration implements Integration_Interface { |
| 19 |
|
| 20 |
/** |
| 21 |
* The product helper. |
| 22 |
* |
| 23 |
* @var Product_Helper |
| 24 |
*/ |
| 25 |
private $product_helper; |
| 26 |
|
| 27 |
/** |
| 28 |
* Crawl_Settings_Integration constructor. |
| 29 |
* |
| 30 |
* @param Product_Helper $product_helper The product helper. |
| 31 |
*/ |
| 32 |
public function __construct( |
| 33 |
Product_Helper $product_helper |
| 34 |
) { |
| 35 |
$this->product_helper = $product_helper; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Returns the conditionals based in which this loadable should be active. |
| 40 |
* |
| 41 |
* In this case: when on an admin page. |
| 42 |
*/ |
| 43 |
public static function get_conditionals() { |
| 44 |
return [ Admin_Conditional::class ]; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Registers an action to add a new tab to the General page. |
| 49 |
*/ |
| 50 |
public function register_hooks() { |
| 51 |
\add_action( 'wpseo_settings_tabs_dashboard', [ $this, 'add_crawl_settings_tab' ] ); |
| 52 |
if ( ! $this->product_helper->is_premium() || ! $this->is_premium_upgraded() ) { |
| 53 |
\add_action( 'wpseo_settings_tab_crawl_cleanup', [ $this, 'add_crawl_settings_tab_content' ] ); |
| 54 |
\add_action( 'wpseo_settings_tab_crawl_cleanup_network', [ $this, 'add_crawl_settings_tab_content_network' ] ); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Checks if Premium is installed and upgraded to the right version. |
| 60 |
* |
| 61 |
* @return bool Whether Premium is installed and upgraded to the right version. |
| 62 |
*/ |
| 63 |
public function is_premium_upgraded() { |
| 64 |
$premium_version = $this->product_helper->get_premium_version(); |
| 65 |
return $premium_version !== null && \version_compare( $premium_version, '18.6-RC1', '>=' ); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Adds a dedicated tab in the General sub-page. |
| 70 |
* |
| 71 |
* @param WPSEO_Option_Tabs $dashboard_tabs Object representing the tabs of the General sub-page. |
| 72 |
*/ |
| 73 |
public function add_crawl_settings_tab( $dashboard_tabs ) { |
| 74 |
$premium = $this->product_helper->is_premium() && $this->is_premium_upgraded(); |
| 75 |
|
| 76 |
$dashboard_tabs->add_tab( |
| 77 |
new WPSEO_Option_Tab( |
| 78 |
'crawl-settings', |
| 79 |
\__( 'Crawl settings', 'wordpress-seo' ), |
| 80 |
[ |
| 81 |
'save_button' => $premium, |
| 82 |
'beta' => $premium, |
| 83 |
'premium' => ! $premium, |
| 84 |
] |
| 85 |
) |
| 86 |
); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Adds content to the Crawl Cleanup tab. |
| 91 |
* |
| 92 |
* @param Yoast_Form $yform The yoast form object. |
| 93 |
*/ |
| 94 |
public function add_crawl_settings_tab_content( $yform ) { |
| 95 |
$this->display_premium_upsell_btn(); |
| 96 |
|
| 97 |
$yform->toggle_switch( |
| 98 |
'remove_feed_post_comments_free', |
| 99 |
[ |
| 100 |
'off' => __( 'Keep', 'wordpress-seo' ), |
| 101 |
'on' => __( 'Remove', 'wordpress-seo' ), |
| 102 |
], |
| 103 |
__( 'Post comment feeds', 'wordpress-seo' ), |
| 104 |
'', |
| 105 |
[ |
| 106 |
'disabled' => true, |
| 107 |
] |
| 108 |
); |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Adds content to the Crawl Cleanup network tab. |
| 113 |
* |
| 114 |
* @param Yoast_Form $yform The yoast form object. |
| 115 |
*/ |
| 116 |
public function add_crawl_settings_tab_content_network( $yform ) { |
| 117 |
$this->display_premium_upsell_btn(); |
| 118 |
|
| 119 |
$yform->toggle_switch( |
| 120 |
WPSEO_Option::ALLOW_KEY_PREFIX . 'remove_feed_post_comments_free', |
| 121 |
[ |
| 122 |
'on' => __( 'Allow Control', 'wordpress-seo' ), |
| 123 |
'off' => __( 'Disable', 'wordpress-seo' ), |
| 124 |
], |
| 125 |
__( 'Post comment feeds', 'wordpress-seo' ), |
| 126 |
'', |
| 127 |
[ |
| 128 |
'disabled' => true, |
| 129 |
] |
| 130 |
); |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Displays the Premium upsell button. |
| 135 |
*/ |
| 136 |
public function display_premium_upsell_btn() { |
| 137 |
echo '<a class="yoast-button-upsell" href="'; |
| 138 |
echo \esc_url( WPSEO_Shortlinker::get( 'http://yoa.st/crawl-settings-upsell' ) ); |
| 139 |
echo '" target="_blank" style=" margin-top: 16px; margin-bottom: 16px; ">'; |
| 140 |
|
| 141 |
$button_msg = ( $this->product_helper->is_premium() && ! $this->is_premium_upgraded() ) ? \esc_html__( 'Upgrade Premium', 'wordpress-seo' ) : \esc_html__( 'Unlock with Premium', 'wordpress-seo' ); |
| 142 |
// phpcs:ignore WordPress.Security.EscapeOutput -- Already escaped. |
| 143 |
echo $button_msg |
| 144 |
// phpcs:ignore WordPress.Security.EscapeOutput -- Already escapes correctly. |
| 145 |
. WPSEO_Admin_Utils::get_new_tab_message(); |
| 146 |
echo '<span aria-hidden="true" class="yoast-button-upsell__caret"></span></a>'; |
| 147 |
} |
| 148 |
} |
| 149 |
|