PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/wp-content/plugins/wordpress-seo/wp-seo-main.php

https://github.com/Fishgate/privatecollectionswp
PHP | 429 lines | 252 code | 79 blank | 98 comment | 56 complexity | 71e1261ac21c026daf2411c6d09587e4 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Main
  4. */
  5. if ( ! function_exists( 'add_filter' ) ) {
  6. header( 'Status: 403 Forbidden' );
  7. header( 'HTTP/1.1 403 Forbidden' );
  8. exit();
  9. }
  10. /**
  11. * @internal Nobody should be able to overrule the real version number as this can cause serious issues
  12. * with the options, so no if ( ! defined() )
  13. */
  14. define( 'WPSEO_VERSION', '1.5.6' );
  15. if ( ! defined( 'WPSEO_PATH' ) ) {
  16. define( 'WPSEO_PATH', plugin_dir_path( WPSEO_FILE ) );
  17. }
  18. if ( ! defined( 'WPSEO_BASENAME' ) ) {
  19. define( 'WPSEO_BASENAME', plugin_basename( WPSEO_FILE ) );
  20. }
  21. if ( ! defined( 'WPSEO_CSSJS_SUFFIX' ) ) {
  22. define( 'WPSEO_CSSJS_SUFFIX', ( ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) ? '' : '.min' ) );
  23. }
  24. /* ***************************** CLASS AUTOLOADING *************************** */
  25. /**
  26. * Auto load our class files
  27. *
  28. * @param string $class Class name
  29. * @return void
  30. */
  31. function wpseo_auto_load( $class ) {
  32. static $classes = null;
  33. if ( $classes === null ) {
  34. $classes = array(
  35. 'wpseo_admin' => WPSEO_PATH . 'admin/class-admin.php',
  36. 'wpseo_bulk_title_editor_list_table' => WPSEO_PATH . 'admin/class-bulk-title-editor-list-table.php',
  37. 'wpseo_bulk_description_list_table' => WPSEO_PATH . 'admin/class-bulk-description-editor-list-table.php',
  38. 'wpseo_bulk_list_table' => WPSEO_PATH . 'admin/class-bulk-editor-list-table.php',
  39. 'wpseo_admin_pages' => WPSEO_PATH . 'admin/class-config.php',
  40. 'wpseo_metabox' => WPSEO_PATH . 'admin/class-metabox.php',
  41. 'wpseo_social_admin' => WPSEO_PATH . 'admin/class-opengraph-admin.php',
  42. 'wpseo_pointers' => WPSEO_PATH . 'admin/class-pointers.php',
  43. 'wpseo_sitemaps_admin' => WPSEO_PATH . 'admin/class-sitemaps-admin.php',
  44. 'wpseo_taxonomy' => WPSEO_PATH . 'admin/class-taxonomy.php',
  45. 'yoast_tracking' => WPSEO_PATH . 'admin/class-tracking.php',
  46. 'yoast_textstatistics' => WPSEO_PATH . 'admin/TextStatistics.php',
  47. 'wpseo_breadcrumbs' => WPSEO_PATH . 'frontend/class-breadcrumbs.php',
  48. 'wpseo_frontend' => WPSEO_PATH . 'frontend/class-frontend.php',
  49. 'wpseo_opengraph' => WPSEO_PATH . 'frontend/class-opengraph.php',
  50. 'wpseo_twitter' => WPSEO_PATH . 'frontend/class-twitter.php',
  51. 'wpseo_googleplus' => WPSEO_PATH . 'frontend/class-googleplus.php',
  52. 'wpseo_rewrite' => WPSEO_PATH . 'inc/class-rewrite.php',
  53. 'wpseo_sitemaps' => WPSEO_PATH . 'inc/class-sitemaps.php',
  54. 'sitemap_walker' => WPSEO_PATH . 'inc/class-sitemap-walker.php',
  55. 'wpseo_options' => WPSEO_PATH . 'inc/class-wpseo-options.php',
  56. 'wpseo_option' => WPSEO_PATH . 'inc/class-wpseo-options.php',
  57. 'wpseo_option_wpseo' => WPSEO_PATH . 'inc/class-wpseo-options.php',
  58. 'wpseo_option_permalinks' => WPSEO_PATH . 'inc/class-wpseo-options.php',
  59. 'wpseo_option_titles' => WPSEO_PATH . 'inc/class-wpseo-options.php',
  60. 'wpseo_option_social' => WPSEO_PATH . 'inc/class-wpseo-options.php',
  61. 'wpseo_option_rss' => WPSEO_PATH . 'inc/class-wpseo-options.php',
  62. 'wpseo_option_internallinks' => WPSEO_PATH . 'inc/class-wpseo-options.php',
  63. 'wpseo_option_xml' => WPSEO_PATH . 'inc/class-wpseo-options.php',
  64. 'wpseo_option_ms' => WPSEO_PATH . 'inc/class-wpseo-options.php',
  65. 'wpseo_taxonomy_meta' => WPSEO_PATH . 'inc/class-wpseo-options.php',
  66. 'wpseo_meta' => WPSEO_PATH . 'inc/class-wpseo-meta.php',
  67. 'wpseo_replace_vars' => WPSEO_PATH . 'inc/class-wpseo-replace-vars.php',
  68. 'yoast_license_manager' => WPSEO_PATH . 'admin/license-manager/class-license-manager.php',
  69. 'yoast_plugin_license_manager' => WPSEO_PATH . 'admin/license-manager/class-plugin-license-manager.php',
  70. 'yoast_product' => WPSEO_PATH . 'admin/license-manager/class-product.php',
  71. 'yoast_notification_center' => WPSEO_PATH . 'admin/class-yoast-notification-center.php',
  72. 'yoast_notification' => WPSEO_PATH . 'admin/class-yoast-notification.php',
  73. 'wp_list_table' => ABSPATH . 'wp-admin/includes/class-wp-list-table.php',
  74. 'walker_category' => ABSPATH . 'wp-includes/category-template.php',
  75. 'pclzip' => ABSPATH . 'wp-admin/includes/class-pclzip.php',
  76. );
  77. }
  78. $cn = strtolower( $class );
  79. if ( isset( $classes[ $cn ] ) ) {
  80. require_once( $classes[ $cn ] );
  81. }
  82. }
  83. if ( function_exists( 'spl_autoload_register' ) ) {
  84. spl_autoload_register( 'wpseo_auto_load' );
  85. }
  86. /* ***************************** PLUGIN (DE-)ACTIVATION *************************** */
  87. /**
  88. * Run single site / network-wide activation of the plugin.
  89. *
  90. * @param bool $networkwide Whether the plugin is being activated network-wide
  91. */
  92. function wpseo_activate( $networkwide = false ) {
  93. if ( ! is_multisite() || ! $networkwide ) {
  94. _wpseo_activate();
  95. }
  96. else {
  97. /* Multi-site network activation - activate the plugin for all blogs */
  98. wpseo_network_activate_deactivate( true );
  99. }
  100. }
  101. /**
  102. * Run single site / network-wide de-activation of the plugin.
  103. *
  104. * @param bool $networkwide Whether the plugin is being de-activated network-wide
  105. */
  106. function wpseo_deactivate( $networkwide = false ) {
  107. if ( ! is_multisite() || ! $networkwide ) {
  108. _wpseo_deactivate();
  109. }
  110. else {
  111. /* Multi-site network activation - de-activate the plugin for all blogs */
  112. wpseo_network_activate_deactivate( false );
  113. }
  114. }
  115. /**
  116. * Run network-wide (de-)activation of the plugin
  117. *
  118. * @param bool $activate True for plugin activation, false for de-activation
  119. */
  120. function wpseo_network_activate_deactivate( $activate = true ) {
  121. global $wpdb;
  122. $original_blog_id = get_current_blog_id(); // alternatively use: $wpdb->blogid
  123. $all_blogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
  124. if ( is_array( $all_blogs ) && $all_blogs !== array() ) {
  125. foreach ( $all_blogs as $blog_id ) {
  126. switch_to_blog( $blog_id );
  127. if ( $activate === true ) {
  128. _wpseo_activate();
  129. }
  130. else {
  131. _wpseo_deactivate();
  132. }
  133. }
  134. // Restore back to original blog
  135. switch_to_blog( $original_blog_id );
  136. }
  137. }
  138. /**
  139. * Runs on activation of the plugin.
  140. */
  141. function _wpseo_activate() {
  142. require_once( WPSEO_PATH . 'inc/wpseo-functions.php' );
  143. wpseo_load_textdomain(); // Make sure we have our translations available for the defaults
  144. WPSEO_Options::get_instance();
  145. if ( ! is_multisite() ) {
  146. WPSEO_Options::initialize();
  147. }
  148. else {
  149. WPSEO_Options::maybe_set_multisite_defaults( true );
  150. }
  151. WPSEO_Options::ensure_options_exist();
  152. flush_rewrite_rules();
  153. wpseo_add_capabilities();
  154. WPSEO_Options::schedule_yoast_tracking( null, get_option( 'wpseo' ) );
  155. // Clear cache so the changes are obvious.
  156. WPSEO_Options::clear_cache();
  157. do_action( 'wpseo_activate' );
  158. }
  159. /**
  160. * On deactivation, flush the rewrite rules so XML sitemaps stop working.
  161. */
  162. function _wpseo_deactivate() {
  163. require_once( WPSEO_PATH . 'inc/wpseo-functions.php' );
  164. flush_rewrite_rules();
  165. wpseo_remove_capabilities();
  166. // Force unschedule
  167. WPSEO_Options::schedule_yoast_tracking( null, get_option( 'wpseo' ), true );
  168. // Clear cache so the changes are obvious.
  169. WPSEO_Options::clear_cache();
  170. do_action( 'wpseo_deactivate' );
  171. }
  172. /**
  173. * Run wpseo activation routine on creation / activation of a multisite blog if WPSEO is activated
  174. * network-wide.
  175. *
  176. * Will only be called by multisite actions.
  177. * @internal Unfortunately will fail if the plugin is in the must-use directory
  178. * @see https://core.trac.wordpress.org/ticket/24205
  179. */
  180. function wpseo_on_activate_blog( $blog_id ) {
  181. if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
  182. require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
  183. }
  184. if ( is_plugin_active_for_network( plugin_basename( WPSEO_FILE ) ) ) {
  185. switch_to_blog( $blog_id );
  186. wpseo_activate( false );
  187. restore_current_blog();
  188. }
  189. }
  190. /* ***************************** PLUGIN LOADING *************************** */
  191. /**
  192. * Load translations
  193. */
  194. function wpseo_load_textdomain() {
  195. load_plugin_textdomain( 'wordpress-seo', false, dirname( plugin_basename( WPSEO_FILE ) ) . '/languages/' );
  196. }
  197. add_action( 'init', 'wpseo_load_textdomain', 1 );
  198. /**
  199. * On plugins_loaded: load the minimum amount of essential files for this plugin
  200. */
  201. function wpseo_init() {
  202. require_once( WPSEO_PATH . 'inc/wpseo-functions.php' );
  203. // Make sure our option and meta value validation routines and default values are always registered and available
  204. WPSEO_Options::get_instance();
  205. WPSEO_Meta::init();
  206. $option_wpseo = get_option( 'wpseo' );
  207. if ( version_compare( $option_wpseo['version'], WPSEO_VERSION, '<' ) ) {
  208. wpseo_do_upgrade( $option_wpseo['version'] );
  209. }
  210. $options = WPSEO_Options::get_all();
  211. if ( $options['stripcategorybase'] === true ) {
  212. $GLOBALS['wpseo_rewrite'] = new WPSEO_Rewrite;
  213. }
  214. if ( $options['enablexmlsitemap'] === true ) {
  215. $GLOBALS['wpseo_sitemaps'] = new WPSEO_Sitemaps;
  216. }
  217. if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
  218. require_once( WPSEO_PATH . 'inc/wpseo-non-ajax-functions.php' );
  219. }
  220. }
  221. /**
  222. * Used to load the required files on the plugins_loaded hook, instead of immediately.
  223. */
  224. function wpseo_frontend_init() {
  225. add_action( 'init', 'initialize_wpseo_front' );
  226. $options = WPSEO_Options::get_all();
  227. if ( $options['breadcrumbs-enable'] === true ) {
  228. /**
  229. * If breadcrumbs are active (which they supposedly are if the users has enabled this settings,
  230. * there's no reason to have bbPress breadcrumbs as well.
  231. *
  232. * @internal The class itself is only loaded when the template tag is encountered via
  233. * the template tag function in the wpseo-functions.php file
  234. */
  235. add_filter( 'bbp_get_breadcrumb', '__return_false' );
  236. }
  237. add_action( 'template_redirect', 'wpseo_frontend_head_init', 999 );
  238. }
  239. /**
  240. * Instantiate the different social classes on the frontend
  241. */
  242. function wpseo_frontend_head_init() {
  243. $options = WPSEO_Options::get_all();
  244. if ( $options['twitter'] === true && is_singular() ) {
  245. add_action( 'wpseo_head', array( 'WPSEO_Twitter', 'get_instance' ), 40 );
  246. }
  247. if ( $options['opengraph'] === true ) {
  248. $GLOBALS['wpseo_og'] = new WPSEO_OpenGraph;
  249. }
  250. if ( $options['googleplus'] === true && is_singular() ) {
  251. add_action( 'wpseo_head', array( 'WPSEO_GooglePlus', 'get_instance' ), 35 );
  252. }
  253. }
  254. /**
  255. * Used to load the required files on the plugins_loaded hook, instead of immediately.
  256. */
  257. function wpseo_admin_init() {
  258. global $pagenow;
  259. $GLOBALS['wpseo_admin'] = new WPSEO_Admin;
  260. $options = WPSEO_Options::get_all();
  261. if ( isset( $_GET['wpseo_restart_tour'] ) ) {
  262. $options['ignore_tour'] = false;
  263. update_option( 'wpseo', $options );
  264. }
  265. if ( $options['yoast_tracking'] === true ) {
  266. /**
  267. * @internal this is not a proper lean loading implementation (method_exist will autoload the class),
  268. * but it can't be helped as there are other plugins out there which also use versions
  269. * of the Yoast Tracking class and we need to take that into account unfortunately
  270. */
  271. if ( method_exists( 'Yoast_Tracking', 'get_instance' ) ) {
  272. add_action( 'yoast_tracking', array( 'Yoast_Tracking', 'get_instance' ) );
  273. }
  274. else {
  275. $GLOBALS['yoast_tracking'] = new Yoast_Tracking;
  276. }
  277. }
  278. /**
  279. * Filter: 'wpseo_always_register_metaboxes_on_admint' - Allow developers to change whether
  280. * the WPSEO metaboxes are only registered on the typical pages (lean loading) or always
  281. * registered when in admin.
  282. *
  283. * @api bool Whether to always register the metaboxes or not. Defaults to false.
  284. */
  285. if ( in_array( $pagenow, array( 'edit.php', 'post.php', 'post-new.php' ) ) || apply_filters( 'wpseo_always_register_metaboxes_on_admin', false ) ) {
  286. $GLOBALS['wpseo_metabox'] = new WPSEO_Metabox;
  287. if ( $options['opengraph'] === true ) {
  288. $GLOBALS['wpseo_social'] = new WPSEO_Social_Admin;
  289. }
  290. }
  291. if ( in_array( $pagenow, array( 'edit-tags.php' ) ) ) {
  292. $GLOBALS['wpseo_taxonomy'] = new WPSEO_Taxonomy;
  293. }
  294. if ( in_array( $pagenow, array( 'admin.php' ) ) ) {
  295. // @todo [JRF => whomever] Can we load this more selectively ? like only when $_GET['page'] is one of ours ?
  296. $GLOBALS['wpseo_admin_pages'] = new WPSEO_Admin_Pages;
  297. }
  298. if ( $options['tracking_popup_done'] === false || $options['ignore_tour'] === false ) {
  299. add_action( 'admin_enqueue_scripts', array( 'WPSEO_Pointers', 'get_instance' ) );
  300. }
  301. if ( $options['enablexmlsitemap'] === true ) {
  302. $GLOBALS['wpseo_sitemaps_admin'] = new WPSEO_Sitemaps_Admin;
  303. }
  304. }
  305. /* ***************************** BOOTSTRAP / HOOK INTO WP *************************** */
  306. if ( ! function_exists( 'spl_autoload_register' ) ) {
  307. add_action( 'admin_init', 'yoast_wpseo_self_deactivate', 1 );
  308. }
  309. else if ( ! defined( 'WP_INSTALLING' ) || WP_INSTALLING === false ) {
  310. add_action( 'plugins_loaded', 'wpseo_init', 14 );
  311. if ( is_admin() ) {
  312. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
  313. require_once( WPSEO_PATH . 'admin/ajax.php' );
  314. }
  315. else {
  316. add_action( 'plugins_loaded', 'wpseo_admin_init', 15 );
  317. }
  318. }
  319. else {
  320. add_action( 'plugins_loaded', 'wpseo_frontend_init', 15 );
  321. }
  322. add_action( 'admin_init', 'load_yoast_notifications' );
  323. }
  324. // Activation and deactivation hook
  325. register_activation_hook( WPSEO_FILE, 'wpseo_activate' );
  326. register_deactivation_hook( WPSEO_FILE, 'wpseo_deactivate' );
  327. add_action( 'wpmu_new_blog', 'wpseo_on_activate_blog' );
  328. add_action( 'activate_blog', 'wpseo_on_activate_blog' );
  329. function load_yoast_notifications() {
  330. // Init Yoast_Notification_Center class
  331. Yoast_Notification_Center::get();
  332. }
  333. /**
  334. * Throw an error if the PHP SPL extension is disabled (prevent white screens) and self-deactivate plugin
  335. *
  336. * @since 1.5.4
  337. *
  338. * @param string Error message
  339. * @return void
  340. */
  341. function yoast_wpseo_self_deactivate() {
  342. if ( is_admin() ) {
  343. $message = esc_html__( 'The Standard PHP Library (SPL) extension seem to be unavailable. Please ask your web host to enable it.', 'wordpress-seo' );
  344. add_action( 'admin_notices', create_function( $message, 'echo \'<div class="error"><p>\' . __( \'Activation failed:\', \'wordpress-seo\' ) . \' \' . $message . \'</p></div>\';' ) );
  345. deactivate_plugins( plugin_basename( WPSEO_FILE ) );
  346. if ( isset( $_GET['activate'] ) ) {
  347. unset( $_GET['activate'] );
  348. }
  349. }
  350. }