WPSEO_Import_External

Class WPSEO_Import_External.

Defined (1)

The class is defined in the following location(s).

/admin/class-import-external.php  
  1. class WPSEO_Import_External { 
  2.  
  3. /** 
  4. * Whether or not to delete old data 
  5. * @var boolean 
  6. */ 
  7. protected $replace; 
  8.  
  9. /** 
  10. * Message about the import 
  11. * @var string 
  12. */ 
  13. public $msg = ''; 
  14.  
  15. /** 
  16. * Import class constructor. 
  17. * @param boolean $replace Boolean replace switch. 
  18. */ 
  19. public function __construct( $replace = false ) { 
  20. $this->replace = $replace; 
  21.  
  22. WPSEO_Options::initialize(); 
  23.  
  24. /** 
  25. * Convenience function to set import message 
  26. * @param string $msg Message string. 
  27. */ 
  28. protected function set_msg( $msg ) { 
  29. if ( ! empty( $this->msg ) ) { 
  30. $this->msg .= PHP_EOL; 
  31. $this->msg .= $msg; 
  32.  
  33. /** 
  34. * Deletes an option depending on the class replace state 
  35. * @param string $option Option key. 
  36. */ 
  37. protected function perhaps_delete( $option ) { 
  38. if ( $this->replace ) { 
  39. delete_option( $option ); 
  40.  
  41. /** 
  42. * Import HeadSpace SEO settings 
  43. */ 
  44. public function import_headspace() { 
  45. global $wpdb; 
  46.  
  47. WPSEO_Meta::replace_meta( '_headspace_description', WPSEO_Meta::$meta_prefix . 'metadesc', $this->replace ); 
  48. WPSEO_Meta::replace_meta( '_headspace_keywords', WPSEO_Meta::$meta_prefix . 'metakeywords', $this->replace ); 
  49. WPSEO_Meta::replace_meta( '_headspace_page_title', WPSEO_Meta::$meta_prefix . 'title', $this->replace ); 
  50.  
  51. /** 
  52. * @todo [JRF => whomever] verify how headspace sets these metas ( 'noindex', 'nofollow', 'noarchive', 'noodp', 'noydir' ) 
  53. * and if the values saved are concurrent with the ones we use (i.e. 0/1/2) 
  54. */ 
  55. WPSEO_Meta::replace_meta( '_headspace_noindex', WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', $this->replace ); 
  56. WPSEO_Meta::replace_meta( '_headspace_nofollow', WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', $this->replace ); 
  57.  
  58. /** 
  59. * @todo - [JRF => whomever] check if this can be done more efficiently by querying only the meta table 
  60. * possibly directly changing it using concat on the existing values 
  61. */ 
  62. $posts = $wpdb->get_results( "SELECT ID FROM $wpdb->posts" ); 
  63. if ( is_array( $posts ) && $posts !== array() ) { 
  64. foreach ( $posts as $post ) { 
  65. $custom = get_post_custom( $post->ID ); 
  66. $robotsmeta_adv = ''; 
  67. if ( isset( $custom['_headspace_noarchive'] ) ) { 
  68. $robotsmeta_adv .= 'noarchive, '; 
  69. if ( isset( $custom['_headspace_noodp'] ) ) { 
  70. $robotsmeta_adv .= 'noodp, '; 
  71. $robotsmeta_adv = preg_replace( '`, $`', '', $robotsmeta_adv ); 
  72. WPSEO_Meta::set_value( 'meta-robots-adv', $robotsmeta_adv, $post->ID ); 
  73.  
  74. if ( $this->replace ) { 
  75. // We no longer use noydir, but we remove the meta key as it's unneeded. 
  76. $hs_meta = array( 'noarchive', 'noodp', 'noydir' ); 
  77. foreach ( $hs_meta as $meta ) { 
  78. delete_post_meta_by_key( '_headspace_' . $meta ); 
  79. unset( $hs_meta, $meta ); 
  80. $this->set_msg( __( 'HeadSpace2 data successfully imported', 'wordpress-seo' ) );