@@ -67,9 +67,11 @@ public function admin_init() {
67
67
} // end if
68
68
69
69
$ post_types = $ this ->supported_post_types ();
70
+ $ options = get_option ( $ this ->plugin_slug );
70
71
71
72
foreach ( $ post_types as $ pt ) {
72
73
$ post_object = get_post_type_object ( $ pt );
74
+ $ args = array ( $ pt , $ options [$ pt ] );
73
75
74
76
add_settings_section (
75
77
$ pt ,
@@ -84,7 +86,7 @@ public function admin_init() {
84
86
array ( $ this , 'title_callback ' ),
85
87
$ this ->plugin_slug ,
86
88
$ pt ,
87
- array ( $ pt )
89
+ $ args
88
90
);
89
91
90
92
add_settings_field (
@@ -93,7 +95,7 @@ public function admin_init() {
93
95
array ( $ this , 'instruction_callback ' ),
94
96
$ this ->plugin_slug ,
95
97
$ pt ,
96
- array ( $ pt )
98
+ $ args
97
99
);
98
100
99
101
add_settings_field (
@@ -102,7 +104,7 @@ public function admin_init() {
102
104
array ( $ this , 'link_text_callback ' ),
103
105
$ this ->plugin_slug ,
104
106
$ pt ,
105
- array ( $ pt )
107
+ $ args
106
108
);
107
109
108
110
add_settings_field (
@@ -111,13 +113,14 @@ public function admin_init() {
111
113
array ( $ this , 'button_text_callback ' ),
112
114
$ this ->plugin_slug ,
113
115
$ pt ,
114
- array ( $ pt )
116
+ $ args
115
117
);
116
118
}
117
119
118
120
register_setting (
119
121
$ this ->plugin_slug ,
120
- $ this ->plugin_slug
122
+ $ this ->plugin_slug ,
123
+ array ( $ this , 'validate_inputs ' )
121
124
);
122
125
123
126
} // end admin_init
@@ -170,8 +173,7 @@ public function supported_post_types() {
170
173
171
174
public function title_callback ( $ args ) {
172
175
173
- $ options = get_option ( $ this ->plugin_slug );
174
- $ value = isset ( $ options ['title ' ] ) ? $ options ['title ' ] : '' ;
176
+ $ value = isset ( $ args [1 ]['title ' ] ) ? $ args [1 ]['title ' ] : '' ;
175
177
176
178
$ html = '<input type"text" id="title" name=" ' . $ this ->plugin_slug . '[ ' . $ args [0 ] . '][title]" value=" ' . $ value . '" class="regular-text" /> ' ;
177
179
$ html .= '<p class="description"> ' . __ ( 'Enter your custom title for Featured Image Metabox. ' , $ this ->plugin_slug ) . '</p> ' ;
@@ -182,8 +184,7 @@ public function title_callback( $args ) {
182
184
183
185
public function instruction_callback ( $ args ) {
184
186
185
- $ options = get_option ( $ this ->plugin_slug );
186
- $ value = isset ( $ options ['instruction ' ] ) ? $ options ['instruction ' ] : '' ;
187
+ $ value = isset ( $ args [1 ]['instruction ' ] ) ? $ args [1 ]['instruction ' ] : '' ;
187
188
188
189
$ html = '<input type"text" id="instruction" name=" ' . $ this ->plugin_slug . '[ ' . $ args [0 ] . '][instruction]" value=" ' . $ value . '" class="regular-text" /> ' ;
189
190
$ html .= '<p class="description"> ' . __ ( 'Enter the instruction for Featured Image, like image dimensions. ' , $ this ->plugin_slug ) . '</p> ' ;
@@ -194,8 +195,7 @@ public function instruction_callback( $args ) {
194
195
195
196
public function link_text_callback ( $ args ) {
196
197
197
- $ options = get_option ( $ this ->plugin_slug );
198
- $ value = isset ( $ options ['link_text ' ] ) ? $ options ['link_text ' ] : '' ;
198
+ $ value = isset ( $ args [1 ]['link_text ' ] ) ? $ args [1 ]['link_text ' ] : '' ;
199
199
200
200
$ html = '<input type"text" id="link_text" name=" ' . $ this ->plugin_slug . '[ ' . $ args [0 ] . '][link_text]" value=" ' . $ value . '" class="regular-text" /> ' ;
201
201
$ html .= '<p class="description"> ' . sprintf ( __ ( 'Enter the custom link text to replace the "%s". ' , $ this ->plugin_slug ), __ ( 'Set featured image ' ) ) . '</p> ' ;
@@ -206,15 +206,40 @@ public function link_text_callback( $args ) {
206
206
207
207
public function button_text_callback ( $ args ) {
208
208
209
- $ options = get_option ( $ this ->plugin_slug );
210
- $ value = isset ( $ options ['button_text ' ] ) ? $ options ['button_text ' ] : '' ;
209
+ $ value = isset ( $ args [1 ]['button_text ' ] ) ? $ args [1 ]['button_text ' ] : '' ;
211
210
212
211
$ html = '<input type"text" id="button_text" name=" ' . $ this ->plugin_slug . '[ ' . $ args [0 ] . '][button_text]" value=" ' . $ value . '" class="regular-text" /> ' ;
213
212
$ html .= '<p class="description"> ' . sprintf ( __ ( 'Enter the custom button text to replace the "%s". ' , $ this ->plugin_slug ), __ ( 'Set featured image ' ) ) . '</p> ' ;
214
213
215
214
echo $ html ;
216
215
217
216
} // end button_text_callback
217
+
218
+ /**
219
+ * Validate inputs
220
+ *
221
+ * @return array Sanitized data
222
+ *
223
+ * @since 0.7.0
224
+ */
225
+ public function validate_inputs ( $ inputs ) {
226
+
227
+ $ outputs = array ();
228
+
229
+ foreach ( $ inputs as $ key => $ value ) {
230
+ if ( is_array ( $ value ) ) {
231
+ foreach ( $ value as $ k => $ v ) {
232
+ $ outputs [$ key ][$ k ] = sanitize_text_field ( $ v );
233
+ }
234
+ } else {
235
+ $ outputs [$ key ] = sanitize_text_field ( $ value );
236
+ }
237
+
238
+ }
239
+
240
+ return apply_filters ( 'cfim_validate_inputs ' , $ outputs , $ inputs );
241
+
242
+ } // end validate_inputs
218
243
}
219
244
220
245
Custom_Featured_Image_Metabox_Settings::get_instance ();
0 commit comments