lloc /
MslsMenu
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | Plugin Name: MslsMenu |
||
| 5 | Plugin URI: https://github.com/lloc/MslsMenu |
||
| 6 | Description: Adds the Multisite Language Switcher to the primary-nav-menu |
||
| 7 | Version: 2.1 |
||
| 8 | Author: Dennis Ploetner |
||
| 9 | Author URI: http://lloc.de/ |
||
| 10 | Text Domain: mslsmenu |
||
| 11 | */ |
||
| 12 | |||
| 13 | /* |
||
| 14 | Copyright 2014 Dennis Ploetner (email : [email protected]) |
||
| 15 | |||
| 16 | This program is free software; you can redistribute it and/or modify |
||
| 17 | it under the terms of the GNU General Public License, version 2, as |
||
| 18 | published by the Free Software Foundation. |
||
| 19 | |||
| 20 | This program is distributed in the hope that it will be useful, |
||
| 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 23 | GNU General Public License for more details. |
||
| 24 | |||
| 25 | You should have received a copy of the GNU General Public License |
||
| 26 | along with this program; if not, write to the Free Software |
||
| 27 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
||
| 28 | */ |
||
| 29 | |||
| 30 | /** |
||
| 31 | * MslsMenu Class |
||
| 32 | * @package mslsmenu |
||
| 33 | */ |
||
| 34 | class MslsMenu { |
||
| 35 | |||
| 36 | /** |
||
| 37 | * MslsMenu constructor. |
||
| 38 | */ |
||
| 39 | public function __construct() { |
||
| 40 | load_plugin_textdomain( 'mslsmenu', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Plugin init |
||
| 45 | * |
||
| 46 | * @return MslsMenu |
||
| 47 | */ |
||
| 48 | public static function init() { |
||
| 49 | if ( class_exists( lloc\Msls\MslsOptions::class ) ) { |
||
| 50 | add_filter( 'wp_nav_menu_items', [ MslsMenu::class, 'nav_item' ], 10, 2 ); |
||
| 51 | add_action( 'msls_admin_register', [ MslsMenu::class, 'admin_register' ] ); |
||
| 52 | } |
||
| 53 | |||
| 54 | return new self; |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Callback for wp_nav_menu_items |
||
| 59 | * |
||
| 60 | * @param string $items |
||
| 61 | * @param StdClass $args |
||
| 62 | * |
||
| 63 | * @return string |
||
| 64 | */ |
||
| 65 | function nav_item( $items, $args ) { |
||
| 66 | $options = lloc\Msls\MslsOptions::instance(); |
||
| 67 | $locations = (array) $options->mslsmenu_theme_location; |
||
| 68 | |||
| 69 | if ( in_array( $args->theme_location, $locations ) ) { |
||
| 70 | $mslsmenu = ''; |
||
| 71 | |||
| 72 | $obj = lloc\Msls\MslsOutput::init(); |
||
| 73 | foreach ( $obj->get( (int) $options->mslsmenu_display, false, (int) $options->only_with_translation ) as $item ) { |
||
| 74 | $mslsmenu .= $options->mslsmenu_before_item . $item . $options->mslsmenu_after_item; |
||
| 75 | } |
||
| 76 | |||
| 77 | $items .= $options->mslsmenu_before_output . $mslsmenu . $options->mslsmenu_after_output; |
||
| 78 | } |
||
| 79 | |||
| 80 | return $items; |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Callback for msls_admin_register |
||
| 85 | * |
||
| 86 | * @param string $page |
||
| 87 | */ |
||
| 88 | function admin_register( $page ) { |
||
| 89 | $sid = 'mslsmenu_section'; |
||
| 90 | $label = __( 'Menu Settings', 'mslsmenu' ); |
||
| 91 | add_settings_section( $sid, $label, null, $page ); |
||
| 92 | |||
| 93 | $args = [ 'msls_admin' => lloc\Msls\MslsAdmin::init() ]; |
||
| 94 | |||
| 95 | $label = __( 'Theme Location', 'mslsmenu' ); |
||
| 96 | $callback = [ $this, 'theme_location' ]; |
||
| 97 | add_settings_field( 'mslsmenu_theme_location', $label, $callback, $page, $sid, $args ); |
||
| 98 | |||
| 99 | $label = __( 'Display', 'mslsmenu' ); |
||
| 100 | $callback = [ $this, 'display' ]; |
||
| 101 | add_settings_field( 'mslsmenu_display', $label, $callback, $page, $sid, $args ); |
||
| 102 | |||
| 103 | $fields = [ |
||
| 104 | 'mslsmenu_before_output' => __( 'Text/HTML before the list', 'mslsmenu' ), |
||
| 105 | 'mslsmenu_after_output' => __( 'Text/HTML after the list', 'mslsmenu' ), |
||
| 106 | 'mslsmenu_before_item' => __( 'Text/HTML before each item', 'mslsmenu' ), |
||
| 107 | 'mslsmenu_after_item' => __( 'Text/HTML after each item', 'mslsmenu' ), |
||
| 108 | ]; |
||
| 109 | $callback = [ $this, 'input' ]; |
||
| 110 | foreach ( $fields as $id => $label ) { |
||
| 111 | $args['mslsmenu_input'] = $id; |
||
| 112 | add_settings_field( $id, $label, $callback, $page, $sid, $args ); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Callback for mslsmenu_theme_location |
||
| 118 | * |
||
| 119 | * @param array $args |
||
| 120 | */ |
||
| 121 | function theme_location( $args ) { |
||
|
0 ignored issues
–
show
|
|||
| 122 | $locations = []; |
||
| 123 | foreach ( get_nav_menu_locations() as $key => $value ) { |
||
| 124 | $locations[ $key ] = $key; |
||
| 125 | } |
||
| 126 | |||
| 127 | $selected = (array) lloc\Msls\MslsOptions::instance()->mslsmenu_theme_location; |
||
| 128 | |||
| 129 | $options = [ |
||
| 130 | sprintf( |
||
| 131 | '<option value="" %s>%s</option>', |
||
| 132 | selected( true, ( in_array( '', $selected ) ), false ), |
||
| 133 | __( '-- empty --', 'mslsmenu' ) |
||
| 134 | ) |
||
| 135 | ]; |
||
| 136 | foreach ( $locations as $value => $description ) { |
||
| 137 | $options[] = sprintf( |
||
| 138 | '<option value="%s" %s>%s</option>', |
||
| 139 | $value, |
||
| 140 | selected( true, ( in_array( $value, $selected ) ), false ), |
||
| 141 | $description |
||
| 142 | ); |
||
| 143 | } |
||
| 144 | |||
| 145 | printf( '<select id="%1$s" name="msls[%1$s][]" multiple="multiple">%2$s</select>', 'mslsmenu_theme_location', implode( '', $options ) ); |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Callback for mslsmenu_display |
||
| 150 | * |
||
| 151 | * @param array $args |
||
| 152 | */ |
||
| 153 | function display( $args ) { |
||
| 154 | $types = lloc\Msls\MslsLink::get_types_description(); |
||
| 155 | $display = lloc\Msls\MslsOptions::instance()->mslsmenu_display; |
||
| 156 | |||
| 157 | echo $args['msls_admin']->render_select( 'mslsmenu_display', $types, $display ); |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Callback for mslsmenu text-inputs |
||
| 162 | * |
||
| 163 | * @param array $args |
||
| 164 | */ |
||
| 165 | function input( $args ) { |
||
| 166 | echo $args['msls_admin']->render_input( $args['mslsmenu_input'] ); |
||
| 167 | } |
||
| 168 | |||
| 169 | } |
||
| 170 | |||
| 171 | if ( function_exists( 'add_action' ) ) { |
||
| 172 | add_action( 'plugins_loaded', function () { |
||
| 173 | MslsMenu::init(); |
||
| 174 | } ); |
||
| 175 | } |
||
| 176 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.