-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
66 lines (58 loc) · 1.66 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Plugin Name: Advanced Custom Fields: Nav Menu
* Plugin URI: https://github.com/joshuafredrickson/acf-nav-menu
* Description: A nav menu field for ACF.
* Version: 1.1.1
* Author: Joshua Fredrickson
* Author URI: https://github.com/joshuafredrickson
*/
namespace Jf\AcfNavMenu;
add_action('plugins_loaded', new class () {
/**
* Setup the plugin.
*
* @return void
*/
public function __invoke()
{
if (file_exists($composer = __DIR__ . '/vendor/autoload.php')) {
require_once $composer;
}
$this->register();
}
/**
* Register the field type with ACF.
*
* @return void
*/
protected function register()
{
foreach (['acf/include_field_types', 'acf/register_fields'] as $hook) {
add_action($hook, function () {
return new NavMenuField(
plugin_dir_url(__FILE__),
plugin_dir_path(__FILE__)
);
});
}
/**
* Add basic Admin Columns Pro support to the nav menu field.
*
* @param mixed $value
* @param int $id
* @param \ACA\ACF\Column $column
* @return mixed
*/
add_filter('ac/column/value', function ($value, $id, $column) {
if (
! is_a($column, '\ACA\ACF\Column') ||
$column->get_type() !== 'nav_menu'
) {
return $value;
}
$nav_menu = wp_get_nav_menu_object(get_field($column->get_meta_key()));
return $nav_menu ? $nav_menu->name : $value;
}, 10, 3);
}
});