wpseo-non-ajax-functions.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Internals
  6. */
  7. if ( ! defined( 'WPSEO_VERSION' ) ) {
  8. header( 'Status: 403 Forbidden' );
  9. header( 'HTTP/1.1 403 Forbidden' );
  10. exit();
  11. }
  12. /**
  13. * Initializes the admin bar.
  14. *
  15. * @return void
  16. */
  17. function wpseo_initialize_admin_bar() {
  18. $admin_bar_menu = new WPSEO_Admin_Bar_Menu();
  19. $admin_bar_menu->register_hooks();
  20. }
  21. add_action( 'wp_loaded', 'wpseo_initialize_admin_bar' );
  22. /**
  23. * Allows editing of the meta fields through weblog editors like Marsedit.
  24. *
  25. * @param array $required_capabilities Capabilities that must all be true to allow action.
  26. * @param array $capabilities Array of capabilities to be checked, unused here.
  27. * @param array $args List of arguments for the specific capabilities to be checked.
  28. *
  29. * @return array $required_capabilities Filtered capabilities.
  30. */
  31. function allow_custom_field_edits( $required_capabilities, $capabilities, $args ) {
  32. if ( ! in_array( $args[0], [ 'edit_post_meta', 'add_post_meta' ], true ) ) {
  33. return $required_capabilities;
  34. }
  35. // If this is provided, it is the post ID.
  36. if ( empty( $args[2] ) ) {
  37. return $required_capabilities;
  38. }
  39. // If this is provided, it is the custom field.
  40. if ( empty( $args[3] ) ) {
  41. return $required_capabilities;
  42. }
  43. // If the meta key is part of the plugin, grant capabilities accordingly.
  44. if ( strpos( $args[3], WPSEO_Meta::$meta_prefix ) === 0 && current_user_can( 'edit_post', $args[2] ) ) {
  45. $required_capabilities[ $args[0] ] = true;
  46. }
  47. return $required_capabilities;
  48. }
  49. add_filter( 'user_has_cap', 'allow_custom_field_edits', 0, 3 );
  50. /* ********************* DEPRECATED FUNCTIONS ********************* */
  51. /**
  52. * Adds an SEO admin bar menu to the site admin, with several options.
  53. *
  54. * If the current user is an admin they can also go straight to several settings menus from here.
  55. *
  56. * @deprecated 7.9 Use WPSEO_Admin_Bar_Menu::add_menu() instead.
  57. * @codeCoverageIgnore
  58. *
  59. * @return void
  60. */
  61. function wpseo_admin_bar_menu() {
  62. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', 'WPSEO_Admin_Bar_Menu::add_menu()' );
  63. // Only use this admin bar menu for the site admin.
  64. if ( is_admin() && ! is_blog_admin() ) {
  65. return;
  66. }
  67. $options = WPSEO_Options::get_options( [ 'wpseo', 'wpseo_ms' ] );
  68. if ( $options['enable_admin_bar_menu'] !== true ) {
  69. return;
  70. }
  71. global $wp_admin_bar;
  72. $admin_bar_menu = new WPSEO_Admin_Bar_Menu();
  73. $admin_bar_menu->add_menu( $wp_admin_bar );
  74. }
  75. /**
  76. * Returns the SEO score element for the admin bar.
  77. *
  78. * @deprecated 7.9
  79. * @codeCoverageIgnore
  80. *
  81. * @return string
  82. */
  83. function wpseo_adminbar_seo_score() {
  84. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', null );
  85. $rating = WPSEO_Meta::get_value( 'linkdex', get_the_ID() );
  86. return wpseo_adminbar_score( $rating );
  87. }
  88. /**
  89. * Returns the content score element for the adminbar.
  90. *
  91. * @deprecated 7.9
  92. * @codeCoverageIgnore
  93. *
  94. * @return string
  95. */
  96. function wpseo_adminbar_content_score() {
  97. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', null );
  98. $rating = WPSEO_Meta::get_value( 'content_score', get_the_ID() );
  99. return wpseo_adminbar_score( $rating );
  100. }
  101. /**
  102. * Returns the SEO score element for the adminbar.
  103. *
  104. * @deprecated 7.9
  105. * @codeCoverageIgnore
  106. *
  107. * @return string
  108. */
  109. function wpseo_tax_adminbar_seo_score() {
  110. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', null );
  111. $rating = 0;
  112. if ( is_tax() || is_category() || is_tag() ) {
  113. $rating = WPSEO_Taxonomy_Meta::get_meta_without_term( 'linkdex' );
  114. }
  115. return wpseo_adminbar_score( $rating );
  116. }
  117. /**
  118. * Returns the Content score element for the adminbar.
  119. *
  120. * @deprecated 7.9
  121. * @codeCoverageIgnore
  122. *
  123. * @return string
  124. */
  125. function wpseo_tax_adminbar_content_score() {
  126. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', null );
  127. $rating = 0;
  128. if ( is_tax() || is_category() || is_tag() ) {
  129. $rating = WPSEO_Taxonomy_Meta::get_meta_without_term( 'content_score' );
  130. }
  131. return wpseo_adminbar_score( $rating );
  132. }
  133. /**
  134. * Takes The SEO score and makes the score icon for the adminbar with it.
  135. *
  136. * @deprecated 7.9
  137. * @codeCoverageIgnore
  138. *
  139. * @param int $score The 0-100 rating of the score. Can be either SEO score or content score.
  140. *
  141. * @return string $score_adminbar_element
  142. */
  143. function wpseo_adminbar_score( $score ) {
  144. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', null );
  145. $score = WPSEO_Utils::translate_score( $score );
  146. $score_adminbar_element = '<div class="wpseo-score-icon adminbar-seo-score ' . $score . '"><span class="adminbar-seo-score-text screen-reader-text"></span></div>';
  147. return $score_adminbar_element;
  148. }
  149. /**
  150. * Enqueue CSS to format the Yoast SEO adminbar item.
  151. *
  152. * @deprecated 7.9 Use WPSEO_Admin_Bar_Menu::enqueue_assets() instead.
  153. * @codeCoverageIgnore
  154. */
  155. function wpseo_admin_bar_style() {
  156. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', 'WPSEO_Admin_Bar_Menu::enqueue_assets()' );
  157. if ( ! is_admin_bar_showing() || WPSEO_Options::get( 'enable_admin_bar_menu' ) !== true ) {
  158. return;
  159. }
  160. if ( is_admin() && ! is_blog_admin() ) {
  161. return;
  162. }
  163. $admin_bar_menu = new WPSEO_Admin_Bar_Menu();
  164. $admin_bar_menu->enqueue_assets();
  165. }
  166. /**
  167. * Detects if the advanced settings are enabled.
  168. *
  169. * @deprecated 7.0
  170. * @codeCoverageIgnore
  171. */
  172. function wpseo_advanced_settings_enabled() {
  173. _deprecated_function( __FUNCTION__, 'WPSEO 7.0', null );
  174. }