PluginProbe
Advanced Custom Fields (ACF®) / 3.1.5
Advanced Custom Fields (ACF®) v3.1.5
6.8.9 6.8.8 6.8.7 6.8.6 6.8.5 6.8.4 6.8.3 6.8.2 6.8.1 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.2 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 All 230 releases
advanced-custom-fields / core / options_page.php
options_page.php
326 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*--------------------------------------------------------------------------
4 *
5 * Acf_options_page
6 *
7 * @author Elliot Condon
8 * @since 2.0.4
9 *
10 *-------------------------------------------------------------------------*/
11
12
13 class Options_page
14 {
15
16 var $parent;
17 var $dir;
18 var $data;
19
20 /*--------------------------------------------------------------------------------------
21 *
22 * Acf_options_page
23 *
24 * @author Elliot Condon
25 * @since 2.0.4
26 *
27 *-------------------------------------------------------------------------------------*/
28
29 function __construct($parent)
30 {
31 // vars
32 $this->parent = $parent;
33 $this->dir = $parent->dir;
34
35 // data for passing variables
36 $this->data = array();
37
38 // actions
39 add_action('admin_menu', array($this,'admin_menu'));
40
41 }
42
43
44 /*--------------------------------------------------------------------------------------
45 *
46 * admin_menu
47 *
48 * @author Elliot Condon
49 * @since 2.0.4
50 *
51 *-------------------------------------------------------------------------------------*/
52
53 function admin_menu()
54 {
55 // validate
56 if(!$this->parent->is_field_unlocked('options_page'))
57 {
58 return true;
59 }
60
61 $parent_slug = 'acf-options';
62 $parent_title = __('Options','acf');
63
64 // set parent slug
65 $custom = apply_filters('acf_register_options_page',array());
66 if(!empty($custom))
67 {
68 $parent_slug = $custom[0]['slug'];
69 $parent_title = $custom[0]['title'];
70 }
71
72
73 // Parent
74 $parent_page = add_menu_page($parent_title, __('Options','acf'), 'edit_posts', $parent_slug, array($this, 'html'));
75
76 // some fields require js + css
77 add_action('admin_print_scripts-'.$parent_page, array($this, 'admin_print_scripts'));
78 add_action('admin_print_styles-'.$parent_page, array($this, 'admin_print_styles'));
79
80 // Add admin head
81 add_action('admin_head-'.$parent_page, array($this,'admin_head'));
82 add_action('admin_footer-'.$parent_page, array($this,'admin_footer'));
83
84 if(!empty($custom))
85 {
86 foreach($custom as $c)
87 {
88 $child_page = add_submenu_page($parent_slug, $c['title'], $c['title'], 'edit_posts', $c['slug'], array($this, 'html'));
89
90 // some fields require js + css
91 add_action('admin_print_scripts-'.$child_page, array($this, 'admin_print_scripts'));
92 add_action('admin_print_styles-'.$child_page, array($this, 'admin_print_styles'));
93
94 // Add admin head
95 add_action('admin_head-'.$child_page, array($this,'admin_head'));
96 add_action('admin_footer-'.$child_page, array($this,'admin_footer'));
97 }
98 }
99
100 }
101
102
103 /*--------------------------------------------------------------------------------------
104 *
105 * admin_init
106 *
107 * @author Elliot Condon
108 * @since 2.0.4
109 *
110 *-------------------------------------------------------------------------------------*/
111
112 function admin_init()
113 {
114
115
116 }
117
118
119
120
121 /*--------------------------------------------------------------------------------------
122 *
123 * admin_head
124 *
125 * @author Elliot Condon
126 * @since 2.0.4
127 *
128 *-------------------------------------------------------------------------------------*/
129
130 function admin_head()
131 {
132
133 // save
134 if(isset($_POST['update_options']))
135 {
136 // post_id = 0 for options page
137 $post_id = 999999999;
138
139 // strip slashes
140 $_POST = array_map('stripslashes_deep', $_POST);
141
142 // save fields
143 $fields = isset($_POST['fields']) ? $_POST['fields'] : false;
144
145 if($fields)
146 {
147 foreach($fields as $key => $value)
148 {
149 // get field
150 $field = $this->parent->get_acf_field($key);
151
152 $this->parent->update_value($post_id, $field, $value);
153 }
154 }
155
156 $this->data['admin_message'] = 'Options Updated';
157
158 }
159
160 $metabox_ids = $this->parent->get_input_metabox_ids(array('post_id' => 999999999), false);
161 /*$style = isset($metabox_ids[0]) ? $this->parent->get_input_style($metabox_ids[0]) : '';
162 echo '<style type="text/css" id="acf_style" >' .$style . '</style>';*/
163
164 if(empty($metabox_ids))
165 {
166 $this->data['no_fields'] = true;
167 return false;
168 }
169
170 // fields admin_head
171 foreach($this->parent->fields as $field)
172 {
173 $this->parent->fields[$field->name]->admin_head();
174 }
175
176
177 // Style
178 echo '<link rel="stylesheet" type="text/css" href="'.$this->parent->dir.'/css/global.css" />';
179 echo '<link rel="stylesheet" type="text/css" href="'.$this->parent->dir.'/css/input.css" />';
180
181 // Javascript
182 echo '<script type="text/javascript" src="'.$this->parent->dir.'/js/input-actions.js" ></script>';
183 echo '<script type="text/javascript">
184 acf.validation_message = "' . __("Validation Failed. One or more fields below are required.",'acf') . '";
185 acf.post_id = 999999999;
186 acf.editor_mode = "tinymce";
187 acf.admin_url = "' . admin_url() . '";
188 </script>';
189
190
191 // get acf's
192 $acfs = $this->parent->get_field_groups();
193 if($acfs)
194 {
195 foreach($acfs as $acf)
196 {
197 // hide / show
198 $show = in_array($acf['id'], $metabox_ids) ? "true" : "false";
199 if($show == "true")
200 {
201 // add meta box
202 add_meta_box(
203 'acf_' . $acf['id'],
204 $acf['title'],
205 array($this->parent, 'meta_box_input'),
206 'acf_options_page',
207 $acf['options']['position'],
208 'high',
209 array( 'fields' => $acf['fields'], 'options' => $acf['options'], 'show' => $show )
210 );
211 }
212 }
213 }
214
215 }
216
217
218 /*--------------------------------------------------------------------------------------
219 *
220 * admin_footer
221 *
222 * @author Elliot Condon
223 * @since 2.0.4
224 *
225 *-------------------------------------------------------------------------------------*/
226 function admin_footer()
227 {
228 //wp_preload_dialogs( array( 'plugins' => 'safari,inlinepopups,spellchecker,paste,wordpress,media,fullscreen,wpeditimage,wpgallery,tabfocus' ) );
229 }
230
231
232 /*---------------------------------------------------------------------------------------------
233 * admin_print_scripts / admin_print_styles
234 *
235 * @author Elliot Condon
236 * @since 2.0.4
237 *
238 ---------------------------------------------------------------------------------------------*/
239 function admin_print_scripts() {
240
241 foreach($this->parent->fields as $field)
242 {
243 $this->parent->fields[$field->name]->admin_print_scripts();
244 }
245
246 }
247
248 function admin_print_styles() {
249
250 foreach($this->parent->fields as $field)
251 {
252 $this->parent->fields[$field->name]->admin_print_styles();
253 }
254
255 }
256
257
258 /*--------------------------------------------------------------------------------------
259 *
260 * options_page
261 *
262 * @author Elliot Condon
263 * @since 2.0.4
264 *
265 *-------------------------------------------------------------------------------------*/
266 function html()
267 {
268 ?>
269 <div class="wrap no_move">
270
271 <div class="icon32" id="icon-options-general"><br></div>
272 <h2><?php echo get_admin_page_title(); ?></h2>
273
274 <?php if(isset($this->data['admin_message'])): ?>
275 <div id="message" class="updated"><p><?php echo $this->data['admin_message']; ?></p></div>
276 <?php endif; ?>
277
278 <?php if(isset($this->data['no_fields'])): ?>
279 <div id="message" class="updated"><p>No Custom Field Group found for the options page. <a href="<?php echo admin_url(); ?>post-new.php?post_type=acf">Create a Custom Field Group</a></p></div>
280 <?php else: ?>
281
282 <form id="post" method="post" name="post">
283 <div class="metabox-holder has-right-sidebar" id="poststuff">
284
285 <!-- Sidebar -->
286 <div class="inner-sidebar" id="side-info-column">
287
288 <!-- Update -->
289 <div class="postbox">
290 <h3 class="hndle"><span><?php _e("Save",'acf'); ?></span></h3>
291 <div class="inside">
292 <input type="hidden" name="HTTP_REFERER" value="<?php echo $_SERVER['HTTP_REFERER'] ?>" />
293 <input type="submit" class="button-primary" value="Save Options" name="update_options" />
294 </div>
295 </div>
296
297 </div>
298
299 <!-- Main -->
300 <div id="post-body">
301 <div id="post-body-content">
302 <?php $meta_boxes = do_meta_boxes('acf_options_page', 'normal', null); ?>
303 <script type="text/javascript">
304 (function($){
305
306 $('#poststuff .postbox[id*="acf_"]').addClass('acf_postbox');
307
308 })(jQuery);
309 </script>
310 </div>
311 </div>
312
313 </div>
314 </form>
315
316 <?php endif; ?>
317
318 </div>
319
320 <?php
321
322 }
323
324 }
325
326 ?>