/wp-content/plugins/wordpress-seo/admin/import/plugins/class-import-aioseo.php

https://bitbucket.org/carloskikea/helpet · PHP · 107 lines · 54 code · 10 blank · 43 comment · 2 complexity · 7047853a22bd5d9cc0f10507b53ec9aa MD5 · raw file

  1. <?php
  2. /**
  3. * File with the class to handle data from All in One SEO Pack.
  4. *
  5. * @package WPSEO\Admin\Import\Plugins
  6. */
  7. /**
  8. * Class with functionality to import & clean All in One SEO Pack post metadata.
  9. */
  10. class WPSEO_Import_AIOSEO extends WPSEO_Plugin_Importer {
  11. /**
  12. * The plugin name.
  13. *
  14. * @var string
  15. */
  16. protected $plugin_name = 'All In One SEO Pack';
  17. /**
  18. * Meta key, used in SQL LIKE clause for delete query.
  19. *
  20. * @var string
  21. */
  22. protected $meta_key = '_aioseop_%';
  23. /**
  24. * OpenGraph keys to import.
  25. *
  26. * @var array
  27. */
  28. protected $import_keys = array(
  29. 'aioseop_opengraph_settings_title' => 'opengraph-title',
  30. 'aioseop_opengraph_settings_desc' => 'opengraph-description',
  31. 'aioseop_opengraph_settings_customimg' => 'opengraph-image',
  32. 'aioseop_opengraph_settings_customimg_twitter' => 'twitter-image',
  33. );
  34. /**
  35. * Array of meta keys to detect and import.
  36. *
  37. * @var array
  38. */
  39. protected $clone_keys = array(
  40. array(
  41. 'old_key' => '_aioseop_title',
  42. 'new_key' => 'title',
  43. ),
  44. array(
  45. 'old_key' => '_aioseop_description',
  46. 'new_key' => 'metadesc',
  47. ),
  48. array(
  49. 'old_key' => '_aioseop_noindex',
  50. 'new_key' => 'meta-robots-noindex',
  51. 'convert' => array( 'on' => 1 ),
  52. ),
  53. array(
  54. 'old_key' => '_aioseop_nofollow',
  55. 'new_key' => 'meta-robots-nofollow',
  56. 'convert' => array( 'on' => 1 ),
  57. ),
  58. );
  59. /**
  60. * Import All In One SEO meta values.
  61. *
  62. * @return bool Import success status.
  63. */
  64. protected function import() {
  65. $status = parent::import();
  66. if ( $status ) {
  67. $this->import_opengraph();
  68. }
  69. return $status;
  70. }
  71. /**
  72. * Imports the OpenGraph and Twitter settings for all posts.
  73. *
  74. * @return bool
  75. */
  76. protected function import_opengraph() {
  77. $query_posts = new WP_Query( 'post_type=any&meta_key=_aioseop_opengraph_settings&order=ASC&fields=ids&nopaging=true' );
  78. if ( ! empty( $query_posts->posts ) ) {
  79. foreach ( array_values( $query_posts->posts ) as $post_id ) {
  80. $this->import_post_opengraph( $post_id );
  81. }
  82. }
  83. return true;
  84. }
  85. /**
  86. * Imports the OpenGraph and Twitter settings for a single post.
  87. *
  88. * @param int $post_id Post ID.
  89. */
  90. private function import_post_opengraph( $post_id ) {
  91. $meta = get_post_meta( $post_id, '_aioseop_opengraph_settings', true );
  92. $meta = maybe_unserialize( $meta );
  93. foreach ( $this->import_keys as $old_key => $new_key ) {
  94. $this->maybe_save_post_meta( $new_key, $meta[ $old_key ], $post_id );
  95. }
  96. }
  97. }