| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Some common code for PLL_Admin_Filters_Post and PLL_Admin_Filters_Media |
| 5 |
* |
| 6 |
* @since 1.5 |
| 7 |
*/ |
| 8 |
abstract class PLL_Admin_Filters_Post_Base { |
| 9 |
public $links, $model, $pref_lang; |
| 10 |
|
| 11 |
/** |
| 12 |
* Constructor: setups filters and actions |
| 13 |
* |
| 14 |
* @since 1.2 |
| 15 |
* |
| 16 |
* @param object $polylang |
| 17 |
*/ |
| 18 |
public function __construct( &$polylang ) { |
| 19 |
$this->links = &$polylang->links; |
| 20 |
$this->model = &$polylang->model; |
| 21 |
$this->pref_lang = &$polylang->pref_lang; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Save translations from language metabox |
| 26 |
* |
| 27 |
* @since 1.5 |
| 28 |
* |
| 29 |
* @param int $post_id |
| 30 |
* @param array $arr |
| 31 |
* @return array |
| 32 |
*/ |
| 33 |
protected function save_translations( $post_id, $arr ) { |
| 34 |
// Security check as 'wp_insert_post' can be called from outside WP admin |
| 35 |
check_admin_referer( 'pll_language', '_pll_nonce' ); |
| 36 |
|
| 37 |
// Save translations after checking the translated post is in the right language |
| 38 |
foreach ( $arr as $lang => $tr_id ) { |
| 39 |
$translations[ $lang ] = ( $tr_id && $this->model->post->get_language( (int) $tr_id )->slug == $lang ) ? (int) $tr_id : 0; |
| 40 |
} |
| 41 |
|
| 42 |
$this->model->post->save_translations( $post_id, $translations ); |
| 43 |
return $translations; |
| 44 |
} |
| 45 |
} |
| 46 |
|