PluginProbe
Polylang / 2.6.5
Polylang v2.6.5
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 / admin / admin.php

admin.php in Polylang 2.6.5, at admin/admin.php

199 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Admin side controller
5 * accessible in $polylang global object
6 *
7 * Properties:
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
28 *
29 * @since 1.2
30 */
31 class PLL_Admin extends PLL_Admin_Base {
32 public $filters, $filters_columns, $filters_post, $filters_term, $nav_menu, $sync, $filters_media;
33
34 /**
35 * Loads the polylang text domain
36 * Setups filters and action needed on all admin pages and on plugins page
37 *
38 * @since 1.2
39 *
40 * @param object $links_model
41 */
42 public function __construct( &$links_model ) {
43 parent::__construct( $links_model );
44
45 // Adds a 'settings' link in the plugins table
46 add_filter( 'plugin_action_links_' . POLYLANG_BASENAME, array( $this, 'plugin_action_links' ) );
47 add_action( 'in_plugin_update_message-' . POLYLANG_BASENAME, array( $this, 'plugin_update_message' ), 10, 2 );
48 }
49
50 /**
51 * Setups filters and action needed on all admin pages and on plugins page
52 * Loads the settings pages or the filters base on the request
53 *
54 * @since 1.2
55 */
56 public function init() {
57 parent::init();
58
59 // Setup filters for admin pages
60 // Priority 5 to make sure filters are there before customize_register is fired
61 if ( $this->model->get_languages_list() ) {
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 }
69 }
70 }
71
72 /**
73 * Adds a 'settings' link in the plugins table
74 *
75 * @since 0.1
76 *
77 * @param array $links list of links associated to the plugin
78 * @return array modified list of links
79 */
80 public function plugin_action_links( $links ) {
81 array_unshift( $links, '<a href="admin.php?page=mlang">' . __( 'Settings', 'polylang' ) . '</a>' );
82 return $links;
83 }
84
85 /**
86 * Adds the upgrade notice in plugins table
87 *
88 * @since 1.1.6
89 *
90 * @param array $plugin_data Not used
91 * @param object $r Plugin update data
92 */
93 public function plugin_update_message( $plugin_data, $r ) {
94 if ( isset( $r->upgrade_notice ) ) {
95 printf( '<p style="margin: 3px 0 0 0; border-top: 1px solid #ddd; padding-top: 3px">%s</p>', esc_html( $r->upgrade_notice ) );
96 }
97 }
98
99 /**
100 * Setup filters for admin pages
101 *
102 * @since 1.2
103 */
104 public function add_filters() {
105 // All these are separated just for convenience and maintainability
106 $classes = array( 'Filters', 'Filters_Columns', 'Filters_Post', 'Filters_Term', 'Nav_Menu', 'Sync', 'Classic_Editor', 'Block_Editor' );
107
108 // Don't load media filters if option is disabled or if user has no right
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 ) ) ) {
110 $classes[] = 'Filters_Media';
111 }
112
113 foreach ( $classes as $class ) {
114 $obj = strtolower( $class );
115
116 /**
117 * Filter the class to instantiate when loading admin filters
118 *
119 * @since 1.5
120 *
121 * @param string $class class name
122 */
123 $class = apply_filters( 'pll_' . $obj, 'PLL_Admin_' . $class );
124 $this->$obj = new $class( $this );
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 // Duplicate content
141 if ( class_exists( 'PLL_Duplicate' ) ) {
142 $this->duplicate = new PLL_Duplicate( $this );
143 }
144
145 if ( class_exists( 'PLL_Duplicate_REST' ) ) {
146 $this->duplicate_rest = new PLL_Duplicate_REST();
147 }
148
149 // Block editor metabox
150 if ( pll_use_block_editor_plugin() ) {
151 $this->block_editor_plugin = new PLL_Block_Editor_Plugin( $this );
152 }
153
154 // FIXME: Specific for WP CRON and WP CLI as the action admin_init is not fired.
155 // Waiting for a better way to handle the cases without loading the complete admin.
156 if ( wp_doing_cron() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
157 $this->maybe_load_sync_post();
158 }
159
160 }
161
162 /**
163 * Load the post synchronization object, depending on the editor in use.
164 *
165 * @since 2.6
166 */
167 public function maybe_load_sync_post() {
168 // Post synchronization
169 if ( 'post-new.php' === $GLOBALS['pagenow'] && function_exists( 'use_block_editor_for_post' ) ) {
170 // We need to wait until we know which editor is in use
171 add_filter( 'use_block_editor_for_post', array( $this, '_maybe_load_sync_post' ), 999 ); // After the plugin Classic Editor
172 } 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
173 $this->_maybe_load_sync_post( use_block_editor_for_post( (int) $_GET['post'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
174 } else {
175 $this->_maybe_load_sync_post( false );
176 }
177 }
178
179 /**
180 * Load the post synchronization object, depending on the editor in use.
181 *
182 * @since 2.6
183 *
184 * @param bool $is_block_editor Whether to use the block editor or not.
185 * @return bool
186 */
187 public function _maybe_load_sync_post( $is_block_editor ) {
188 if ( ! isset( $this->sync_post ) ) { // Make sure to instantiate the class only once, as the function may be called from a filter.
189 if ( class_exists( 'PLL_Sync_Post_REST' ) && pll_use_block_editor_plugin() && $is_block_editor ) {
190 $this->sync_post = new PLL_Sync_Post_REST( $this );
191 } elseif ( class_exists( 'PLL_Sync_Post' ) ) {
192 $this->sync_post = new PLL_Sync_Post( $this );
193 }
194 }
195
196 return $is_block_editor;
197 }
198 }
199