| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | * @package Polylang |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | - * A class to manage copy and synchronization of post metas | |
| 7 | + * A class to manage copy and synchronization of post metas. | |
| 8 | 8 | * |
| 9 | 9 | * @since 2.3 |
| 10 | 10 | */ |
| 11 | 11 | class PLL_Sync_Post_Metas extends PLL_Sync_Metas { |
| @@ -16,13 +16,13 @@ | ||
| 16 | 16 | */ |
| 17 | 17 | public $options; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * Constructor | |
| 20 | + * Constructor. | |
| 21 | 21 | * |
| 22 | 22 | * @since 2.3 |
| 23 | 23 | * |
| 24 | - * @param object $polylang | |
| 24 | + * @param object $polylang The Polylang object. | |
| 25 | 25 | */ |
| 26 | 26 | public function __construct( &$polylang ) { |
| 27 | 27 | $this->meta_type = 'post'; |
| 28 | 28 | |
| @@ -37,22 +37,24 @@ | ||
| 37 | 37 | * Get the custom fields to copy or synchronize. |
| 38 | 38 | * |
| 39 | 39 | * @since 2.3 |
| 40 | 40 | * |
| 41 | - * @param int $from Id of the post from which we copy informations. | |
| 42 | - * @param int $to Id of the post to which we paste informations. | |
| 41 | + * @param int $from Id of the post from which we copy information. | |
| 42 | + * @param int $to Id of the post to which we paste information. | |
| 43 | 43 | * @param string $lang Language slug. |
| 44 | 44 | * @param bool $sync True if it is synchronization, false if it is a copy. |
| 45 | 45 | * @return string[] List of meta keys. |
| 46 | 46 | */ |
| 47 | 47 | protected function get_metas_to_copy( $from, $to, $lang, $sync = false ) { |
| 48 | - // Copy or synchronize post metas and allow plugins to do the same | |
| 49 | - $metas = get_post_custom( $from ); | |
| 50 | 48 | $keys = array(); |
| 51 | 49 | |
| 52 | - // Get public meta keys ( including from translated post in case we just deleted a custom field ) | |
| 50 | + // Get public meta keys ( including from translated post in case we just deleted a custom field ). | |
| 53 | 51 | if ( ! $sync || in_array( 'post_meta', $this->options['sync'] ) ) { |
| 54 | - foreach ( $keys = array_unique( array_merge( array_keys( $metas ), array_keys( get_post_custom( $to ) ) ) ) as $k => $meta_key ) { | |
| 52 | + $from_keys = (array) get_post_custom_keys( $from ); | |
| 53 | + $to_keys = (array) get_post_custom_keys( $to ); | |
| 54 | + | |
| 55 | + $keys = array_unique( array_merge( $from_keys, $to_keys ) ); | |
| 56 | + foreach ( $keys as $k => $meta_key ) { | |
| 55 | 57 | if ( is_protected_meta( $meta_key ) ) { |
| 56 | 58 | unset( $keys[ $k ] ); |
| 57 | 59 | } |
| 58 | 60 | } |
| @@ -57,9 +59,9 @@ | ||
| 57 | 59 | } |
| 58 | 60 | } |
| 59 | 61 | } |
| 60 | 62 | |
| 61 | - // Add page template and featured image | |
| 63 | + // Add page template and featured image. | |
| 62 | 64 | foreach ( array( '_wp_page_template', '_thumbnail_id' ) as $meta ) { |
| 63 | 65 | if ( ! $sync || in_array( $meta, $this->options['sync'] ) ) { |
| 64 | 66 | $keys[] = $meta; |
| 65 | 67 | } |
| @@ -68,9 +70,9 @@ | ||
| 68 | 70 | if ( $this->options['media_support'] ) { |
| 69 | 71 | $keys[] = '_wp_attached_file'; |
| 70 | 72 | $keys[] = '_wp_attachment_metadata'; |
| 71 | 73 | $keys[] = '_wp_attachment_backup_sizes'; |
| 72 | - $keys[] = '_wp_attachment_is_custom_header'; // Random header image | |
| 74 | + $keys[] = '_wp_attachment_is_custom_header'; // Random header image. | |
| 73 | 75 | } |
| 74 | 76 | |
| 75 | 77 | /** This filter is documented in modules/sync/sync-metas.php */ |
| 76 | 78 | return array_unique( apply_filters( 'pll_copy_post_metas', $keys, $sync, $from, $to, $lang ) ); |
| @@ -76,15 +78,15 @@ | ||
| 76 | 78 | return array_unique( apply_filters( 'pll_copy_post_metas', $keys, $sync, $from, $to, $lang ) ); |
| 77 | 79 | } |
| 78 | 80 | |
| 79 | 81 | /** |
| 80 | - * Translates the thumbnail id | |
| 82 | + * Translates the thumbnail id. | |
| 81 | 83 | * |
| 82 | 84 | * @since 2.3 |
| 83 | 85 | * |
| 84 | - * @param int $value Thumbnail id | |
| 85 | - * @param string $key Meta key | |
| 86 | - * @param string $lang Language code | |
| 86 | + * @param int $value Thumbnail id. | |
| 87 | + * @param string $key Meta key. | |
| 88 | + * @param string $lang Language code. | |
| 87 | 89 | * @return int |
| 88 | 90 | */ |
| 89 | 91 | public function translate_thumbnail_id( $value, $key, $lang ) { |
| 90 | 92 | return ( $this->options['media_support'] && '_thumbnail_id' === $key && $to_value = $this->model->post->get_translation( $value, $lang ) ) ? $to_value : $value; |