-
Notifications
You must be signed in to change notification settings - Fork 1
/
hooks.php
78 lines (67 loc) · 1.76 KB
/
hooks.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
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Register menu items.
*/
add_action( 'admin_menu', function () {
add_management_page(
'Find Junk HTML', // page title
'Find Junk HTML', // menu title
'manage_options', // capability
'fjh', // menu slug
'fjh_page_fjh', // function
null // position
);
});
add_action( 'admin_menu', function () {
add_options_page(
'Find Junk HTML', // page title
'Find Junk HTML', // menu title
'manage_options', // capability
'fjh-options', // menu slug
'fjh_page_options', // function
null // position
);
});
/**
* Add settings link.
*/
add_filter( 'plugin_action_links_'.basename( __DIR__ ).'/find-junk-html.php', function ( $links ) {
$settings_url = admin_url( 'options-general.php?page=fjh-options' );
$links['settings'] = '<a href="'.$settings_url.'">'.__( 'Settings', fjh_textdomain() ).'</a>';
return $links;
});
/**
* Settings, sections and fields.
*/
add_action( 'admin_init', function () {
register_setting(
'fjh_options', // option group
'fjh_options', // option name
[] // args
);
// sections
$section = 'needles';
$page = 'fjh_needles';
add_settings_section(
$section, // section
'', // title
'fjh_needles_cb', // callback
$page // page
);
// fields
add_settings_field(
'fjh_junk', // id
__( 'Junk', fjh_textdomain() ), // title
'fjh_junk_cb', // callback
$page, // page
$section, // section
[] // args
);
});
/**
* Add admin header navigation.
*/
add_action( 'current_screen', function ( $screen ) {
if ( strpos( $screen->id, '_page_fjh' ) !== false )
add_action( 'in_admin_header', 'fjh_nav' );
});