| @@ -1,5 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * @package Polylang | |
| 4 | + */ | |
| 2 | 5 | |
| 3 | 6 | /** |
| 4 | 7 | * Manages custom menus translations as well as the language switcher menu item on admin side |
| 5 | 8 | * |
| @@ -29,8 +32,10 @@ | ||
| 29 | 32 | * Setups filters and terms |
| 30 | 33 | * adds the language switcher metabox and create new nav menu locations |
| 31 | 34 | * |
| 32 | 35 | * @since 1.1 |
| 36 | + * | |
| 37 | + * @return void | |
| 33 | 38 | */ |
| 34 | 39 | public function admin_init() { |
| 35 | 40 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 36 | 41 | add_action( 'wp_update_nav_menu_item', array( $this, 'wp_update_nav_menu_item' ), 10, 2 ); |
| @@ -51,8 +56,10 @@ | ||
| 51 | 56 | * The checkbox and all hidden fields are important |
| 52 | 57 | * Thanks to John Morris for his very interesting post http://www.johnmorrisonline.com/how-to-add-a-fully-functional-custom-meta-box-to-wordpress-navigation-menus/ |
| 53 | 58 | * |
| 54 | 59 | * @since 1.1 |
| 60 | + * | |
| 61 | + * @return void | |
| 55 | 62 | */ |
| 56 | 63 | public function lang_switch() { |
| 57 | 64 | global $_nav_menu_placeholder, $nav_menu_selected_id; |
| 58 | 65 | $_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1; |
| @@ -64,9 +71,9 @@ | ||
| 64 | 71 | <label class="menu-item-title"> |
| 65 | 72 | <input type="checkbox" class="menu-item-checkbox" name="menu-item[<?php echo (int) $_nav_menu_placeholder; ?>][menu-item-object-id]" value="-1"> <?php esc_html_e( 'Languages', 'polylang' ); ?> |
| 66 | 73 | </label> |
| 67 | 74 | <input type="hidden" class="menu-item-type" name="menu-item[<?php echo (int) $_nav_menu_placeholder; ?>][menu-item-type]" value="custom"> |
| 68 | - <input type="hidden" class="menu-item-title" name="menu-item[<?php echo (int) $_nav_menu_placeholder; ?>][menu-item-title]" value="<?php esc_html_e( 'Languages', 'polylang' ); ?>"> | |
| 75 | + <input type="hidden" class="menu-item-title" name="menu-item[<?php echo (int) $_nav_menu_placeholder; ?>][menu-item-title]" value="<?php esc_attr_e( 'Languages', 'polylang' ); ?>"> | |
| 69 | 76 | <input type="hidden" class="menu-item-url" name="menu-item[<?php echo (int) $_nav_menu_placeholder; ?>][menu-item-url]" value="#pll_switcher"> |
| 70 | 77 | </li> |
| 71 | 78 | </ul> |
| 72 | 79 | </div> |
| @@ -83,17 +90,19 @@ | ||
| 83 | 90 | /** |
| 84 | 91 | * Prepares javascript to modify the language switcher menu item |
| 85 | 92 | * |
| 86 | 93 | * @since 1.1 |
| 94 | + * | |
| 95 | + * @return void | |
| 87 | 96 | */ |
| 88 | 97 | public function admin_enqueue_scripts() { |
| 89 | 98 | $screen = get_current_screen(); |
| 90 | - if ( 'nav-menus' != $screen->base ) { | |
| 99 | + if ( empty( $screen ) || 'nav-menus' !== $screen->base ) { | |
| 91 | 100 | return; |
| 92 | 101 | } |
| 93 | 102 | |
| 94 | 103 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 95 | - wp_enqueue_script( 'pll_nav_menu', plugins_url( '/js/nav-menu' . $suffix . '.js', POLYLANG_FILE ), array( 'jquery' ), POLYLANG_VERSION ); | |
| 104 | + wp_enqueue_script( 'pll_nav_menu', plugins_url( '/js/build/nav-menu' . $suffix . '.js', POLYLANG_ROOT_FILE ), array( 'jquery' ), POLYLANG_VERSION ); | |
| 96 | 105 | |
| 97 | 106 | $data = array( |
| 98 | 107 | 'strings' => PLL_Switcher::get_switcher_options( 'menu', 'string' ), // The strings for the options |
| 99 | 108 | 'title' => __( 'Languages', 'polylang' ), // The title |
| @@ -126,8 +135,9 @@ | ||
| 126 | 135 | * @since 1.1 |
| 127 | 136 | * |
| 128 | 137 | * @param int $menu_id not used |
| 129 | 138 | * @param int $menu_item_db_id |
| 139 | + * @return void | |
| 130 | 140 | */ |
| 131 | 141 | public function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0 ) { |
| 132 | 142 | if ( empty( $_POST['menu-item-url'][ $menu_item_db_id ] ) || '#pll_switcher' !== $_POST['menu-item-url'][ $menu_item_db_id ] ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 133 | 143 | return; |
| @@ -175,14 +185,14 @@ | ||
| 175 | 185 | return $locations; |
| 176 | 186 | } |
| 177 | 187 | |
| 178 | 188 | /** |
| 179 | - * Assign menu languages and translations based on ( temporary ) locations | |
| 189 | + * Assign menu languages and translations based on ( temporary ) locations. | |
| 180 | 190 | * |
| 181 | 191 | * @since 1.1 |
| 182 | 192 | * |
| 183 | - * @param array $mods theme mods | |
| 184 | - * @return unmodified $mods | |
| 193 | + * @param mixed $mods Theme mods. | |
| 194 | + * @return mixed | |
| 185 | 195 | */ |
| 186 | 196 | public function pre_update_option_theme_mods( $mods ) { |
| 187 | 197 | if ( current_user_can( 'edit_theme_options' ) && isset( $mods['nav_menu_locations'] ) ) { |
| 188 | 198 | |
| @@ -249,8 +259,9 @@ | ||
| 249 | 259 | * |
| 250 | 260 | * @since 1.7.3 |
| 251 | 261 | * |
| 252 | 262 | * @param int $term_id nav menu id |
| 263 | + * @return void | |
| 253 | 264 | */ |
| 254 | 265 | public function delete_nav_menu( $term_id ) { |
| 255 | 266 | if ( isset( $this->options['nav_menus'] ) ) { |
| 256 | 267 | foreach ( $this->options['nav_menus'] as $theme => $locations ) { |