| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * Admin side controller |
| 8 | 5 | * accessible in $polylang global object |
| @@ -7,84 +4,35 @@ | ||
| 7 | 4 | * Admin side controller |
| 8 | 5 | * accessible in $polylang global object |
| 9 | 6 | * |
| 10 | 7 | * Properties: |
| 11 | - * options => inherited, reference to Polylang options array | |
| 12 | - * model => inherited, reference to PLL_Model object | |
| 13 | - * links_model => inherited, reference to PLL_Links_Model object | |
| 14 | - * links => inherited, reference to PLL_Admin_Links object | |
| 15 | - * static_pages => inherited, reference to PLL_Admin_Static_Pages object | |
| 16 | - * filters_links => inherited, reference to PLL_Filters_Links object | |
| 17 | - * curlang => inherited, optional, current language used to filter the content (language of the post or term being edited, equal to filter_lang otherwise) | |
| 18 | - * filter_lang => inherited, optional, current status of the admin languages filter (in the admin bar) | |
| 19 | - * pref_lang => inherited, preferred language used as default when saving posts or terms | |
| 20 | - * posts => reference to PLL_CRUD_Posts object | |
| 21 | - * terms => reference to PLL_CRUD_Terms object | |
| 22 | - * filters => reference to PLL_Admin_Filters object | |
| 23 | - * filters_sanitization => reference to PLL_Filters_Sanitization object | |
| 24 | - * filters_columns => reference to PLL_Admin_Filters_Columns object | |
| 25 | - * filters_post => reference to PLL_Admin_Filters_Post object | |
| 26 | - * filters_term => reference to PLL_Admin_filters_Term object | |
| 27 | - * nav_menu => reference to PLL_Admin_Nav_Menu object | |
| 28 | - * block_editor => reference to PLL_Admin_Block_Editor object | |
| 29 | - * classic_editor => reference to PLL_Admin_Classic_Editor object | |
| 30 | - * filters_media => optional, reference to PLL_Admin_Filters_Media object | |
| 8 | + * options => inherited, reference to Polylang options array | |
| 9 | + * model => inherited, reference to PLL_Model object | |
| 10 | + * links_model => inherited, reference to PLL_Links_Model object | |
| 11 | + * links => inherited, reference to PLL_Admin_Links object | |
| 12 | + * static_pages => inherited, reference to PLL_Admin_Static_Pages object | |
| 13 | + * filters_links => inherited, reference to PLL_Filters_Links object | |
| 14 | + * curlang => inherited, optional, current language used to filter the content (language of the post or term being edited, equal to filter_lang otherwise) | |
| 15 | + * filter_lang => inherited, optional, current status of the admin languages filter (in the admin bar) | |
| 16 | + * pref_lang => inherited, preferred language used as default when saving posts or terms | |
| 17 | + * posts => reference to PLL_CRUD_Posts object | |
| 18 | + * terms => reference to PLL_CRUD_Terms object | |
| 19 | + * filters => reference to PLL_Admin_Filters object | |
| 20 | + * filters_columns => reference to PLL_Admin_Filters_Columns object | |
| 21 | + * filters_post => reference to PLL_Admin_Filters_Post object | |
| 22 | + * filters_term => reference to PLL_Admin_filters_Term object | |
| 23 | + * nav_menu => reference to PLL_Admin_Nav_Menu object | |
| 24 | + * sync => reference to PLL_Admin_Sync object | |
| 25 | + * block_editor => reference to PLL_Admin_Block_Editor object | |
| 26 | + * classic_editor => reference to PLL_Admin_Classic_Editor object | |
| 27 | + * filters_media => optional, reference to PLL_Admin_Filters_Media object | |
| 31 | 28 | * |
| 32 | 29 | * @since 1.2 |
| 33 | 30 | */ |
| 34 | 31 | class PLL_Admin extends PLL_Admin_Base { |
| 35 | - /** | |
| 36 | - * Instance of PLL_Admin_Filters | |
| 37 | - * | |
| 38 | - * @var PLL_Admin_Filters | |
| 39 | - */ | |
| 40 | - public $filters; | |
| 32 | + public $filters, $filters_columns, $filters_post, $filters_term, $nav_menu, $sync, $filters_media; | |
| 41 | 33 | |
| 42 | 34 | /** |
| 43 | - * Instance of PLL_Admin_Filters_Columns | |
| 44 | - * | |
| 45 | - * @var PLL_Admin_Filters_Columns | |
| 46 | - */ | |
| 47 | - public $filters_columns; | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * Instance of PLL_Admin_Filters_Post | |
| 51 | - * | |
| 52 | - * @var PLL_Admin_Filters_Post | |
| 53 | - */ | |
| 54 | - public $filters_post; | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * Instance of PLL_Admin_filters_Term | |
| 58 | - * | |
| 59 | - * @var PLL_Admin_filters_Term | |
| 60 | - */ | |
| 61 | - public $filters_term; | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * Instance of PLL_Admin_Nav_Menu | |
| 65 | - * | |
| 66 | - * @var PLL_Admin_Nav_Menu | |
| 67 | - */ | |
| 68 | - public $nav_menu; | |
| 69 | - | |
| 70 | - /** | |
| 71 | - * Instance of PLL_Admin_Filters_Media | |
| 72 | - * | |
| 73 | - * @var PLL_Admin_Filters_Media | |
| 74 | - */ | |
| 75 | - public $filters_media; | |
| 76 | - | |
| 77 | - /** | |
| 78 | - * Instance of PLL_Filters_Sanitization | |
| 79 | - * | |
| 80 | - * @since 2.9 | |
| 81 | - * | |
| 82 | - * @var PLL_Filters_Sanitization | |
| 83 | - */ | |
| 84 | - public $filters_sanitization; | |
| 85 | - | |
| 86 | - /** | |
| 87 | 35 | * Loads the polylang text domain |
| 88 | 36 | * Setups filters and action needed on all admin pages and on plugins page |
| 89 | 37 | * |
| 90 | 38 | * @since 1.2 |
| @@ -111,8 +59,14 @@ | ||
| 111 | 59 | // Setup filters for admin pages |
| 112 | 60 | // Priority 5 to make sure filters are there before customize_register is fired |
| 113 | 61 | if ( $this->model->get_languages_list() ) { |
| 114 | 62 | add_action( 'wp_loaded', array( $this, 'add_filters' ), 5 ); |
| 63 | + add_action( 'admin_init', array( $this, 'maybe_load_sync_post' ) ); | |
| 64 | + | |
| 65 | + // Bulk Translate | |
| 66 | + if ( class_exists( 'PLL_Bulk_Translate' ) ) { | |
| 67 | + add_action( 'current_screen', array( $this->bulk_translate = new PLL_Bulk_Translate( $this ), 'init' ) ); | |
| 68 | + } | |
| 115 | 69 | } |
| 116 | 70 | } |
| 117 | 71 | |
| 118 | 72 | /** |
| @@ -145,14 +99,12 @@ | ||
| 145 | 99 | /** |
| 146 | 100 | * Setup filters for admin pages |
| 147 | 101 | * |
| 148 | 102 | * @since 1.2 |
| 149 | - * @since 2.7 instantiate a PLL_Bulk_Translate instance. | |
| 150 | 103 | */ |
| 151 | 104 | public function add_filters() { |
| 152 | - $this->filters_sanitization = new PLL_Filters_Sanitization( $this->get_locale_for_sanitization() ); | |
| 153 | 105 | // All these are separated just for convenience and maintainability |
| 154 | - $classes = array( 'Filters', 'Filters_Columns', 'Filters_Post', 'Filters_Term', 'Nav_Menu', 'Classic_Editor', 'Block_Editor' ); | |
| 106 | + $classes = array( 'Filters', 'Filters_Columns', 'Filters_Post', 'Filters_Term', 'Nav_Menu', 'Sync', 'Classic_Editor', 'Block_Editor' ); | |
| 155 | 107 | |
| 156 | 108 | // Don't load media filters if option is disabled or if user has no right |
| 157 | 109 | if ( $this->options['media_support'] && ( $obj = get_post_type_object( 'attachment' ) ) && ( current_user_can( $obj->cap->edit_posts ) || current_user_can( $obj->cap->create_posts ) ) ) { |
| 158 | 110 | $classes[] = 'Filters_Media'; |
| @@ -170,29 +122,72 @@ | ||
| 170 | 122 | */ |
| 171 | 123 | $class = apply_filters( 'pll_' . $obj, 'PLL_Admin_' . $class ); |
| 172 | 124 | $this->$obj = new $class( $this ); |
| 173 | 125 | } |
| 126 | + | |
| 127 | + $this->posts = new PLL_CRUD_Posts( $this ); | |
| 128 | + $this->terms = new PLL_CRUD_Terms( $this ); | |
| 129 | + | |
| 130 | + // Advanced media | |
| 131 | + if ( $this->options['media_support'] && class_exists( 'PLL_Admin_Advanced_Media' ) ) { | |
| 132 | + $this->advanced_media = new PLL_Admin_Advanced_Media( $this ); | |
| 133 | + } | |
| 134 | + | |
| 135 | + // Share term slugs | |
| 136 | + if ( get_option( 'permalink_structure' ) && $this->options['force_lang'] && class_exists( 'PLL_Admin_Share_Term_Slug' ) ) { | |
| 137 | + $this->share_term_slug = new PLL_Admin_Share_Term_Slug( $this ); | |
| 138 | + } | |
| 139 | + | |
| 140 | + if ( class_exists( 'PLL_Sync_Content' ) ) { | |
| 141 | + $this->sync_content = new PLL_Sync_Content( $this ); | |
| 142 | + } | |
| 143 | + | |
| 144 | + // Duplicate content | |
| 145 | + if ( class_exists( 'PLL_Duplicate' ) ) { | |
| 146 | + $this->duplicate = new PLL_Duplicate( $this ); | |
| 147 | + } | |
| 148 | + | |
| 149 | + if ( class_exists( 'PLL_Duplicate_REST' ) ) { | |
| 150 | + $this->duplicate_rest = new PLL_Duplicate_REST(); | |
| 151 | + } | |
| 152 | + | |
| 153 | + // Block editor metabox | |
| 154 | + if ( pll_use_block_editor_plugin() ) { | |
| 155 | + $this->block_editor_plugin = new PLL_Block_Editor_Plugin( $this ); | |
| 156 | + } | |
| 174 | 157 | } |
| 158 | + | |
| 175 | 159 | /** |
| 176 | - * Retrieve the locale according to the current language instead of the language | |
| 177 | - * of the admin interface. | |
| 160 | + * Load the post synchronization object, depending on the editor in use. | |
| 178 | 161 | * |
| 179 | - * @since 2.0 | |
| 162 | + * @since 2.6 | |
| 163 | + */ | |
| 164 | + public function maybe_load_sync_post() { | |
| 165 | + // Post synchronization | |
| 166 | + if ( 'post-new.php' === $GLOBALS['pagenow'] && function_exists( 'use_block_editor_for_post' ) ) { | |
| 167 | + // We need to wait until we know which editor is in use | |
| 168 | + add_filter( 'use_block_editor_for_post', array( $this, '_maybe_load_sync_post' ), 999 ); // After the plugin Classic Editor | |
| 169 | + } elseif ( 'post.php' === $GLOBALS['pagenow'] && function_exists( 'use_block_editor_for_post' ) && isset( $_GET['post'] ) && empty( $_GET['meta-box-loader'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 170 | + $this->_maybe_load_sync_post( use_block_editor_for_post( (int) $_GET['post'] ) ); // phpcs:ignore WordPress.Security.NonceVerification | |
| 171 | + } else { | |
| 172 | + $this->_maybe_load_sync_post( false ); | |
| 173 | + } | |
| 174 | + } | |
| 175 | + | |
| 176 | + /** | |
| 177 | + * Load the post synchronization object, depending on the editor in use. | |
| 180 | 178 | * |
| 181 | - * @return string | |
| 179 | + * @since 2.6 | |
| 180 | + * | |
| 181 | + * @param bool $is_block_editor Whether to use the block editor or not | |
| 182 | + * @return bool | |
| 182 | 183 | */ |
| 183 | - public function get_locale_for_sanitization() { | |
| 184 | - $locale = get_locale(); | |
| 185 | - | |
| 186 | - if ( isset( $_POST['post_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['post_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 187 | - $locale = $lang->locale; | |
| 188 | - } elseif ( isset( $_POST['term_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 189 | - $locale = $lang->locale; | |
| 190 | - } elseif ( isset( $_POST['inline_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 191 | - $locale = $lang->locale; | |
| 192 | - } elseif ( ! empty( $this->curlang ) ) { | |
| 193 | - $locale = $this->curlang->locale; | |
| 184 | + public function _maybe_load_sync_post( $is_block_editor ) { | |
| 185 | + if ( class_exists( 'PLL_Sync_Post_REST' ) && pll_use_block_editor_plugin() && $is_block_editor ) { | |
| 186 | + $this->sync_post = new PLL_Sync_Post_REST( $this ); | |
| 187 | + } elseif ( class_exists( 'PLL_Sync_Post' ) ) { | |
| 188 | + $this->sync_post = new PLL_Sync_Post( $this ); | |
| 194 | 189 | } |
| 195 | 190 | |
| 196 | - return $locale; | |
| 191 | + return $is_block_editor; | |
| 197 | 192 | } |
| 198 | 193 | } |