PluginProbe
Faust.js / 0.7.1
Faust.js v0.7.1
1.8.12 1.8.11 1.4.1 1.8.0 1.8.8 1.8.9 trunk 0.7.0 0.7.1 0.7.10 0.7.11 0.7.3 0.7.4 0.7.5 0.7.6 0.7.7 0.7.8 0.7.9 0.8.0 0.8.1 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 All 40 releases
faustwp / includes / menus / callbacks.php

callbacks.php in Faust.js 0.7.1, at includes/menus/callbacks.php

52 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Resets menu locations to those from Settings → Headless → Menu Locations.
4 *
5 * @package FaustWP
6 */
7
8 namespace WPE\FaustWP\Menus;
9
10 use function WPE\FaustWP\Settings\faustwp_get_setting;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 add_action( 'after_setup_theme', __NAMESPACE__ . '\\remove_menu_locations', 100 );
17 /**
18 * Callback for WordPress 'after_setup_theme' action.
19 *
20 * Unregisters menu locations such as those provided by the active PHP theme.
21 */
22 function remove_menu_locations() {
23 $menus = array_keys( get_registered_nav_menus() );
24
25 array_walk( $menus, 'unregister_nav_menu' );
26 }
27
28 add_action( 'after_setup_theme', __NAMESPACE__ . '\\register_menu_locations', 101 );
29 /**
30 * Callback for WordPress 'after_setup_theme' action.
31 *
32 * Registers menus specified at Settings → Headless → Menu Locations.
33 */
34 function register_menu_locations() {
35 $location_setting = faustwp_get_setting( 'menu_locations', 'Primary, Footer' );
36 $locations = explode( ',', $location_setting );
37 $menus = array();
38
39 foreach ( $locations as $location ) {
40 $location = trim( $location );
41 $key = sanitize_title_with_dashes( $location );
42
43 if ( $key ) {
44 $menus[ $key ] = $location;
45 }
46 }
47
48 if ( $menus ) {
49 register_nav_menus( $menus );
50 }
51 }
52