PluginProbe
Polylang / 3.7
Polylang v3.7
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / modules / sync / settings-sync.php

settings-sync.php in Polylang 3.7, at modules/sync/settings-sync.php

117 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Polylang
4 */
5
6 /**
7 * Settings class for synchronization settings management
8 *
9 * @since 1.8
10 */
11 class PLL_Settings_Sync extends PLL_Settings_Module {
12 /**
13 * Stores the display order priority.
14 *
15 * @var int
16 */
17 public $priority = 50;
18
19 /**
20 * Constructor
21 *
22 * @since 1.8
23 *
24 * @param object $polylang The polylang object.
25 */
26 public function __construct( &$polylang ) {
27 parent::__construct(
28 $polylang,
29 array(
30 'module' => 'sync',
31 'title' => __( 'Synchronization', 'polylang' ),
32 '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' ),
33 )
34 );
35 }
36
37 /**
38 * Deactivates the module
39 *
40 * @since 1.8
41 */
42 public function deactivate() {
43 $this->options['sync'] = array();
44 }
45
46 /**
47 * Displays the settings form
48 *
49 * @since 1.8
50 */
51 protected function form() {
52 ?>
53 <ul class="pll-inline-block-list">
54 <?php
55 foreach ( self::list_metas_to_sync() as $key => $str ) {
56 printf(
57 '<li><label><input name="sync[%s]" type="checkbox" value="1" %s /> %s</label></li>',
58 esc_attr( $key ),
59 checked( in_array( $key, $this->options['sync'] ), true, false ),
60 esc_html( $str )
61 );
62 }
63 ?>
64 </ul>
65 <?php
66 }
67
68 /**
69 * Prepare the received data before saving.
70 *
71 * @since 3.7
72 *
73 * @param array $options Raw values to save.
74 * @return array
75 */
76 protected function prepare_raw_data( array $options ): array {
77 // Take care to return only validated options.
78 return array( 'sync' => empty( $options['sync'] ) ? array() : array_keys( $options['sync'], 1 ) );
79 }
80
81 /**
82 * Get the row actions.
83 *
84 * @since 1.8
85 *
86 * @return string[] Row actions.
87 */
88 protected function get_actions() {
89 return empty( $this->options['sync'] ) ? array( 'configure' ) : array( 'configure', 'deactivate' );
90 }
91
92 /**
93 * Get the list of synchronization settings.
94 *
95 * @since 1.0
96 *
97 * @return string[] Array synchronization options.
98 *
99 * @phpstan-return non-empty-array<non-falsy-string, string>
100 */
101 public static function list_metas_to_sync() {
102 return array(
103 'taxonomies' => __( 'Taxonomies', 'polylang' ),
104 'post_meta' => __( 'Custom fields', 'polylang' ),
105 'comment_status' => __( 'Comment status', 'polylang' ),
106 'ping_status' => __( 'Ping status', 'polylang' ),
107 'sticky_posts' => __( 'Sticky posts', 'polylang' ),
108 'post_date' => __( 'Published date', 'polylang' ),
109 'post_format' => __( 'Post format', 'polylang' ),
110 'post_parent' => __( 'Page parent', 'polylang' ),
111 '_wp_page_template' => __( 'Page template', 'polylang' ),
112 'menu_order' => __( 'Page order', 'polylang' ),
113 '_thumbnail_id' => __( 'Featured image', 'polylang' ),
114 );
115 }
116 }
117