PageRenderTime 15ms CodeModel.GetById 6ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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