| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Polylang |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* Main Polylang class for admin (except Polylang pages), accessible from @see PLL(). |
| 8 |
* |
| 9 |
* @since 1.2 |
| 10 |
*/ |
| 11 |
class PLL_Admin extends PLL_Admin_Base { |
| 12 |
/** |
| 13 |
* @var PLL_Admin_Filters|null |
| 14 |
*/ |
| 15 |
public $filters; |
| 16 |
|
| 17 |
/** |
| 18 |
* @var PLL_Admin_Filters_Columns|null |
| 19 |
*/ |
| 20 |
public $filters_columns; |
| 21 |
|
| 22 |
/** |
| 23 |
* @var PLL_Admin_Filters_Post|null |
| 24 |
*/ |
| 25 |
public $filters_post; |
| 26 |
|
| 27 |
/** |
| 28 |
* @var PLL_Admin_Filters_Term|null |
| 29 |
*/ |
| 30 |
public $filters_term; |
| 31 |
|
| 32 |
/** |
| 33 |
* @var PLL_Admin_Filters_Media|null |
| 34 |
*/ |
| 35 |
public $filters_media; |
| 36 |
|
| 37 |
/** |
| 38 |
* @since 2.9 |
| 39 |
* |
| 40 |
* @var PLL_Filters_Sanitization|null |
| 41 |
*/ |
| 42 |
public $filters_sanitization; |
| 43 |
|
| 44 |
/** |
| 45 |
* @var PLL_Admin_Block_Editor|null |
| 46 |
*/ |
| 47 |
public $block_editor; |
| 48 |
|
| 49 |
/** |
| 50 |
* @var PLL_Admin_Classic_Editor|null |
| 51 |
*/ |
| 52 |
public $classic_editor; |
| 53 |
|
| 54 |
/** |
| 55 |
* @var PLL_Admin_Nav_Menu|null |
| 56 |
*/ |
| 57 |
public $nav_menu; |
| 58 |
|
| 59 |
/** |
| 60 |
* @var PLL_Admin_Filters_Widgets_Options|null |
| 61 |
*/ |
| 62 |
public $filters_widgets_options; |
| 63 |
|
| 64 |
/** |
| 65 |
* Setups filters and action needed on all admin pages and on plugins page. |
| 66 |
* |
| 67 |
* @since 1.2 |
| 68 |
* |
| 69 |
* @param PLL_Links_Model $links_model Reference to the links model. |
| 70 |
*/ |
| 71 |
public function __construct( &$links_model ) { |
| 72 |
parent::__construct( $links_model ); |
| 73 |
|
| 74 |
// Adds a 'settings' link in the plugins table |
| 75 |
add_filter( 'plugin_action_links_' . POLYLANG_BASENAME, array( $this, 'plugin_action_links' ) ); |
| 76 |
add_action( 'in_plugin_update_message-' . POLYLANG_BASENAME, array( $this, 'plugin_update_message' ), 10, 2 ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Setups filters and action needed on all admin pages and on plugins page |
| 81 |
* Loads the settings pages or the filters base on the request |
| 82 |
* |
| 83 |
* @since 1.2 |
| 84 |
*/ |
| 85 |
public function init() { |
| 86 |
parent::init(); |
| 87 |
|
| 88 |
// Setup filters for admin pages |
| 89 |
// Priority 5 to make sure filters are there before customize_register is fired |
| 90 |
if ( $this->model->get_languages_list() ) { |
| 91 |
add_action( 'wp_loaded', array( $this, 'add_filters' ), 5 ); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Adds a 'settings' link for our plugin in the plugins list table. |
| 97 |
* |
| 98 |
* @since 0.1 |
| 99 |
* |
| 100 |
* @param string[] $links List of links associated to the plugin. |
| 101 |
* @return string[] Modified list of links. |
| 102 |
*/ |
| 103 |
public function plugin_action_links( $links ) { |
| 104 |
array_unshift( $links, '<a href="admin.php?page=mlang">' . __( 'Settings', 'polylang' ) . '</a>' ); |
| 105 |
return $links; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Adds the upgrade notice in plugins table |
| 110 |
* |
| 111 |
* @since 1.1.6 |
| 112 |
* |
| 113 |
* @param array $plugin_data Not used |
| 114 |
* @param object $r Plugin update data |
| 115 |
* @return void |
| 116 |
*/ |
| 117 |
public function plugin_update_message( $plugin_data, $r ) { |
| 118 |
if ( isset( $r->upgrade_notice ) ) { |
| 119 |
printf( '<p style="margin: 3px 0 0 0; border-top: 1px solid #ddd; padding-top: 3px">%s</p>', esc_html( $r->upgrade_notice ) ); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Setup filters for admin pages |
| 125 |
* |
| 126 |
* @since 1.2 |
| 127 |
* @since 2.7 instantiate a PLL_Bulk_Translate instance. |
| 128 |
* @return void |
| 129 |
*/ |
| 130 |
public function add_filters() { |
| 131 |
$this->filters_sanitization = new PLL_Filters_Sanitization( $this->get_locale_for_sanitization() ); |
| 132 |
$this->filters_widgets_options = new PLL_Admin_Filters_Widgets_Options( $this ); |
| 133 |
|
| 134 |
// All these are separated just for convenience and maintainability |
| 135 |
$classes = array( 'Filters', 'Filters_Columns', 'Filters_Post', 'Filters_Term', 'Nav_Menu', 'Classic_Editor', 'Block_Editor' ); |
| 136 |
|
| 137 |
// Don't load media filters if option is disabled or if user has no right |
| 138 |
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 ) ) ) { |
| 139 |
$classes[] = 'Filters_Media'; |
| 140 |
} |
| 141 |
|
| 142 |
foreach ( $classes as $class ) { |
| 143 |
$obj = strtolower( $class ); |
| 144 |
|
| 145 |
/** |
| 146 |
* Filter the class to instantiate when loading admin filters |
| 147 |
* |
| 148 |
* @since 1.5 |
| 149 |
* |
| 150 |
* @param string $class class name |
| 151 |
*/ |
| 152 |
$class = apply_filters( 'pll_' . $obj, 'PLL_Admin_' . $class ); |
| 153 |
$this->$obj = new $class( $this ); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Retrieve the locale according to the current language instead of the language |
| 159 |
* of the admin interface. |
| 160 |
* |
| 161 |
* @since 2.0 |
| 162 |
* |
| 163 |
* @return string |
| 164 |
*/ |
| 165 |
public function get_locale_for_sanitization() { |
| 166 |
$locale = get_locale(); |
| 167 |
|
| 168 |
if ( isset( $_POST['post_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['post_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 169 |
$locale = $lang->locale; |
| 170 |
} elseif ( isset( $_POST['term_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 171 |
$locale = $lang->locale; |
| 172 |
} elseif ( isset( $_POST['inline_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 173 |
$locale = $lang->locale; |
| 174 |
} elseif ( ! empty( $this->curlang ) ) { |
| 175 |
$locale = $this->curlang->locale; |
| 176 |
} |
| 177 |
|
| 178 |
return $locale; |
| 179 |
} |
| 180 |
} |
| 181 |
|