wpseo-non-ajax-functions.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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], array( '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 he can also go straight to several settings menu's from here.
  55. *
  56. * @deprecated 7.9 Use WPSEO_Admin_Bar_Menu::add_menu() instead
  57. *
  58. * @return void
  59. */
  60. function wpseo_admin_bar_menu() {
  61. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', 'WPSEO_Admin_Bar_Menu::add_menu()' );
  62. // Only use this admin bar menu for the site admin.
  63. if ( is_admin() && ! is_blog_admin() ) {
  64. return;
  65. }
  66. $options = WPSEO_Options::get_options( array( 'wpseo', 'wpseo_ms' ) );
  67. if ( $options['enable_admin_bar_menu'] !== true ) {
  68. return;
  69. }
  70. global $wp_admin_bar;
  71. $admin_bar_menu = new WPSEO_Admin_Bar_Menu();
  72. $admin_bar_menu->add_menu( $wp_admin_bar );
  73. }
  74. /**
  75. * Returns the SEO score element for the admin bar.
  76. *
  77. * @deprecated 7.9
  78. *
  79. * @return string
  80. */
  81. function wpseo_adminbar_seo_score() {
  82. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', null );
  83. $rating = WPSEO_Meta::get_value( 'linkdex', get_the_ID() );
  84. return wpseo_adminbar_score( $rating );
  85. }
  86. /**
  87. * Returns the content score element for the adminbar.
  88. *
  89. * @deprecated 7.9
  90. *
  91. * @return string
  92. */
  93. function wpseo_adminbar_content_score() {
  94. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', null );
  95. $rating = WPSEO_Meta::get_value( 'content_score', get_the_ID() );
  96. return wpseo_adminbar_score( $rating );
  97. }
  98. /**
  99. * Returns the SEO score element for the adminbar.
  100. *
  101. * @deprecated 7.9
  102. *
  103. * @return string
  104. */
  105. function wpseo_tax_adminbar_seo_score() {
  106. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', null );
  107. $rating = 0;
  108. if ( is_tax() || is_category() || is_tag() ) {
  109. $rating = WPSEO_Taxonomy_Meta::get_meta_without_term( 'linkdex' );
  110. }
  111. return wpseo_adminbar_score( $rating );
  112. }
  113. /**
  114. * Returns the Content score element for the adminbar.
  115. *
  116. * @deprecated 7.9
  117. *
  118. * @return string
  119. */
  120. function wpseo_tax_adminbar_content_score() {
  121. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', null );
  122. $rating = 0;
  123. if ( is_tax() || is_category() || is_tag() ) {
  124. $rating = WPSEO_Taxonomy_Meta::get_meta_without_term( 'content_score' );
  125. }
  126. return wpseo_adminbar_score( $rating );
  127. }
  128. /**
  129. * Takes The SEO score and makes the score icon for the adminbar with it.
  130. *
  131. * @deprecated 7.9
  132. *
  133. * @param int $score The 0-100 rating of the score. Can be either SEO score or content score.
  134. *
  135. * @return string $score_adminbar_element
  136. */
  137. function wpseo_adminbar_score( $score ) {
  138. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', null );
  139. $score = WPSEO_Utils::translate_score( $score );
  140. $score_adminbar_element = '<div class="wpseo-score-icon adminbar-seo-score ' . $score . '"><span class="adminbar-seo-score-text screen-reader-text"></span></div>';
  141. return $score_adminbar_element;
  142. }
  143. /**
  144. * Enqueue CSS to format the Yoast SEO adminbar item.
  145. *
  146. * @deprecated 7.9 Use WPSEO_Admin_Bar_Menu::enqueue_assets() instead
  147. */
  148. function wpseo_admin_bar_style() {
  149. _deprecated_function( __FUNCTION__, 'WPSEO 7.9', 'WPSEO_Admin_Bar_Menu::enqueue_assets()' );
  150. if ( ! is_admin_bar_showing() || WPSEO_Options::get( 'enable_admin_bar_menu' ) !== true ) {
  151. return;
  152. }
  153. if ( is_admin() && ! is_blog_admin() ) {
  154. return;
  155. }
  156. $admin_bar_menu = new WPSEO_Admin_Bar_Menu();
  157. $admin_bar_menu->enqueue_assets();
  158. }
  159. /**
  160. * Detects if the advanced settings are enabled.
  161. *
  162. * @deprecated 7.0
  163. */
  164. function wpseo_advanced_settings_enabled() {
  165. _deprecated_function( __FUNCTION__, 'WPSEO 7.0', null );
  166. }