class-expose-shortlinks.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. * @var array Array containing the keys and shortlinks.
  13. */
  14. private $shortlinks = array(
  15. 'shortlinks.focus_keyword_info' => 'https://yoa.st/focus-keyword',
  16. 'shortlinks.snippet_preview_info' => 'https://yoa.st/snippet-preview',
  17. 'shortlinks.cornerstone_content_info' => 'https://yoa.st/1i9',
  18. 'shortlinks.upsell.sidebar.focus_keyword_synonyms_link' => 'https://yoa.st/textlink-synonyms-popup-sidebar',
  19. 'shortlinks.upsell.sidebar.focus_keyword_synonyms_button' => 'https://yoa.st/keyword-synonyms-popup-sidebar',
  20. 'shortlinks.upsell.sidebar.focus_keyword_additional_link' => 'https://yoa.st/textlink-keywords-popup-sidebar',
  21. 'shortlinks.upsell.sidebar.focus_keyword_additional_button' => 'https://yoa.st/add-keywords-popup-sidebar',
  22. 'shortlinks.upsell.sidebar.additional_link' => 'https://yoa.st/textlink-keywords-sidebar',
  23. 'shortlinks.upsell.sidebar.additional_button' => 'https://yoa.st/add-keywords-sidebar',
  24. 'shortlinks.upsell.metabox.go_premium' => 'https://yoa.st/pe-premium-page',
  25. 'shortlinks.upsell.metabox.focus_keyword_synonyms_link' => 'https://yoa.st/textlink-synonyms-popup-metabox',
  26. 'shortlinks.upsell.metabox.focus_keyword_synonyms_button' => 'https://yoa.st/keyword-synonyms-popup',
  27. 'shortlinks.upsell.metabox.focus_keyword_additional_link' => 'https://yoa.st/textlink-keywords-popup-metabox',
  28. 'shortlinks.upsell.metabox.focus_keyword_additional_button' => 'https://yoa.st/add-keywords-popup',
  29. 'shortlinks.upsell.metabox.additional_link' => 'https://yoa.st/textlink-keywords-metabox',
  30. 'shortlinks.upsell.metabox.additional_button' => 'https://yoa.st/add-keywords-metabox',
  31. 'shortlinks.readability_analysis_info' => 'https://yoa.st/readability-analysis',
  32. );
  33. /**
  34. * Registers all hooks to WordPress.
  35. *
  36. * @return void
  37. */
  38. public function register_hooks() {
  39. add_filter( 'wpseo_admin_l10n', array( $this, 'expose_shortlinks' ) );
  40. }
  41. /**
  42. * Adds shortlinks to the passed array.
  43. *
  44. * @param array $input The array to add shortlinks to.
  45. *
  46. * @return array The passed array with the additional shortlinks.
  47. */
  48. public function expose_shortlinks( $input ) {
  49. foreach ( $this->shortlinks as $key => $shortlink ) {
  50. $input[ $key ] = WPSEO_Shortlinker::get( $shortlink );
  51. }
  52. return $input;
  53. }
  54. }