| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * Base class for both admin |
| 8 | 5 | * |
| @@ -22,9 +19,9 @@ | ||
| 22 | 19 | public function __construct( &$links_model ) { |
| 23 | 20 | parent::__construct( $links_model ); |
| 24 | 21 | |
| 25 | 22 | // Plugin i18n, only needed for backend |
| 26 | - load_plugin_textdomain( 'polylang' ); | |
| 23 | + load_plugin_textdomain( 'polylang', false, basename( POLYLANG_DIR ) . '/languages' ); | |
| 27 | 24 | |
| 28 | 25 | // Adds the link to the languages panel in the WordPress admin menu |
| 29 | 26 | add_action( 'admin_menu', array( $this, 'add_menus' ) ); |
| 30 | 27 | |
| @@ -32,8 +29,15 @@ | ||
| 32 | 29 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 33 | 30 | add_action( 'admin_print_footer_scripts', array( $this, 'admin_print_footer_scripts' ), 0 ); // High priority in case an ajax request is sent by an immediately invoked function |
| 34 | 31 | |
| 35 | 32 | add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_controls_enqueue_scripts' ) ); |
| 33 | + | |
| 34 | + if ( defined( 'POLYLANG_PRO' ) ) { | |
| 35 | + new PLL_Pro(); | |
| 36 | + } elseif ( ! defined( 'PLL_LINGOTEK_AD' ) || PLL_LINGOTEK_AD ) { | |
| 37 | + require_once POLYLANG_DIR . '/lingotek/lingotek.php'; // Lingotek | |
| 38 | + add_action( 'wp_loaded', array( new PLL_Lingotek(), 'init' ) ); | |
| 39 | + } | |
| 36 | 40 | } |
| 37 | 41 | |
| 38 | 42 | /** |
| 39 | 43 | * Setups filters and action needed on all admin pages and on plugins page |
| @@ -43,14 +47,13 @@ | ||
| 43 | 47 | */ |
| 44 | 48 | public function init() { |
| 45 | 49 | parent::init(); |
| 46 | 50 | |
| 47 | - $this->notices = new PLL_Admin_Notices( $this ); | |
| 48 | - | |
| 49 | 51 | if ( ! $this->model->get_languages_list() ) { |
| 50 | 52 | return; |
| 51 | 53 | } |
| 52 | 54 | |
| 55 | + $this->notices = new PLL_Admin_Notices( $this ); | |
| 53 | 56 | $this->links = new PLL_Admin_Links( $this ); // FIXME needed here ? |
| 54 | 57 | $this->static_pages = new PLL_Admin_Static_Pages( $this ); // FIXME needed here ? |
| 55 | 58 | $this->filters_links = new PLL_Filters_Links( $this ); // FIXME needed here ? |
| 56 | 59 | |
| @@ -55,13 +58,19 @@ | ||
| 55 | 58 | $this->filters_links = new PLL_Filters_Links( $this ); // FIXME needed here ? |
| 56 | 59 | |
| 57 | 60 | // Filter admin language for users |
| 58 | 61 | // We must not call user info before WordPress defines user roles in wp-settings.php |
| 59 | - add_action( 'setup_theme', array( $this, 'init_user' ) ); | |
| 62 | + add_filter( 'setup_theme', array( $this, 'init_user' ) ); | |
| 60 | 63 | add_filter( 'request', array( $this, 'request' ) ); |
| 61 | 64 | |
| 62 | 65 | // Adds the languages in admin bar |
| 63 | 66 | add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 100 ); // 100 determines the position |
| 67 | + | |
| 68 | + // Translate slugs, only for pretty permalinks | |
| 69 | + if ( get_option( 'permalink_structure' ) && class_exists( 'PLL_Translate_Slugs' ) ) { | |
| 70 | + $slugs_model = new PLL_Translate_Slugs_Model( $this ); | |
| 71 | + $this->translate_slugs = new PLL_Translate_Slugs( $slugs_model, $this->curlang ); | |
| 72 | + } | |
| 64 | 73 | } |
| 65 | 74 | |
| 66 | 75 | /** |
| 67 | 76 | * Adds the link to the languages panel in the WordPress admin menu |
| @@ -68,10 +77,8 @@ | ||
| 68 | 77 | * |
| 69 | 78 | * @since 0.1 |
| 70 | 79 | */ |
| 71 | 80 | public function add_menus() { |
| 72 | - global $admin_page_hooks; | |
| 73 | - | |
| 74 | 81 | // Prepare the list of tabs |
| 75 | 82 | $tabs = array( 'lang' => __( 'Languages', 'polylang' ) ); |
| 76 | 83 | |
| 77 | 84 | // Only if at least one language has been created |
| @@ -89,16 +96,13 @@ | ||
| 89 | 96 | * @param array $tabs list of tab names |
| 90 | 97 | */ |
| 91 | 98 | $tabs = apply_filters( 'pll_settings_tabs', $tabs ); |
| 92 | 99 | |
| 93 | - $parent = ''; | |
| 94 | - | |
| 95 | 100 | foreach ( $tabs as $tab => $title ) { |
| 96 | 101 | $page = 'lang' === $tab ? 'mlang' : "mlang_$tab"; |
| 97 | 102 | if ( empty( $parent ) ) { |
| 98 | 103 | $parent = $page; |
| 99 | 104 | add_menu_page( $title, __( 'Languages', 'polylang' ), 'manage_options', $page, null, 'dashicons-translation' ); |
| 100 | - $admin_page_hooks[ $page ] = 'languages'; // Hack to avoid the localization of the hook name. See: https://core.trac.wordpress.org/ticket/18857 | |
| 101 | 105 | } |
| 102 | 106 | |
| 103 | 107 | add_submenu_page( $parent, $title, $title, 'manage_options', $page, array( $this, 'languages_page' ) ); |
| 104 | 108 | } |
| @@ -116,23 +120,22 @@ | ||
| 116 | 120 | } |
| 117 | 121 | |
| 118 | 122 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 119 | 123 | |
| 120 | - /* | |
| 121 | - * For each script: | |
| 122 | - * 0 => the pages on which to load the script | |
| 123 | - * 1 => the scripts it needs to work | |
| 124 | - * 2 => 1 if loaded even if languages have not been defined yet, 0 otherwise | |
| 125 | - * 3 => 1 if loaded in footer | |
| 126 | - */ | |
| 124 | + // For each script: | |
| 125 | + // 0 => the pages on which to load the script | |
| 126 | + // 1 => the scripts it needs to work | |
| 127 | + // 2 => 1 if loaded even if languages have not been defined yet, 0 otherwise | |
| 128 | + // 3 => 1 if loaded in footer | |
| 129 | + // FIXME: check if I can load more scripts in footer | |
| 127 | 130 | $scripts = array( |
| 128 | - 'user' => array( array( 'profile', 'user-edit' ), array( 'jquery' ), 0, 0 ), | |
| 129 | - 'widgets' => array( array( 'widgets' ), array( 'jquery' ), 0, 0 ), | |
| 131 | + 'post' => array( array( 'edit', 'upload' ), array( 'jquery', 'wp-ajax-response' ), 0, 1 ), | |
| 132 | + 'term' => array( array( 'edit-tags', 'term' ), array( 'jquery', 'wp-ajax-response', 'jquery-ui-autocomplete' ), 0, 1 ), | |
| 133 | + 'user' => array( array( 'profile', 'user-edit' ), array( 'jquery' ), 0, 0 ), | |
| 134 | + 'widgets' => array( array( 'widgets' ), array( 'jquery' ), 0, 0 ), | |
| 130 | 135 | ); |
| 131 | 136 | |
| 132 | 137 | if ( ! empty( $screen->post_type ) && $this->model->is_translated_post_type( $screen->post_type ) ) { |
| 133 | - $scripts['post'] = array( array( 'edit', 'upload' ), array( 'jquery', 'wp-ajax-response' ), 0, 1 ); | |
| 134 | - | |
| 135 | 138 | // Classic editor. |
| 136 | 139 | if ( ! method_exists( $screen, 'is_block_editor' ) || ! $screen->is_block_editor() ) { |
| 137 | 140 | $scripts['classic-editor'] = array( array( 'post', 'media', 'async-upload' ), array( 'jquery', 'wp-ajax-response', 'post' ), 0, 1 ); |
| 138 | 141 | } |
| @@ -142,12 +145,8 @@ | ||
| 142 | 145 | $scripts['block-editor'] = array( array( 'post' ), array( 'jquery', 'wp-ajax-response', 'wp-api-fetch' ), 0, 1 ); |
| 143 | 146 | } |
| 144 | 147 | } |
| 145 | 148 | |
| 146 | - if ( ! empty( $screen->taxonomy ) && $this->model->is_translated_taxonomy( $screen->taxonomy ) ) { | |
| 147 | - $scripts['term'] = array( array( 'edit-tags', 'term' ), array( 'jquery', 'wp-ajax-response', 'jquery-ui-autocomplete' ), 0, 1 ); | |
| 148 | - } | |
| 149 | - | |
| 150 | 149 | foreach ( $scripts as $script => $v ) { |
| 151 | 150 | if ( in_array( $screen->base, $v[0] ) && ( $v[2] || $this->model->get_languages_list() ) ) { |
| 152 | 151 | wp_enqueue_script( 'pll_' . $script, plugins_url( '/js/' . $script . $suffix . '.js', POLYLANG_FILE ), $v[1], POLYLANG_VERSION, $v[3] ); |
| 153 | 152 | } |
| @@ -176,8 +175,24 @@ | ||
| 176 | 175 | * |
| 177 | 176 | * @since 2.4.0 |
| 178 | 177 | */ |
| 179 | 178 | public function localize_scripts() { |
| 179 | + if ( wp_script_is( 'pll_classic-editor', 'enqueued' ) ) { | |
| 180 | + wp_localize_script( | |
| 181 | + 'pll_classic-editor', | |
| 182 | + 'confirm_text', | |
| 183 | + __( 'You are about to overwrite an existing translation. Are you sure you want to proceed?', 'polylang' ) | |
| 184 | + ); | |
| 185 | + } | |
| 186 | + | |
| 187 | + if ( wp_script_is( 'pll_block-editor', 'enqueued' ) ) { | |
| 188 | + wp_localize_script( | |
| 189 | + 'pll_block-editor', | |
| 190 | + 'confirm_text', | |
| 191 | + __( 'You are about to overwrite an existing translation. Are you sure you want to proceed?', 'polylang' ) | |
| 192 | + ); | |
| 193 | + } | |
| 194 | + | |
| 180 | 195 | if ( wp_script_is( 'pll_widgets', 'enqueued' ) ) { |
| 181 | 196 | wp_localize_script( |
| 182 | 197 | 'pll_widgets', |
| 183 | 198 | 'pll_widgets', |