| @@ -1,12 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | - * Manages custom menus translations | |
| 8 | - * Common to admin and frontend for the customizer | |
| 4 | + * manages custom menus translations | |
| 5 | + * common to admin and frontend for the customizer | |
| 9 | 6 | * |
| 10 | 7 | * @since 1.7.7 |
| 11 | 8 | */ |
| 12 | 9 | class PLL_Nav_Menu { |
| @@ -12,9 +9,9 @@ | ||
| 12 | 9 | class PLL_Nav_Menu { |
| 13 | 10 | public $model, $options; |
| 14 | 11 | |
| 15 | 12 | /** |
| 16 | - * Constructor: setups filters and actions | |
| 13 | + * constructor: setups filters and actions | |
| 17 | 14 | * |
| 18 | 15 | * @since 1.7.7 |
| 19 | 16 | * |
| 20 | 17 | * @param object $polylang |
| @@ -22,37 +19,14 @@ | ||
| 22 | 19 | public function __construct( &$polylang ) { |
| 23 | 20 | $this->model = &$polylang->model; |
| 24 | 21 | $this->options = &$polylang->options; |
| 25 | 22 | |
| 26 | - $this->theme = get_option( 'stylesheet' ); | |
| 27 | - | |
| 28 | - add_filter( 'wp_setup_nav_menu_item', array( $this, 'wp_setup_nav_menu_item' ) ); | |
| 29 | - | |
| 30 | - // Integration with WP customizer | |
| 23 | + // integration with WP customizer | |
| 31 | 24 | add_action( 'customize_register', array( $this, 'create_nav_menu_locations' ), 5 ); |
| 32 | - | |
| 33 | - // Filter _wp_auto_add_pages_to_menu by language | |
| 34 | - add_action( 'transition_post_status', array( $this, 'auto_add_pages_to_menu' ), 5, 3 ); // before _wp_auto_add_pages_to_menu | |
| 35 | 25 | } |
| 36 | 26 | |
| 37 | 27 | /** |
| 38 | - * Assigns the title and label to the language switcher menu items | |
| 39 | - * | |
| 40 | - * @since 2.6 | |
| 41 | - * | |
| 42 | - * @param object $item Menu item. | |
| 43 | - * @return object | |
| 44 | - */ | |
| 45 | - public function wp_setup_nav_menu_item( $item ) { | |
| 46 | - if ( '#pll_switcher' === $item->url ) { | |
| 47 | - $item->post_title = __( 'Languages', 'polylang' ); | |
| 48 | - $item->type_label = __( 'Language switcher', 'polylang' ); | |
| 49 | - } | |
| 50 | - return $item; | |
| 51 | - } | |
| 52 | - | |
| 53 | - /** | |
| 54 | - * Create temporary nav menu locations ( one per location and per language ) for all non-default language | |
| 28 | + * create temporary nav menu locations ( one per location and per language ) for all non-default language | |
| 55 | 29 | * to do only one time |
| 56 | 30 | * |
| 57 | 31 | * @since 1.2 |
| 58 | 32 | */ |
| @@ -59,10 +33,8 @@ | ||
| 59 | 33 | public function create_nav_menu_locations() { |
| 60 | 34 | static $once; |
| 61 | 35 | global $_wp_registered_nav_menus; |
| 62 | 36 | |
| 63 | - $arr = array(); | |
| 64 | - | |
| 65 | 37 | if ( isset( $_wp_registered_nav_menus ) && ! $once ) { |
| 66 | 38 | foreach ( $_wp_registered_nav_menus as $loc => $name ) { |
| 67 | 39 | foreach ( $this->model->get_languages_list() as $lang ) { |
| 68 | 40 | $arr[ $this->combine_location( $loc, $lang ) ] = $name . ' ' . $lang->name; |
| @@ -74,9 +46,9 @@ | ||
| 74 | 46 | } |
| 75 | 47 | } |
| 76 | 48 | |
| 77 | 49 | /** |
| 78 | - * Creates a temporary nav menu location from a location and a language | |
| 50 | + * creates a temporary nav menu location from a location and a language | |
| 79 | 51 | * |
| 80 | 52 | * @since 1.8 |
| 81 | 53 | * |
| 82 | 54 | * @param string $loc nav menu location |
| @@ -87,9 +59,9 @@ | ||
| 87 | 59 | return $loc . ( strpos( $loc, '___' ) || $this->options['default_lang'] === $lang->slug ? '' : '___' . $lang->slug ); |
| 88 | 60 | } |
| 89 | 61 | |
| 90 | 62 | /** |
| 91 | - * Get nav menu locations and language from a temporary location | |
| 63 | + * get nav menu locations and language from a temporary locaction | |
| 92 | 64 | * |
| 93 | 65 | * @since 1.8 |
| 94 | 66 | * |
| 95 | 67 | * @param string $loc temporary location |
| @@ -102,50 +74,6 @@ | ||
| 102 | 74 | if ( 1 == count( $infos ) ) { |
| 103 | 75 | $infos[] = $this->options['default_lang']; |
| 104 | 76 | } |
| 105 | 77 | return array_combine( array( 'location', 'lang' ), $infos ); |
| 106 | - } | |
| 107 | - | |
| 108 | - /** | |
| 109 | - * Filters the option nav_menu_options for auto added pages to menu | |
| 110 | - * | |
| 111 | - * @since 0.9.4 | |
| 112 | - * | |
| 113 | - * @param array $options | |
| 114 | - * @return array Modified options | |
| 115 | - */ | |
| 116 | - public function nav_menu_options( $options ) { | |
| 117 | - $options['auto_add'] = array_intersect( $options['auto_add'], $this->auto_add_menus ); | |
| 118 | - return $options; | |
| 119 | - } | |
| 120 | - | |
| 121 | - /** | |
| 122 | - * Filters _wp_auto_add_pages_to_menu by language | |
| 123 | - * | |
| 124 | - * @since 0.9.4 | |
| 125 | - * | |
| 126 | - * @param string $new_status Transition to this post status. | |
| 127 | - * @param string $old_status Previous post status. | |
| 128 | - * @param object $post Post data. | |
| 129 | - */ | |
| 130 | - public function auto_add_pages_to_menu( $new_status, $old_status, $post ) { | |
| 131 | - if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type || ! empty( $post->post_parent ) ) { | |
| 132 | - return; | |
| 133 | - } | |
| 134 | - | |
| 135 | - if ( ! empty( $this->options['nav_menus'][ $this->theme ] ) ) { | |
| 136 | - $this->auto_add_menus = array(); | |
| 137 | - | |
| 138 | - $lang = $this->model->post->get_language( $post->ID ); | |
| 139 | - $lang = empty( $lang ) ? $this->options['default_lang'] : $lang->slug; // If the page has no language yet, the default language will be assigned | |
| 140 | - | |
| 141 | - // Get all the menus in the page language | |
| 142 | - foreach ( $this->options['nav_menus'][ $this->theme ] as $loc ) { | |
| 143 | - if ( ! empty( $loc[ $lang ] ) ) { | |
| 144 | - $this->auto_add_menus[] = $loc[ $lang ]; | |
| 145 | - } | |
| 146 | - } | |
| 147 | - | |
| 148 | - add_filter( 'option_nav_menu_options', array( $this, 'nav_menu_options' ) ); | |
| 149 | - } | |
| 150 | 78 | } |
| 151 | 79 | } |