| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
die('-1'); |
| 5 |
} |
| 6 |
|
| 7 |
class Quadmenu_Locations { |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
|
| 11 |
$this->locations(); |
| 12 |
|
| 13 |
$this->dev(); |
| 14 |
|
| 15 |
add_action('init', array($this, 'active'), -10); |
| 16 |
|
| 17 |
add_action('admin_init', array($this, 'save'), 999); |
| 18 |
} |
| 19 |
|
| 20 |
function dev() { |
| 21 |
|
| 22 |
register_nav_menus(array( |
| 23 |
'quadmenu_dev' => 'QuadMenu Dev', |
| 24 |
)); |
| 25 |
|
| 26 |
unset($GLOBALS['quadmenu_locations']['quadmenu_dev']); |
| 27 |
} |
| 28 |
|
| 29 |
function locations() { |
| 30 |
|
| 31 |
global $quadmenu_locations; |
| 32 |
|
| 33 |
$quadmenu_locations = get_option(QUADMENU_LOCATIONS, array()); |
| 34 |
} |
| 35 |
|
| 36 |
function active() { |
| 37 |
|
| 38 |
global $quadmenu, $quadmenu_locations, $quadmenu_active_locations; |
| 39 |
|
| 40 |
$quadmenu_active_locations = array('quadmenu_dev' => true); |
| 41 |
|
| 42 |
if (!empty($quadmenu) && is_array($quadmenu_locations) && count($quadmenu_locations)) { |
| 43 |
|
| 44 |
foreach ($quadmenu_locations as $id => $location) { |
| 45 |
if (!empty($quadmenu[$id . '_integration']) && !empty($quadmenu[$id . '_theme'])) { |
| 46 |
$quadmenu_active_locations[$id] = $quadmenu[$id . '_theme']; |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
public function save() { |
| 53 |
|
| 54 |
global $_wp_registered_nav_menus, $quadmenu, $quadmenu_locations; |
| 55 |
|
| 56 |
if (!empty($quadmenu) && is_array($_wp_registered_nav_menus) && count($_wp_registered_nav_menus)) { |
| 57 |
|
| 58 |
$quadmenu_locations = array(); |
| 59 |
|
| 60 |
foreach ($_wp_registered_nav_menus as $location => $name) { |
| 61 |
|
| 62 |
$quadmenu_locations[$location] = array( |
| 63 |
'name' => $name |
| 64 |
); |
| 65 |
} |
| 66 |
|
| 67 |
update_option(QUADMENU_LOCATIONS, $quadmenu_locations); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
new Quadmenu_Locations(); |
| 74 |
|