class-expose-shortlinks.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * Exposes shortlinks in a global, so that we can pass them to our Javascript components.
  9. */
  10. class WPSEO_Expose_Shortlinks implements WPSEO_WordPress_Integration {
  11. /**
  12. * Array containing the keys and shortlinks.
  13. *
  14. * @var array
  15. */
  16. private $shortlinks = [
  17. 'shortlinks.focus_keyword_info' => 'https://yoa.st/focus-keyword',
  18. 'shortlinks.snippet_preview_info' => 'https://yoa.st/snippet-preview',
  19. 'shortlinks.cornerstone_content_info' => 'https://yoa.st/1i9',
  20. 'shortlinks.upsell.sidebar.focus_keyword_synonyms_link' => 'https://yoa.st/textlink-synonyms-popup-sidebar',
  21. 'shortlinks.upsell.sidebar.focus_keyword_synonyms_button' => 'https://yoa.st/keyword-synonyms-popup-sidebar',
  22. 'shortlinks.upsell.sidebar.focus_keyword_additional_link' => 'https://yoa.st/textlink-keywords-popup-sidebar',
  23. 'shortlinks.upsell.sidebar.focus_keyword_additional_button' => 'https://yoa.st/add-keywords-popup-sidebar',
  24. 'shortlinks.upsell.sidebar.additional_link' => 'https://yoa.st/textlink-keywords-sidebar',
  25. 'shortlinks.upsell.sidebar.additional_button' => 'https://yoa.st/add-keywords-sidebar',
  26. 'shortlinks.upsell.metabox.go_premium' => 'https://yoa.st/pe-premium-page',
  27. 'shortlinks.upsell.metabox.focus_keyword_synonyms_link' => 'https://yoa.st/textlink-synonyms-popup-metabox',
  28. 'shortlinks.upsell.metabox.focus_keyword_synonyms_button' => 'https://yoa.st/keyword-synonyms-popup',
  29. 'shortlinks.upsell.metabox.focus_keyword_additional_link' => 'https://yoa.st/textlink-keywords-popup-metabox',
  30. 'shortlinks.upsell.metabox.focus_keyword_additional_button' => 'https://yoa.st/add-keywords-popup',
  31. 'shortlinks.upsell.metabox.additional_link' => 'https://yoa.st/textlink-keywords-metabox',
  32. 'shortlinks.upsell.metabox.additional_button' => 'https://yoa.st/add-keywords-metabox',
  33. 'shortlinks.upsell.gsc.create_redirect_button' => 'https://yoa.st/redirects',
  34. 'shortlinks.readability_analysis_info' => 'https://yoa.st/readability-analysis',
  35. 'shortlinks.activate_premium_info' => 'https://yoa.st/activate-subscription',
  36. 'shortlinks.upsell.sidebar.morphology_upsell_metabox' => 'https://yoa.st/morphology-upsell-metabox',
  37. 'shortlinks.upsell.sidebar.morphology_upsell_sidebar' => 'https://yoa.st/morphology-upsell-sidebar',
  38. ];
  39. /**
  40. * Registers all hooks to WordPress.
  41. *
  42. * @return void
  43. */
  44. public function register_hooks() {
  45. add_filter( 'wpseo_admin_l10n', [ $this, 'expose_shortlinks' ] );
  46. }
  47. /**
  48. * Adds shortlinks to the passed array.
  49. *
  50. * @param array $input The array to add shortlinks to.
  51. *
  52. * @return array The passed array with the additional shortlinks.
  53. */
  54. public function expose_shortlinks( $input ) {
  55. foreach ( $this->get_shortlinks() as $key => $shortlink ) {
  56. $input[ $key ] = WPSEO_Shortlinker::get( $shortlink );
  57. }
  58. $input['default_query_params'] = WPSEO_Shortlinker::get_query_params();
  59. return $input;
  60. }
  61. /**
  62. * Retrieves the shortlinks.
  63. *
  64. * @return array The shortlinks.
  65. */
  66. private function get_shortlinks() {
  67. if ( ! $this->is_term_edit() ) {
  68. return $this->shortlinks;
  69. }
  70. $shortlinks = $this->shortlinks;
  71. $shortlinks['shortlinks.upsell.metabox.focus_keyword_synonyms_link'] = 'https://yoa.st/textlink-synonyms-popup-metabox-term';
  72. $shortlinks['shortlinks.upsell.metabox.focus_keyword_synonyms_button'] = 'https://yoa.st/keyword-synonyms-popup-term';
  73. $shortlinks['shortlinks.upsell.metabox.focus_keyword_additional_link'] = 'https://yoa.st/textlink-keywords-popup-metabox-term';
  74. $shortlinks['shortlinks.upsell.metabox.focus_keyword_additional_button'] = 'https://yoa.st/add-keywords-popup-term';
  75. $shortlinks['shortlinks.upsell.metabox.additional_link'] = 'https://yoa.st/textlink-keywords-metabox-term';
  76. $shortlinks['shortlinks.upsell.metabox.additional_button'] = 'https://yoa.st/add-keywords-metabox-term';
  77. $shortlinks['shortlinks.upsell.sidebar.morphology_upsell_metabox'] = 'https://yoa.st/morphology-upsell-metabox-term';
  78. return $shortlinks;
  79. }
  80. /**
  81. * Checks if the current page is a term edit page.
  82. *
  83. * @return bool True when page is term edit.
  84. */
  85. private function is_term_edit() {
  86. global $pagenow;
  87. return WPSEO_Taxonomy::is_term_edit( $pagenow );
  88. }
  89. }