@@ -66,44 +66,54 @@ public function admin_init() {
66
66
add_option ( $ this ->plugin_slug , $ this ->default_settings () );
67
67
} // end if
68
68
69
- add_settings_section (
70
- 'general ' ,
71
- __ ( 'General ' , $ this ->plugin_slug ),
72
- '' ,
73
- $ this ->plugin_slug
74
- );
75
-
76
- add_settings_field (
77
- 'title ' ,
78
- __ ( 'Title Text ' , $ this ->plugin_slug ),
79
- array ( $ this , 'title_callback ' ),
80
- $ this ->plugin_slug ,
81
- 'general '
82
- );
83
-
84
- add_settings_field (
85
- 'instruction ' ,
86
- __ ( 'Instruction ' , $ this ->plugin_slug ),
87
- array ( $ this , 'instruction_callback ' ),
88
- $ this ->plugin_slug ,
89
- 'general '
90
- );
91
-
92
- add_settings_field (
93
- 'link_text ' ,
94
- __ ( 'Link Text ' , $ this ->plugin_slug ),
95
- array ( $ this , 'link_text_callback ' ),
96
- $ this ->plugin_slug ,
97
- 'general '
98
- );
99
-
100
- add_settings_field (
101
- 'button_text ' ,
102
- __ ( 'Button Text ' , $ this ->plugin_slug ),
103
- array ( $ this , 'button_text_callback ' ),
104
- $ this ->plugin_slug ,
105
- 'general '
106
- );
69
+ $ post_types = $ this ->supported_post_types ();
70
+
71
+ foreach ( $ post_types as $ pt ) {
72
+ $ post_object = get_post_type_object ( $ pt );
73
+
74
+ add_settings_section (
75
+ $ pt ,
76
+ sprintf ( __ ( 'Featured Image Metabox in %s ' , $ this ->plugin_slug ), $ post_object ->labels ->name ),
77
+ '' ,
78
+ $ this ->plugin_slug
79
+ );
80
+
81
+ add_settings_field (
82
+ 'title ' ,
83
+ __ ( 'Title Text ' , $ this ->plugin_slug ),
84
+ array ( $ this , 'title_callback ' ),
85
+ $ this ->plugin_slug ,
86
+ $ pt ,
87
+ array ( $ pt )
88
+ );
89
+
90
+ add_settings_field (
91
+ 'instruction ' ,
92
+ __ ( 'Instruction ' , $ this ->plugin_slug ),
93
+ array ( $ this , 'instruction_callback ' ),
94
+ $ this ->plugin_slug ,
95
+ $ pt ,
96
+ array ( $ pt )
97
+ );
98
+
99
+ add_settings_field (
100
+ 'link_text ' ,
101
+ __ ( 'Link Text ' , $ this ->plugin_slug ),
102
+ array ( $ this , 'link_text_callback ' ),
103
+ $ this ->plugin_slug ,
104
+ $ pt ,
105
+ array ( $ pt )
106
+ );
107
+
108
+ add_settings_field (
109
+ 'button_text ' ,
110
+ __ ( 'Button Text ' , $ this ->plugin_slug ),
111
+ array ( $ this , 'button_text_callback ' ),
112
+ $ this ->plugin_slug ,
113
+ $ pt ,
114
+ array ( $ pt )
115
+ );
116
+ }
107
117
108
118
register_setting (
109
119
$ this ->plugin_slug ,
@@ -119,59 +129,87 @@ public function admin_init() {
119
129
*/
120
130
public function default_settings () {
121
131
122
- $ defaults = array (
123
- 'title ' => 'Post Featured Image ' ,
124
- 'instruction ' => '' ,
125
- 'link_text ' => '' ,
126
- 'button_text ' => '' ,
127
- );
132
+ $ post_types = $ this ->supported_post_types ();
133
+ $ keys = array (
134
+ 'title ' => '' ,
135
+ 'instruction ' => '' ,
136
+ 'link_text ' => '' ,
137
+ 'button_text ' => '' ,
138
+ );
139
+ $ defaults = array ();
140
+
141
+ foreach ( $ post_types as $ pt ) {
142
+ $ defaults [$ pt ] = $ keys ;
143
+ }
128
144
129
- return apply_filters ( 'default_settings ' , $ defaults );
145
+ return apply_filters ( 'cfim_default_settings ' , $ defaults );
130
146
131
147
} // end default_settings
132
148
133
- public function title_callback () {
149
+ /**
150
+ * Get post types with thumbnail support
151
+ *
152
+ * @return array supported post types
153
+ *
154
+ * @since 0.6.0
155
+ */
156
+ public function supported_post_types () {
157
+
158
+ $ post_types = get_post_types ();
159
+ $ results = array ();
160
+
161
+ foreach ( $ post_types as $ pt ) {
162
+ if ( post_type_supports ( $ pt , 'thumbnail ' ) ) {
163
+ $ results [] = $ pt ;
164
+ }
165
+ }
166
+
167
+ return $ results ;
168
+
169
+ } // end supported_post_types
170
+
171
+ public function title_callback ( $ args ) {
134
172
135
173
$ options = get_option ( $ this ->plugin_slug );
136
174
$ value = isset ( $ options ['title ' ] ) ? $ options ['title ' ] : '' ;
137
175
138
- $ html = '<input type"text" id="title" name=" ' . $ this ->plugin_slug . '[title]" value=" ' . $ value . '" class="regular-text" /> ' ;
176
+ $ html = '<input type"text" id="title" name=" ' . $ this ->plugin_slug . '[ ' . $ args [ 0 ] . ' ][ title]" value=" ' . $ value . '" class="regular-text" /> ' ;
139
177
$ html .= '<p class="description"> ' . __ ( 'Enter your custom title for Featured Image Metabox. ' , $ this ->plugin_slug ) . '</p> ' ;
140
178
141
179
echo $ html ;
142
180
143
181
} // end title_callback
144
182
145
- public function instruction_callback () {
183
+ public function instruction_callback ( $ args ) {
146
184
147
185
$ options = get_option ( $ this ->plugin_slug );
148
186
$ value = isset ( $ options ['instruction ' ] ) ? $ options ['instruction ' ] : '' ;
149
187
150
- $ html = '<input type"text" id="instruction" name=" ' . $ this ->plugin_slug . '[instruction]" value=" ' . $ value . '" class="regular-text" /> ' ;
151
- $ html .= '<p class="description"> ' . __ ( 'Enter the instruction for Featured Image, like the image dimensions. ' , $ this ->plugin_slug ) . '</p> ' ;
188
+ $ html = '<input type"text" id="instruction" name=" ' . $ this ->plugin_slug . '[ ' . $ args [ 0 ] . ' ][ instruction]" value=" ' . $ value . '" class="regular-text" /> ' ;
189
+ $ html .= '<p class="description"> ' . __ ( 'Enter the instruction for Featured Image, like image dimensions. ' , $ this ->plugin_slug ) . '</p> ' ;
152
190
153
191
echo $ html ;
154
192
155
193
} // end instruction_callback
156
194
157
- public function link_text_callback () {
195
+ public function link_text_callback ( $ args ) {
158
196
159
197
$ options = get_option ( $ this ->plugin_slug );
160
198
$ value = isset ( $ options ['link_text ' ] ) ? $ options ['link_text ' ] : '' ;
161
199
162
- $ html = '<input type"text" id="link_text" name=" ' . $ this ->plugin_slug . '[link_text]" value=" ' . $ value . '" class="regular-text" /> ' ;
200
+ $ html = '<input type"text" id="link_text" name=" ' . $ this ->plugin_slug . '[ ' . $ args [ 0 ] . ' ][ link_text]" value=" ' . $ value . '" class="regular-text" /> ' ;
163
201
$ html .= '<p class="description"> ' . sprintf ( __ ( 'Enter the custom link text to replace the "%s". ' , $ this ->plugin_slug ), __ ( 'Set featured image ' ) ) . '</p> ' ;
164
202
165
203
echo $ html ;
166
204
167
205
} // end link_text_callback
168
206
169
- public function button_text_callback () {
207
+ public function button_text_callback ( $ args ) {
170
208
171
209
$ options = get_option ( $ this ->plugin_slug );
172
210
$ value = isset ( $ options ['button_text ' ] ) ? $ options ['button_text ' ] : '' ;
173
211
174
- $ html = '<input type"text" id="button_text" name=" ' . $ this ->plugin_slug . '[button_text]" value=" ' . $ value . '" class="regular-text" /> ' ;
212
+ $ html = '<input type"text" id="button_text" name=" ' . $ this ->plugin_slug . '[ ' . $ args [ 0 ] . ' ][ button_text]" value=" ' . $ value . '" class="regular-text" /> ' ;
175
213
$ html .= '<p class="description"> ' . sprintf ( __ ( 'Enter the custom button text to replace the "%s". ' , $ this ->plugin_slug ), __ ( 'Set featured image ' ) ) . '</p> ' ;
176
214
177
215
echo $ html ;
0 commit comments