2021-09-21 15:01:08 +02:00
< ? php
2021-09-21 15:06:29 +02:00
/**
* @ package Polylang
*/
2021-09-21 15:01:08 +02:00
/**
* Settings class for synchronization settings management
*
* @ since 1.8
*/
class PLL_Settings_Sync extends PLL_Settings_Module {
2021-09-21 15:06:29 +02:00
/**
* Stores the display order priority .
*
* @ var int
*/
public $priority = 50 ;
2021-09-21 15:01:08 +02:00
/**
2021-09-21 15:06:29 +02:00
* Constructor
2021-09-21 15:01:08 +02:00
*
* @ since 1.8
*
* @ param object $polylang polylang object
*/
public function __construct ( & $polylang ) {
2021-09-21 15:06:29 +02:00
parent :: __construct (
$polylang ,
array (
'module' => 'sync' ,
'title' => __ ( 'Synchronization' , 'polylang' ),
'description' => __ ( 'The synchronization options allow to maintain exact same values (or translations in the case of taxonomies and page parent) of meta content between the translations of a post or page.' , 'polylang' ),
)
);
2021-09-21 15:01:08 +02:00
}
/**
2021-09-21 15:06:29 +02:00
* Deactivates the module
2021-09-21 15:01:08 +02:00
*
* @ since 1.8
*/
public function deactivate () {
$this -> options [ 'sync' ] = array ();
update_option ( 'polylang' , $this -> options );
}
/**
2021-09-21 15:06:29 +02:00
* Displays the settings form
2021-09-21 15:01:08 +02:00
*
* @ since 1.8
*/
protected function form () {
?>
< ul class = " pll-inline-block-list " >
< ? php
foreach ( self :: list_metas_to_sync () as $key => $str ) {
printf (
'<li><label><input name="sync[%s]" type="checkbox" value="1" %s /> %s</label></li>' ,
esc_attr ( $key ),
2021-09-21 15:06:29 +02:00
checked ( in_array ( $key , $this -> options [ 'sync' ] ), true , false ),
2021-09-21 15:01:08 +02:00
esc_html ( $str )
);
}
?>
</ ul >
< ? php
}
/**
2021-09-21 15:06:29 +02:00
* Sanitizes the settings before saving
2021-09-21 15:01:08 +02:00
*
* @ since 1.8
*
* @ param array $options
*/
protected function update ( $options ) {
2021-09-21 15:06:29 +02:00
$newoptions = array ( 'sync' => empty ( $options [ 'sync' ] ) ? array () : array_keys ( $options [ 'sync' ], 1 ) );
2021-09-21 15:01:08 +02:00
return $newoptions ; // take care to return only validated options
}
/**
2021-09-21 15:06:29 +02:00
* Get the row actions .
2021-09-21 15:01:08 +02:00
*
* @ since 1.8
*
2021-09-21 15:06:29 +02:00
* @ return string [] Row actions .
2021-09-21 15:01:08 +02:00
*/
protected function get_actions () {
return empty ( $this -> options [ 'sync' ] ) ? array ( 'configure' ) : array ( 'configure' , 'deactivate' );
}
/**
2021-09-21 15:06:29 +02:00
* Get the list of synchronization settings .
2021-09-21 15:01:08 +02:00
*
* @ since 1.0
*
2021-09-21 15:06:29 +02:00
* @ return string [] Array synchronization options .
2021-09-21 15:01:08 +02:00
*/
2021-09-21 15:06:29 +02:00
public static function list_metas_to_sync () {
2021-09-21 15:01:08 +02:00
return array (
'taxonomies' => __ ( 'Taxonomies' , 'polylang' ),
'post_meta' => __ ( 'Custom fields' , 'polylang' ),
'comment_status' => __ ( 'Comment status' , 'polylang' ),
'ping_status' => __ ( 'Ping status' , 'polylang' ),
'sticky_posts' => __ ( 'Sticky posts' , 'polylang' ),
'post_date' => __ ( 'Published date' , 'polylang' ),
'post_format' => __ ( 'Post format' , 'polylang' ),
'post_parent' => __ ( 'Page parent' , 'polylang' ),
'_wp_page_template' => __ ( 'Page template' , 'polylang' ),
'menu_order' => __ ( 'Page order' , 'polylang' ),
'_thumbnail_id' => __ ( 'Featured image' , 'polylang' ),
);
}
}