-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlostfound_options.php
More file actions
121 lines (95 loc) · 3.05 KB
/
Copy pathlostfound_options.php
File metadata and controls
121 lines (95 loc) · 3.05 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
add_action( 'admin_menu', 'lostfound_add_admin_menu' );
add_action( 'admin_init', 'lostfound_settings_init' );
function lostfound_add_admin_menu() {
$parent_slug = 'edit.php?post_type=lostfound';
$page_title = 'Lost and Found Pets - Settings';
$menu_title = 'Settings';
$capability = 'edit_pages';
$menu_slug = 'lostfound-settings';
$function = 'lostfound_options_page';
add_submenu_page(
$parent_slug,
$page_title,
$menu_title,
$capability,
$menu_slug,
$function
);
}
function lostfound_settings_init() {
register_setting( 'lostfound_settings_group', 'lostfound_settings' );
add_settings_section(
'lostfound_settings_group_section',
__( 'Settings', 'lostfound' ),
'lostfound_settings_section_callback',
'lostfound_settings_group'
);
add_settings_field(
'notifications_email',
__( 'Notification Email', 'lostfound' ),
'notifications_email_render',
'lostfound_settings_group',
'lostfound_settings_group_section'
);
add_settings_field(
'new_post_status',
__( 'New Post Status', 'lostfound' ),
'new_post_status_render',
'lostfound_settings_group',
'lostfound_settings_group_section'
);
add_settings_field(
'submit_redirect_url',
__( 'Redirect URL', 'lostfound' ),
'submit_redirect_url_render',
'lostfound_settings_group',
'lostfound_settings_group_section'
);
}
function notifications_email_render() {
$option = get_option( 'lostfound_settings' )['notifications_email'];
?>
<input type="email" name="lostfound_settings[notifications_email]" value="<?php echo $option; ?>" required>
<?php
}
function new_post_status_render() {
$option = get_option( 'lostfound_settings' )['new_post_status'];
?>
<select name='lostfound_settings[new_post_status]' required>
<option value="publish" <?php selected( $option, 'publish' ); ?>>Published</option>
<option value="pending" <?php selected( $option, 'pending' ); ?>>Pending</option>
</select>
<?php
}
function submit_redirect_url_render() {
$option = get_option( 'lostfound_settings' )['submit_redirect_url'];
?>
<input type="text" name="lostfound_settings[submit_redirect_url]" value="<?php echo $option; ?>" required>
<?php
}
function lostfound_settings_section_callback() {
?>
<p>Set the Notification Email setting to the email address that will receive new submission notifications. Default: admin email</p>
<p>The new post status determines whether new posts are published automatically or wait for admin approval. Default: Pending</p>
<p>The Redirect URL section determines the URL which the user is redirected to after submitting a new post</p>
<?php
}
function lostfound_options_page() {
?>
<div class="container">
<h1>Lost and Found</h1>
<form action="options.php" method="post">
<div class="settings">
<?php
settings_fields( 'lostfound_settings_group' );
do_settings_sections( 'lostfound_settings_group' );
?>
</div>
<div class="save">
<?php submit_button(); ?>
</div>
</form>
</div>
<?php
}