PageRenderTime 44ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/public_html/wp-content/plugins/wordpress-seo/inc/wpseo-non-ajax-functions.php

https://gitlab.com/hop23typhu/list-theme
PHP | 637 lines | 400 code | 75 blank | 162 comment | 95 complexity | a1b6b05daba6cbf7dd9efe67baa73b5d MD5 | raw file
  1. <?php
  2. /**
  3. * @package WPSEO\Internals
  4. */
  5. if ( ! defined( 'WPSEO_VERSION' ) ) {
  6. header( 'Status: 403 Forbidden' );
  7. header( 'HTTP/1.1 403 Forbidden' );
  8. exit();
  9. }
  10. /**
  11. * Test whether force rewrite should be enabled or not.
  12. */
  13. function wpseo_title_test() {
  14. $options = get_option( 'wpseo_titles' );
  15. $options['forcerewritetitle'] = false;
  16. $options['title_test'] = 1;
  17. update_option( 'wpseo_titles', $options );
  18. // Setting title_test to > 0 forces the plugin to output the title below through a filter in class-frontend.php
  19. $expected_title = 'This is a Yoast Test Title';
  20. WPSEO_Utils::clear_cache();
  21. $args = array(
  22. 'user-agent' => sprintf( 'WordPress/%1$s; %2$s - Yoast', $GLOBALS['wp_version'], get_site_url() ),
  23. );
  24. $resp = wp_remote_get( get_bloginfo( 'url' ), $args );
  25. // echo '<pre>'.$resp['body'].'</pre>';
  26. if ( ( $resp && ! is_wp_error( $resp ) ) && ( 200 == $resp['response']['code'] && isset( $resp['body'] ) ) ) {
  27. $res = preg_match( '`<title>([^<]+)</title>`im', $resp['body'], $matches );
  28. if ( $res && strcmp( $matches[1], $expected_title ) !== 0 ) {
  29. $options['forcerewritetitle'] = true;
  30. $resp = wp_remote_get( get_bloginfo( 'url' ), $args );
  31. $res = false;
  32. if ( ( $resp && ! is_wp_error( $resp ) ) && ( 200 == $resp['response']['code'] && isset( $resp['body'] ) ) ) {
  33. $res = preg_match( '`/<title>([^>]+)</title>`im', $resp['body'], $matches );
  34. }
  35. }
  36. if ( ! $res || $matches[1] != $expected_title ) {
  37. $options['forcerewritetitle'] = false;
  38. }
  39. }
  40. else {
  41. // If that dies, let's make sure the titles are correct and force the output.
  42. $options['forcerewritetitle'] = true;
  43. }
  44. $options['title_test'] = 0;
  45. update_option( 'wpseo_titles', $options );
  46. }
  47. // add_filter( 'switch_theme', 'wpseo_title_test', 0 );
  48. /**
  49. * Test whether the active theme contains a <meta> description tag.
  50. *
  51. * @since 1.4.14 Moved from dashboard.php and adjusted - see changelog
  52. *
  53. * @return void
  54. */
  55. function wpseo_description_test() {
  56. $options = get_option( 'wpseo' );
  57. // Reset any related options - dirty way of getting the default to make sure it works on activation
  58. $options['theme_has_description'] = WPSEO_Option_Wpseo::$desc_defaults['theme_has_description'];
  59. $options['theme_description_found'] = WPSEO_Option_Wpseo::$desc_defaults['theme_description_found'];
  60. /* @internal Should this be reset too ? Best to do so as test is done on re-activate and switch_theme
  61. * as well and new warning would be warranted then. Only might give irritation on theme upgrade. */
  62. $options['ignore_meta_description_warning'] = WPSEO_Option_Wpseo::$desc_defaults['ignore_meta_description_warning'];
  63. $file = false;
  64. if ( file_exists( get_stylesheet_directory() . '/header.php' ) ) {
  65. // theme or child theme
  66. $file = get_stylesheet_directory() . '/header.php';
  67. }
  68. elseif ( file_exists( get_template_directory() . '/header.php' ) ) {
  69. // parent theme in case of a child theme
  70. $file = get_template_directory() . '/header.php';
  71. }
  72. if ( is_string( $file ) && $file !== '' ) {
  73. $header_file = file_get_contents( $file );
  74. $issue = preg_match_all( '#<\s*meta\s*(name|content)\s*=\s*("|\')(.*)("|\')\s*(name|content)\s*=\s*("|\')(.*)("|\')(\s+)?/?>#i', $header_file, $matches, PREG_SET_ORDER );
  75. if ( $issue === false || $issue === 0 ) {
  76. $options['theme_has_description'] = false;
  77. }
  78. else {
  79. foreach ( $matches as $meta ) {
  80. if ( ( strtolower( $meta[1] ) == 'name' && strtolower( $meta[3] ) == 'description' ) || ( strtolower( $meta[5] ) == 'name' && strtolower( $meta[7] ) == 'description' ) ) {
  81. $options['theme_description_found'] = $meta[0];
  82. $options['ignore_meta_description_warning'] = false;
  83. break; // no need to run through the rest of the meta's
  84. }
  85. }
  86. if ( $options['theme_description_found'] !== '' ) {
  87. $options['theme_has_description'] = true;
  88. }
  89. else {
  90. $options['theme_has_description'] = false;
  91. }
  92. }
  93. }
  94. update_option( 'wpseo', $options );
  95. }
  96. add_filter( 'after_switch_theme', 'wpseo_description_test', 0 );
  97. if ( version_compare( $GLOBALS['wp_version'], '3.6.99', '>' ) ) {
  98. // Use the new and *sigh* adjusted action hook WP 3.7+
  99. add_action( 'upgrader_process_complete', 'wpseo_upgrader_process_complete', 10, 2 );
  100. }
  101. elseif ( version_compare( $GLOBALS['wp_version'], '3.5.99', '>' ) ) {
  102. // Use the new action hook WP 3.6+
  103. add_action( 'upgrader_process_complete', 'wpseo_upgrader_process_complete', 10, 3 );
  104. }
  105. else {
  106. // Abuse filters to do our action
  107. add_filter( 'update_theme_complete_actions', 'wpseo_update_theme_complete_actions', 10, 2 );
  108. add_filter( 'update_bulk_theme_complete_actions', 'wpseo_update_theme_complete_actions', 10, 2 );
  109. }
  110. /**
  111. * Check if the current theme was updated and if so, test the updated theme
  112. * for the title and meta description tag
  113. *
  114. * @since 1.4.14
  115. *
  116. * @param object $upgrader_object
  117. * @param array $context_array
  118. * @param mixed $themes
  119. *
  120. * @return void
  121. */
  122. function wpseo_upgrader_process_complete( $upgrader_object, $context_array, $themes = null ) {
  123. $options = get_option( 'wpseo' );
  124. // Break if admin_notice already in place
  125. if ( ( ( isset( $options['theme_has_description'] ) && $options['theme_has_description'] === true ) || $options['theme_description_found'] !== '' ) && $options['ignore_meta_description_warning'] !== true ) {
  126. return;
  127. }
  128. // Break if this is not a theme update, not interested in installs as after_switch_theme would still be called
  129. if ( ! isset( $context_array['type'] ) || $context_array['type'] !== 'theme' || ! isset( $context_array['action'] ) || $context_array['action'] !== 'update' ) {
  130. return;
  131. }
  132. $theme = get_stylesheet();
  133. if ( ! isset( $themes ) ) {
  134. // WP 3.7+
  135. $themes = array();
  136. if ( isset( $context_array['themes'] ) && $context_array['themes'] !== array() ) {
  137. $themes = $context_array['themes'];
  138. }
  139. elseif ( isset( $context_array['theme'] ) && $context_array['theme'] !== '' ) {
  140. $themes = $context_array['theme'];
  141. }
  142. }
  143. if ( ( isset( $context_array['bulk'] ) && $context_array['bulk'] === true ) && ( is_array( $themes ) && count( $themes ) > 0 ) ) {
  144. if ( in_array( $theme, $themes ) ) {
  145. // wpseo_title_test();
  146. wpseo_description_test();
  147. }
  148. }
  149. elseif ( is_string( $themes ) && $themes === $theme ) {
  150. // wpseo_title_test();
  151. wpseo_description_test();
  152. }
  153. return;
  154. }
  155. /**
  156. * Abuse a filter to check if the current theme was updated and if so, test the updated theme
  157. * for the title and meta description tag
  158. *
  159. * @since 1.4.14
  160. *
  161. * @param array $update_actions
  162. * @param mixed $updated_theme
  163. *
  164. * @return array $update_actions Unchanged array
  165. */
  166. function wpseo_update_theme_complete_actions( $update_actions, $updated_theme ) {
  167. $options = get_option( 'wpseo' );
  168. // Break if admin_notice already in place
  169. if ( ( ( isset( $options['theme_has_description'] ) && $options['theme_has_description'] === true ) || $options['theme_description_found'] !== '' ) && $options['ignore_meta_description_warning'] !== true ) {
  170. return $update_actions;
  171. }
  172. $theme = get_stylesheet();
  173. if ( is_object( $updated_theme ) ) {
  174. /* Bulk update and $updated_theme only contains info on which theme was last in the list
  175. of updated themes, so go & test */
  176. // wpseo_title_test();
  177. wpseo_description_test();
  178. }
  179. elseif ( $updated_theme === $theme ) {
  180. /* Single theme update for the active theme */
  181. // wpseo_title_test();
  182. wpseo_description_test();
  183. }
  184. return $update_actions;
  185. }
  186. /**
  187. * Adds an SEO admin bar menu with several options. If the current user is an admin he can also go straight to several settings menu's from here.
  188. */
  189. function wpseo_admin_bar_menu() {
  190. // If the current user can't write posts, this is all of no use, so let's not output an admin menu
  191. if ( ! current_user_can( 'edit_posts' ) ) {
  192. return;
  193. }
  194. global $wp_admin_bar, $post;
  195. $focuskw = '';
  196. $score = '';
  197. $seo_url = get_admin_url( null, 'admin.php?page=wpseo_dashboard' );
  198. if ( ( is_singular() || ( is_admin() && in_array( $GLOBALS['pagenow'], array(
  199. 'post.php',
  200. 'post-new.php',
  201. ), true ) ) ) && isset( $post ) && is_object( $post ) && apply_filters( 'wpseo_use_page_analysis', true ) === true
  202. ) {
  203. $focuskw = WPSEO_Meta::get_value( 'focuskw', $post->ID );
  204. $perc_score = WPSEO_Meta::get_value( 'linkdex', $post->ID );
  205. $calc_score = WPSEO_Utils::calc( $perc_score, '/', 10, true );
  206. $txtscore = WPSEO_Utils::translate_score( $calc_score );
  207. $title = WPSEO_Utils::translate_score( $calc_score, false );
  208. $score = '<div title="' . esc_attr( $title ) . '" class="' . esc_attr( 'wpseo-score-icon ' . $txtscore . ' ' . $perc_score ) . '"></div>';
  209. $seo_url = get_edit_post_link( $post->ID );
  210. if ( $txtscore !== 'na' ) {
  211. $seo_url .= '#wpseo_linkdex';
  212. }
  213. }
  214. $wp_admin_bar->add_menu( array(
  215. 'id' => 'wpseo-menu',
  216. 'title' => __( 'SEO', 'wordpress-seo' ) . $score,
  217. 'href' => $seo_url,
  218. ) );
  219. $wp_admin_bar->add_menu( array(
  220. 'parent' => 'wpseo-menu',
  221. 'id' => 'wpseo-kwresearch',
  222. 'title' => __( 'Keyword Research', 'wordpress-seo' ),
  223. '#',
  224. ) );
  225. $wp_admin_bar->add_menu( array(
  226. 'parent' => 'wpseo-kwresearch',
  227. 'id' => 'wpseo-adwordsexternal',
  228. 'title' => __( 'AdWords External', 'wordpress-seo' ),
  229. 'href' => 'http://adwords.google.com/keywordplanner',
  230. 'meta' => array( 'target' => '_blank' ),
  231. ) );
  232. $wp_admin_bar->add_menu( array(
  233. 'parent' => 'wpseo-kwresearch',
  234. 'id' => 'wpseo-googleinsights',
  235. 'title' => __( 'Google Insights', 'wordpress-seo' ),
  236. 'href' => 'http://www.google.com/insights/search/#q=' . urlencode( $focuskw ) . '&cmpt=q',
  237. 'meta' => array( 'target' => '_blank' ),
  238. ) );
  239. $wp_admin_bar->add_menu( array(
  240. 'parent' => 'wpseo-kwresearch',
  241. 'id' => 'wpseo-wordtracker',
  242. 'title' => __( 'SEO Book', 'wordpress-seo' ),
  243. 'href' => 'http://tools.seobook.com/keyword-tools/seobook/?keyword=' . urlencode( $focuskw ),
  244. 'meta' => array( 'target' => '_blank' ),
  245. ) );
  246. if ( ! is_admin() ) {
  247. $url = WPSEO_Frontend::get_instance()->canonical( false );
  248. if ( is_string( $url ) ) {
  249. $wp_admin_bar->add_menu( array(
  250. 'parent' => 'wpseo-menu',
  251. 'id' => 'wpseo-analysis',
  252. 'title' => __( 'Analyze this page', 'wordpress-seo' ),
  253. '#',
  254. ) );
  255. $wp_admin_bar->add_menu( array(
  256. 'parent' => 'wpseo-analysis',
  257. 'id' => 'wpseo-inlinks-ose',
  258. 'title' => __( 'Check Inlinks (OSE)', 'wordpress-seo' ),
  259. 'href' => '//moz.com/researchtools/ose/links?site=' . urlencode( $url ),
  260. 'meta' => array( 'target' => '_blank' ),
  261. ) );
  262. $wp_admin_bar->add_menu( array(
  263. 'parent' => 'wpseo-analysis',
  264. 'id' => 'wpseo-kwdensity',
  265. 'title' => __( 'Check Keyword Density', 'wordpress-seo' ),
  266. 'href' => '//www.zippy.co.uk/keyworddensity/index.php?url=' . urlencode( $url ) . '&keyword=' . urlencode( $focuskw ),
  267. 'meta' => array( 'target' => '_blank' ),
  268. ) );
  269. $wp_admin_bar->add_menu( array(
  270. 'parent' => 'wpseo-analysis',
  271. 'id' => 'wpseo-cache',
  272. 'title' => __( 'Check Google Cache', 'wordpress-seo' ),
  273. 'href' => '//webcache.googleusercontent.com/search?strip=1&q=cache:' . urlencode( $url ),
  274. 'meta' => array( 'target' => '_blank' ),
  275. ) );
  276. $wp_admin_bar->add_menu( array(
  277. 'parent' => 'wpseo-analysis',
  278. 'id' => 'wpseo-header',
  279. 'title' => __( 'Check Headers', 'wordpress-seo' ),
  280. 'href' => '//quixapp.com/headers/?r=' . urlencode( $url ),
  281. 'meta' => array( 'target' => '_blank' ),
  282. ) );
  283. $wp_admin_bar->add_menu( array(
  284. 'parent' => 'wpseo-analysis',
  285. 'id' => 'wpseo-richsnippets',
  286. 'title' => __( 'Check Rich Snippets', 'wordpress-seo' ),
  287. 'href' => '//www.google.com/webmasters/tools/richsnippets?q=' . urlencode( $url ),
  288. 'meta' => array( 'target' => '_blank' ),
  289. ) );
  290. $wp_admin_bar->add_menu( array(
  291. 'parent' => 'wpseo-analysis',
  292. 'id' => 'wpseo-facebookdebug',
  293. 'title' => __( 'Facebook Debugger', 'wordpress-seo' ),
  294. 'href' => '//developers.facebook.com/tools/debug/og/object?q=' . urlencode( $url ),
  295. 'meta' => array( 'target' => '_blank' ),
  296. ) );
  297. $wp_admin_bar->add_menu( array(
  298. 'parent' => 'wpseo-analysis',
  299. 'id' => 'wpseo-pinterestvalidator',
  300. 'title' => __( 'Pinterest Rich Pins Validator', 'wordpress-seo' ),
  301. 'href' => '//developers.pinterest.com/rich_pins/validator/?link=' . urlencode( $url ),
  302. 'meta' => array( 'target' => '_blank' ),
  303. ) );
  304. $wp_admin_bar->add_menu( array(
  305. 'parent' => 'wpseo-analysis',
  306. 'id' => 'wpseo-htmlvalidation',
  307. 'title' => __( 'HTML Validator', 'wordpress-seo' ),
  308. 'href' => '//validator.w3.org/check?uri=' . urlencode( $url ),
  309. 'meta' => array( 'target' => '_blank' ),
  310. ) );
  311. $wp_admin_bar->add_menu( array(
  312. 'parent' => 'wpseo-analysis',
  313. 'id' => 'wpseo-cssvalidation',
  314. 'title' => __( 'CSS Validator', 'wordpress-seo' ),
  315. 'href' => '//jigsaw.w3.org/css-validator/validator?uri=' . urlencode( $url ),
  316. 'meta' => array( 'target' => '_blank' ),
  317. ) );
  318. $wp_admin_bar->add_menu( array(
  319. 'parent' => 'wpseo-analysis',
  320. 'id' => 'wpseo-pagespeed',
  321. 'title' => __( 'Google Page Speed Test', 'wordpress-seo' ),
  322. 'href' => '//developers.google.com/speed/pagespeed/insights/?url=' . urlencode( $url ),
  323. 'meta' => array( 'target' => '_blank' ),
  324. ) );
  325. $wp_admin_bar->add_menu( array(
  326. 'parent' => 'wpseo-analysis',
  327. 'id' => 'wpseo-modernie',
  328. 'title' => __( 'Modern IE Site Scan', 'wordpress-seo' ),
  329. 'href' => '//www.modern.ie/en-us/report#' . urlencode( $url ),
  330. 'meta' => array( 'target' => '_blank' ),
  331. ) );
  332. $wp_admin_bar->add_menu( array(
  333. 'parent' => 'wpseo-analysis',
  334. 'id' => 'wpseo-google-mobile-friendly',
  335. 'title' => __( 'Mobile-Friendly Test', 'wordpress-seo' ),
  336. 'href' => 'https://www.google.com/webmasters/tools/mobile-friendly/?url=' . urlencode( $url ),
  337. 'meta' => array( 'target' => '_blank' ),
  338. ) );
  339. }
  340. }
  341. $admin_menu = current_user_can( 'manage_options' );
  342. if ( ! $admin_menu && is_multisite() ) {
  343. $options = get_site_option( 'wpseo_ms' );
  344. $admin_menu = ( $options['access'] === 'superadmin' && is_super_admin() );
  345. }
  346. // @todo: add links to bulk title and bulk description edit pages
  347. if ( $admin_menu ) {
  348. $wp_admin_bar->add_menu( array(
  349. 'parent' => 'wpseo-menu',
  350. 'id' => 'wpseo-settings',
  351. 'title' => __( 'SEO Settings', 'wordpress-seo' ),
  352. ) );
  353. $wp_admin_bar->add_menu( array(
  354. 'parent' => 'wpseo-settings',
  355. 'id' => 'wpseo-general',
  356. 'title' => __( 'General', 'wordpress-seo' ),
  357. 'href' => admin_url( 'admin.php?page=wpseo_dashboard' ),
  358. ) );
  359. $wp_admin_bar->add_menu( array(
  360. 'parent' => 'wpseo-settings',
  361. 'id' => 'wpseo-titles',
  362. 'title' => __( 'Titles &amp; Metas', 'wordpress-seo' ),
  363. 'href' => admin_url( 'admin.php?page=wpseo_titles' ),
  364. ) );
  365. $wp_admin_bar->add_menu( array(
  366. 'parent' => 'wpseo-settings',
  367. 'id' => 'wpseo-social',
  368. 'title' => __( 'Social', 'wordpress-seo' ),
  369. 'href' => admin_url( 'admin.php?page=wpseo_social' ),
  370. ) );
  371. $wp_admin_bar->add_menu( array(
  372. 'parent' => 'wpseo-settings',
  373. 'id' => 'wpseo-xml',
  374. 'title' => __( 'XML Sitemaps', 'wordpress-seo' ),
  375. 'href' => admin_url( 'admin.php?page=wpseo_xml' ),
  376. ) );
  377. $wp_admin_bar->add_menu( array(
  378. 'parent' => 'wpseo-settings',
  379. 'id' => 'wpseo-wpseo_advanced',
  380. 'title' => __( 'Advanced', 'wordpress-seo' ),
  381. 'href' => admin_url( 'admin.php?page=wpseo_advanced' ),
  382. ) );
  383. $wp_admin_bar->add_menu( array(
  384. 'parent' => 'wpseo-settings',
  385. 'id' => 'wpseo-licenses',
  386. 'title' => __( 'Extensions', 'wordpress-seo' ),
  387. 'href' => admin_url( 'admin.php?page=wpseo_licenses' ),
  388. ) );
  389. }
  390. }
  391. add_action( 'admin_bar_menu', 'wpseo_admin_bar_menu', 95 );
  392. /**
  393. * Enqueue a tiny bit of CSS to show so the adminbar shows right.
  394. */
  395. function wpseo_admin_bar_css() {
  396. if ( is_admin_bar_showing() && is_singular() ) {
  397. wp_enqueue_style( 'boxes', plugins_url( 'css/adminbar' . WPSEO_CSSJS_SUFFIX . '.css', WPSEO_FILE ), array(), WPSEO_VERSION );
  398. }
  399. }
  400. add_action( 'wp_enqueue_scripts', 'wpseo_admin_bar_css' );
  401. /**
  402. * Allows editing of the meta fields through weblog editors like Marsedit.
  403. *
  404. * @param array $allcaps Capabilities that must all be true to allow action.
  405. * @param array $cap Array of capabilities to be checked, unused here.
  406. * @param array $args List of arguments for the specific cap to be checked.
  407. *
  408. * @return array $allcaps
  409. */
  410. function allow_custom_field_edits( $allcaps, $cap, $args ) {
  411. // $args[0] holds the capability
  412. // $args[2] holds the post ID
  413. // $args[3] holds the custom field
  414. // Make sure the request is to edit or add a post meta (this is usually also the second value in $cap,
  415. // but this is safer to check).
  416. if ( in_array( $args[0], array( 'edit_post_meta', 'add_post_meta' ) ) ) {
  417. // Only allow editing rights for users who have the rights to edit this post and make sure
  418. // the meta value starts with _yoast_wpseo (WPSEO_Meta::$meta_prefix).
  419. if ( ( isset( $args[2] ) && current_user_can( 'edit_post', $args[2] ) ) && ( ( isset( $args[3] ) && $args[3] !== '' ) && strpos( $args[3], WPSEO_Meta::$meta_prefix ) === 0 ) ) {
  420. $allcaps[ $args[0] ] = true;
  421. }
  422. }
  423. return $allcaps;
  424. }
  425. add_filter( 'user_has_cap', 'allow_custom_field_edits', 0, 3 );
  426. /**
  427. * Display an import message when robots-meta is active
  428. *
  429. * @since 1.5.0
  430. */
  431. function wpseo_robots_meta_message() {
  432. // check if robots meta is running
  433. if ( ( ! isset( $_GET['page'] ) || 'wpseo_import' !== $_GET['page'] ) && is_plugin_active( 'robots-meta/robots-meta.php' ) ) {
  434. add_action( 'admin_notices', 'wpseo_import_robots_meta_notice' );
  435. }
  436. }
  437. add_action( 'admin_init', 'wpseo_robots_meta_message' );
  438. /**
  439. * Handle deactivation Robots Meta
  440. *
  441. * @since 1.5.0
  442. */
  443. function wpseo_disable_robots_meta() {
  444. if ( isset( $_GET['deactivate_robots_meta'] ) && $_GET['deactivate_robots_meta'] === '1' && is_plugin_active( 'robots-meta/robots-meta.php' ) ) {
  445. // Deactivate the plugin
  446. deactivate_plugins( 'robots-meta/robots-meta.php' );
  447. // show notice that robots meta has been deactivated
  448. add_action( 'admin_notices', 'wpseo_deactivate_robots_meta_notice' );
  449. // Clean up the referrer url for later use
  450. if ( isset( $_SERVER['REQUEST_URI'] ) ) {
  451. $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'deactivate_robots_meta' ), sanitize_text_field( $_SERVER['REQUEST_URI'] ) );
  452. }
  453. }
  454. }
  455. add_action( 'admin_init', 'wpseo_disable_robots_meta' );
  456. /**
  457. * Handle deactivation & import of AIOSEO data
  458. *
  459. * @since 1.5.0
  460. */
  461. function wpseo_aioseo_message() {
  462. // check if aioseo is running
  463. if ( ( ! isset( $_GET['page'] ) || 'wpseo_import' != $_GET['page'] ) && is_plugin_active( 'all-in-one-seo-pack/all_in_one_seo_pack.php' ) ) {
  464. add_action( 'admin_notices', 'wpseo_import_aioseo_setting_notice' );
  465. }
  466. }
  467. add_action( 'admin_init', 'wpseo_aioseo_message' );
  468. /**
  469. * Handle deactivation AIOSEO
  470. *
  471. * @since 1.5.0
  472. */
  473. function wpseo_disable_aioseo() {
  474. if ( isset( $_GET['deactivate_aioseo'] ) && $_GET['deactivate_aioseo'] === '1' && is_plugin_active( 'all-in-one-seo-pack/all_in_one_seo_pack.php' ) ) {
  475. // Deactivate AIO
  476. deactivate_plugins( 'all-in-one-seo-pack/all_in_one_seo_pack.php' );
  477. // show notice that aioseo has been deactivated
  478. add_action( 'admin_notices', 'wpseo_deactivate_aioseo_notice' );
  479. // Clean up the referrer url for later use
  480. if ( isset( $_SERVER['REQUEST_URI'] ) ) {
  481. $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'deactivate_aioseo' ), sanitize_text_field( $_SERVER['REQUEST_URI'] ) );
  482. }
  483. }
  484. }
  485. add_action( 'admin_init', 'wpseo_disable_aioseo' );
  486. /**
  487. * Throw a notice to import AIOSEO.
  488. *
  489. * @since 1.4.8
  490. */
  491. function wpseo_import_aioseo_setting_notice() {
  492. $url = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'wpseo-import' ) ), admin_url( 'admin.php?page=wpseo_tools&tool=import-export&import=1&importaioseo=1#top#import-seo' ) );
  493. echo '<div class="error"><p>', sprintf( esc_html__( 'The plugin All-In-One-SEO has been detected. Do you want to %simport its settings%s?', 'wordpress-seo' ), sprintf( '<a href="%s">', esc_url( $url ) ), '</a>' ), '</p></div>';
  494. }
  495. /**
  496. * Throw a notice to inform the user AIOSEO has been deactivated
  497. *
  498. * @since 1.4.8
  499. */
  500. function wpseo_deactivate_aioseo_notice() {
  501. echo '<div class="updated"><p>', esc_html__( 'All-In-One-SEO has been deactivated', 'wordpress-seo' ), '</p></div>';
  502. }
  503. /**
  504. * Throw a notice to import Robots Meta.
  505. *
  506. * @since 1.4.8
  507. */
  508. function wpseo_import_robots_meta_notice() {
  509. $url = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'wpseo-import' ) ), admin_url( 'admin.php?page=wpseo_tools&tool=import-export&import=1&importrobotsmeta=1#top#import-other' ) );
  510. echo '<div class="error"><p>', sprintf( esc_html__( 'The plugin Robots-Meta has been detected. Do you want to %simport its settings%s.', 'wordpress-seo' ), sprintf( '<a href="%s">', esc_url( $url ) ), '</a>' ), '</p></div>';
  511. }
  512. /**
  513. * Throw a notice to inform the user Robots Meta has been deactivated
  514. *
  515. * @since 1.4.8
  516. */
  517. function wpseo_deactivate_robots_meta_notice() {
  518. echo '<div class="updated"><p>', esc_html__( 'Robots-Meta has been deactivated', 'wordpress-seo' ), '</p></div>';
  519. }
  520. /********************** DEPRECATED FUNCTIONS **********************/
  521. /**
  522. * Set the default settings.
  523. *
  524. * @deprecated 1.5.0
  525. * @deprecated use WPSEO_Options::initialize()
  526. * @see WPSEO_Options::initialize()
  527. */
  528. function wpseo_defaults() {
  529. _deprecated_function( __FUNCTION__, 'WPSEO 1.5.0', 'WPSEO_Options::initialize()' );
  530. WPSEO_Options::initialize();
  531. }
  532. /**
  533. * Translates a decimal analysis score into a textual one.
  534. *
  535. * @deprecated 1.5.6.1
  536. * @deprecated use WPSEO_Utils::translate_score()
  537. * @see WPSEO_Utils::translate_score()
  538. *
  539. * @param int $val The decimal score to translate.
  540. * @param bool $css_value Whether to return the i18n translated score or the CSS class value.
  541. *
  542. * @return string
  543. */
  544. function wpseo_translate_score( $val, $css_value = true ) {
  545. _deprecated_function( __FUNCTION__, 'WPSEO 1.5.6.1', 'WPSEO_Utils::translate_score()' );
  546. return WPSEO_Utils::translate_score();
  547. }
  548. /**
  549. * Check whether file editing is allowed for the .htaccess and robots.txt files
  550. *
  551. * @deprecated 1.5.6.1
  552. * @deprecated use WPSEO_Utils::allow_system_file_edit()
  553. * @see WPSEO_Utils::allow_system_file_edit()
  554. *
  555. * @internal current_user_can() checks internally whether a user is on wp-ms and adjusts accordingly.
  556. *
  557. * @return bool
  558. */
  559. function wpseo_allow_system_file_edit() {
  560. _deprecated_function( __FUNCTION__, 'WPSEO 1.5.6.1', 'WPSEO_Utils::allow_system_file_edit()' );
  561. return WPSEO_Utils::allow_system_file_edit();
  562. }