-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.php
More file actions
148 lines (105 loc) · 3.66 KB
/
Copy pathoptions.php
File metadata and controls
148 lines (105 loc) · 3.66 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
add_action( 'admin_menu', 'apm_add_admin_menu' );
add_action( 'admin_init', 'apm_settings_init' );
function apm_add_admin_menu( ) {
add_options_page( __('Automatic Post Media', 'automatic-post-media'), __('Automatic Post Media', 'automatic-post-media'), 'manage_options', '_automatic_post_media', 'apm_options_page' );
}
function apm_settings_init( ) {
register_setting( 'apmPluginPage', 'apm_settings' );
add_settings_section(
'apm_apmPluginPage_section',
__( 'Change Automatic Post Options', 'automatic-post-media' ),
'apm_settings_section_callback',
'apmPluginPage'
);
add_settings_field(
'apm_select_author',
__( 'Choose Author', 'automatic-post-media' ),
'apm_select_author_render',
'apmPluginPage',
'apm_apmPluginPage_section'
);
add_settings_field(
'apm_select_category',
__( 'Choose Category', 'automatic-post-media' ),
'apm_select_category_render',
'apmPluginPage',
'apm_apmPluginPage_section'
);
add_settings_field(
'apm_select_title',
__( 'Choose Title Style', 'automatic-post-media' ),
'apm_select_title_render',
'apmPluginPage',
'apm_apmPluginPage_section'
);
add_settings_field(
'apm_textarea_content',
__( 'Automatic Post Content', 'automatic-post-media' ),
'apm_textarea_content_render',
'apmPluginPage',
'apm_apmPluginPage_section'
);
}
function apm_select_author_render( ) {
$options = (array) get_option( 'apm_settings' );
$authors = get_users( array( 'fields' => array( 'display_name','id' ) ) )
?>
<select name='apm_settings[apm_select_author]'>
<?php foreach($authors as $user){
?>
<option value='<?php echo $user->id;?>' <?php selected( $options['apm_select_author'] ?? '', $user->id ); ?>><?php echo $user->display_name ?></option>
<?php
}?>
</select>
<?php
}
function apm_select_title_render( ) {
$options = (array) get_option( 'apm_settings' );
?>
<select name='apm_settings[apm_select_title]'>
<option value='1' <?php selected( $options['apm_select_title'] ?? '', 1 ); ?>>[EXT]FILENAME</option>
<option value='2' <?php selected( $options['apm_select_title'] ?? '', 2 ); ?>>FILENAME.EXT</option>
<option value='3' <?php selected( $options['apm_select_title'] ?? '', 2 ); ?>>FILENAME</option>
</select>
<?php
}
function apm_select_category_render( ) {
$categories = get_categories( array('hide_empty'=> 0));
$options = (array) get_option( 'apm_settings' );
?>
<select name='apm_settings[apm_select_category]'>
<?php
foreach ($categories as $category) {
?>
<option value='<?php echo $category->term_id;?>' <?php selected( $options['apm_select_category'] ?? '', $category->term_id); ?>><?php echo $category->name;?></option>
<?php
}?>
</select>
<?php
}
function apm_textarea_content_render( ) {
$options = (array) get_option( 'apm_settings' );
if (empty($options['apm_textarea_content'])){
$options['apm_textarea_content'] = "<a href='[url]'>[name]</a>";
}
?>
<textarea cols='40' rows='5' name='apm_settings[apm_textarea_content]'><?php echo esc_textarea($options['apm_textarea_content']); ?></textarea>
<p><code>[url]</code>文件的下载链接</br><code>[name]</code>文件名</p>
<?php
}
function apm_settings_section_callback( ) {
echo __( 'Automatic Post Media Can Post Media into Post', 'automatic-post-media' );
}
function apm_options_page( ) {
?>
<form action='options.php' method='post'>
<h2><?php echo __('Automatic Post Media','automatic-post-media')?></h2>
<?php
settings_fields( 'apmPluginPage' );
do_settings_sections( 'apmPluginPage' );
submit_button();
?>
</form>
<?php
}