| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Integrations\Admin; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Conditionals\Admin_Conditional; |
| 6 |
use Yoast\WP\SEO\Helpers\Product_Helper; |
| 7 |
use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 8 |
|
| 9 |
/** |
| 10 |
* Brand_Insights_Page class |
| 11 |
*/ |
| 12 |
class Brand_Insights_Page implements Integration_Interface { |
| 13 |
|
| 14 |
/** |
| 15 |
* External link icon. |
| 16 |
*/ |
| 17 |
public const EXTERNAL_LINK_ICON = '<span class="yst-external-link-icon"></span>'; |
| 18 |
|
| 19 |
/** |
| 20 |
* The product helper. |
| 21 |
* |
| 22 |
* @var Product_Helper |
| 23 |
*/ |
| 24 |
private $product_helper; |
| 25 |
|
| 26 |
/** |
| 27 |
* Constructor. |
| 28 |
* |
| 29 |
* @param Product_Helper $product_helper The product helper. |
| 30 |
*/ |
| 31 |
public function __construct( |
| 32 |
Product_Helper $product_helper |
| 33 |
) { |
| 34 |
$this->product_helper = $product_helper; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Returns the conditionals based in which this loadable should be active. |
| 39 |
* |
| 40 |
* @return array<string> |
| 41 |
*/ |
| 42 |
public static function get_conditionals() { |
| 43 |
return [ |
| 44 |
Admin_Conditional::class, |
| 45 |
]; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Registers all hooks to WordPress. |
| 50 |
* |
| 51 |
* @return void |
| 52 |
*/ |
| 53 |
public function register_hooks() { |
| 54 |
// Add page with PHP_INT_MAX so it's always the last item. This is the AI Brand Insights button in the sidebar menu. |
| 55 |
\add_filter( 'wpseo_submenu_pages', [ $this, 'add_submenu_page' ], \PHP_INT_MAX ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Adds the Brand Insights submenu page. |
| 60 |
* |
| 61 |
* @param string[] $submenu_pages The Yoast SEO submenu pages. |
| 62 |
* |
| 63 |
* @return string[] The filtered submenu pages. |
| 64 |
*/ |
| 65 |
public function add_submenu_page( $submenu_pages ) { |
| 66 |
$page = $this->product_helper->is_premium() ? 'wpseo_brand_insights_premium' : 'wpseo_brand_insights'; |
| 67 |
|
| 68 |
$button_content = 'AI Brand Insights'; |
| 69 |
|
| 70 |
$menu_title = '<span class="yoast-brand-insights-gradient-border">' |
| 71 |
. '<span class="yoast-brand-insights-content">' |
| 72 |
. $button_content |
| 73 |
. self::EXTERNAL_LINK_ICON |
| 74 |
. '</span></span>'; |
| 75 |
|
| 76 |
$submenu_pages[] = [ |
| 77 |
'wpseo_dashboard', |
| 78 |
'', |
| 79 |
$menu_title, |
| 80 |
'edit_others_posts', |
| 81 |
$page, |
| 82 |
[ $this, 'show_brand_insights_page' ], |
| 83 |
]; |
| 84 |
|
| 85 |
return $submenu_pages; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* The Brand Insights page render function, noop. |
| 90 |
* |
| 91 |
* @return void |
| 92 |
*/ |
| 93 |
public function show_brand_insights_page() { |
| 94 |
// Do nothing and let the redirect happen from the redirect integration. |
| 95 |
} |
| 96 |
} |
| 97 |
|