class-admin-utils.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * Represents the utils for the admin.
  9. */
  10. class WPSEO_Admin_Utils {
  11. /**
  12. * Gets the install URL for the passed plugin slug.
  13. *
  14. * @param string $slug The slug to create an install link for.
  15. *
  16. * @return string The install URL. Empty string if the current user doesn't have the proper capabilities.
  17. */
  18. public static function get_install_url( $slug ) {
  19. if ( ! current_user_can( 'install_plugins' ) ) {
  20. return '';
  21. }
  22. return wp_nonce_url(
  23. self_admin_url( 'update.php?action=install-plugin&plugin=' . dirname( $slug ) ),
  24. 'install-plugin_' . dirname( $slug )
  25. );
  26. }
  27. /**
  28. * Gets the activation URL for the passed plugin slug.
  29. *
  30. * @param string $slug The slug to create an activation link for.
  31. *
  32. * @return string The activation URL. Empty string if the current user doesn't have the proper capabilities.
  33. */
  34. public static function get_activation_url( $slug ) {
  35. if ( ! current_user_can( 'install_plugins' ) ) {
  36. return '';
  37. }
  38. return wp_nonce_url(
  39. self_admin_url( 'plugins.php?action=activate&plugin_status=all&paged=1&s&plugin=' . $slug ),
  40. 'activate-plugin_' . $slug
  41. );
  42. }
  43. /**
  44. * Creates a link if the passed plugin is deemend a directly-installable plugin.
  45. *
  46. * @param array $plugin The plugin to create the link for.
  47. *
  48. * @return string The link to the plugin install. Returns the title if the plugin is deemed a Premium product.
  49. */
  50. public static function get_install_link( $plugin ) {
  51. $install_url = self::get_install_url( $plugin['slug'] );
  52. if ( $install_url === '' || ( isset( $plugin['premium'] ) && $plugin['premium'] === true ) ) {
  53. return $plugin['title'];
  54. }
  55. return sprintf(
  56. '<a href="%s">%s</a>',
  57. $install_url,
  58. $plugin['title']
  59. );
  60. }
  61. /**
  62. * Gets a visually hidden accessible message for links that open in a new browser tab.
  63. *
  64. * @return string The visually hidden accessible message.
  65. */
  66. public static function get_new_tab_message() {
  67. return sprintf(
  68. '<span class="screen-reader-text">%s</span>',
  69. esc_html__( '(Opens in a new browser tab)', 'wordpress-seo' )
  70. );
  71. }
  72. /* ********************* DEPRECATED METHODS ********************* */
  73. /**
  74. * Determines whether or not the user has an invalid version of PHP installed.
  75. *
  76. * @deprecated 8.1
  77. * @codeCoverageIgnore
  78. *
  79. * @return bool Whether or not PHP 5.2 or lower is installed.
  80. */
  81. public static function is_supported_php_version_installed() {
  82. // Intentionally left blank.
  83. return true;
  84. }
  85. }