PluginProbe
Advanced Custom Fields: Extended / 0.9.2.4
Advanced Custom Fields: Extended v0.9.2.4
0.9.2.7 0.9.2.6 0.9.2.5 0.8.6 0.8.6.1 0.8.6.3 0.8.6.5 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.8 0.8.8.1 0.8.8.10 0.8.8.11 0.8.8.2 0.8.8.3 0.8.8.4 All 92 releases
acf-extended / includes / admin / admin.php
admin.php
297 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if(!defined('ABSPATH')){
4 exit;
5 }
6
7 if(!class_exists('acfe_admin')):
8
9 class acfe_admin{
10
11 /**
12 * construct
13 */
14 function __construct(){
15
16 // acf-updates & acf-tools pages
17 add_action('admin_menu', array($this, 'admin_menu'));
18
19 // acf-field-groups (ACF 6.0)
20 add_action('acfe/load_posts/post_type=acf-field-group', array($this, 'load_posts'));
21 add_action('acfe/load_post/post_type=acf-field-group', array($this, 'load_post'));
22
23 // acf-post-type (ACF 6.1)
24 add_action('acfe/load_posts/post_type=acf-post-type', array($this, 'load_posts'));
25 add_action('acfe/load_post/post_type=acf-post-type', array($this, 'load_post'));
26
27 // acf-taxonomy (ACF 6.1)
28 add_action('acfe/load_posts/post_type=acf-taxonomy', array($this, 'load_posts'));
29 add_action('acfe/load_post/post_type=acf-taxonomy', array($this, 'load_post'));
30
31 // acf-ui-options-page (ACF 6.2)
32 add_action('acfe/load_posts/post_type=acf-ui-options-page', array($this, 'load_posts'));
33 add_action('acfe/load_post/post_type=acf-ui-options-page', array($this, 'load_post'));
34
35 // additional hooks
36 add_action('current_screen', array($this, 'current_screen'));
37 add_filter('acf/validate_field', array($this, 'validate_field'));
38
39 // re-add sidebar submitdiv metabox
40 acfe_replace_action('load-post.php', array('ACF_Form_Post', 'initialize'), array($this, 'acf_load_post'));
41 acfe_replace_action('load-post-new.php', array('ACF_Form_Post', 'initialize'), array($this, 'acf_load_post'));
42
43 }
44
45
46 /**
47 * admin_menu
48 */
49 function admin_menu(){
50
51 // get pages
52 $updates = get_plugin_page_hookname('acf-settings-updates', 'edit.php?post_type=acf-field-group');
53 $tools = get_plugin_page_hookname('acf-tools', 'edit.php?post_type=acf-field-group');
54
55 // actions
56 add_action("load-{$updates}", array($this, 'load_acf_page'));
57 add_action("load-{$tools}", array($this, 'load_acf_page'));
58
59 }
60
61
62 /**
63 * load_acf_page
64 */
65 function load_acf_page(){
66 add_filter('admin_body_class', array($this, 'admin_body_class'));
67 }
68
69
70 /**
71 * load_posts
72 */
73 function load_posts(){
74 add_filter('admin_body_class', array($this, 'admin_body_class'));
75 }
76
77
78 /**
79 * load_post
80 */
81 function load_post(){
82 add_filter('admin_body_class', array($this, 'admin_body_class'));
83 add_action('acf/input/admin_head', array($this, 'admin_head'), 20);
84 }
85
86
87 /**
88 * acf_load_post
89 *
90 * Rewrites the ACF_Form_Post initialize which remove the submitdiv metabox
91 *
92 * advanced-custom-fields-pro/includes/forms/form-post.php:48
93 */
94 function acf_load_post(){
95
96 // globals
97 global $typenow;
98
99 // restrict specific post types
100 $restricted = array('acf-field-group', 'acf-post-type', 'acf-taxonomy', 'acf-ui-options-page', 'attachment');
101 if(in_array($typenow, $restricted)){
102 return;
103 }
104
105 // enqueue scripts
106 acf_enqueue_scripts(array(
107 'uploader' => true,
108 ));
109
110 // actions
111 add_action('add_meta_boxes', array(acf_get_instance('ACF_Form_Post'), 'add_meta_boxes'), 10, 2);
112
113 }
114
115
116 /**
117 * admin_body_class
118 *
119 * Adds acf-admin-6 class to body
120 */
121 function admin_body_class($classes){
122
123 // filter
124 $new_class = apply_filters('acfe/acf_admin_body_class', 'acf-admin-6');
125
126 // append class
127 if(!empty($new_class)){
128 $classes .= ' ' . $new_class;
129 }
130
131 // return
132 return $classes;
133 }
134
135
136 /**
137 * admin_head
138 *
139 */
140 function admin_head(){
141
142 // remove forced 1 column on 'screen_layout' options
143 acfe_remove_filter('get_user_option_screen_layout_acf-field-group', array('acf_admin_field_group', 'screen_layout'));
144 acfe_remove_filter('get_user_option_screen_layout_acf-post-type', array('ACF_Admin_Post_type', 'screen_layout'));
145 acfe_remove_filter('get_user_option_screen_layout_acf-taxonomy', array('ACF_Admin_Taxonomy', 'screen_layout'));
146 acfe_remove_filter('get_user_option_screen_layout_acf-ui-options-page', array('ACF_Admin_UI_Options_Page', 'screen_layout'));
147
148 // base url
149 $default_icon = acf_get_url('assets/images/icons/icon-fields.svg');
150
151 // generate default field type missing icon
152 ?>
153 <style>
154 .field-type-icon:before{
155 -webkit-mask-image: url(<?php echo $default_icon; ?>);
156 mask-image: url(<?php echo $default_icon; ?>);
157 }
158 </style>
159 <?php
160
161 }
162
163
164 /**
165 * current_screen
166 *
167 * Remove ACF Title header bar on ACFE modules
168 *
169 * @param $screen
170 */
171 function current_screen($screen){
172
173 // allowed screens
174 $allowed = array(
175 'edit-acf-field-group-category',
176 'edit-acfe-dbt',
177 'acfe-dbt',
178 'edit-acfe-template',
179 'acfe-template',
180 'edit-acfe-form',
181 'acfe-form'
182 );
183
184 // check screen
185 if(acfe_maybe_get($screen, 'post_type') === 'acf-field-group' || acf_is_screen($allowed)){
186
187 // add top menu icons
188 add_action('admin_head', array($this, 'admin_head_navigation'));
189
190 // remove the topbar "white banner" with the page title
191 if(acf_is_screen($allowed)){
192 global $acf_page_title;
193 $acf_page_title = '';
194 }
195
196 }
197
198 // acf 6.1 removed topbar for third party submenu
199 // checking $screen[post_type] to avoid adding the global navigation twice (throws: Cannot redeclare acf_print_menu_section())
200 // this fix an issue when visiting custom admin url like: edit-tags.php?taxonomy=acf-field-group-category&post_type=acf-field-group
201 if(acf_is_screen($allowed) && acfe_maybe_get($screen, 'post_type') !== 'acf-field-group'){
202 add_action('in_admin_header', array($this, 'in_admin_header'));
203 }
204
205 }
206
207
208 /**
209 * in_admin_header
210 *
211 * @return void
212 */
213 function in_admin_header(){
214
215 // safeguard: bail early in case global navigation is already loaded
216 if(function_exists('acf_print_menu_section')){
217 return;
218 }
219
220 // load view
221 acf_get_view(apply_filters('acfe/acf_admin_navigation_page', 'global/navigation'));
222
223 }
224
225
226 /**
227 * admin_head_navigation
228 *
229 * ACF >= 6.0 && <= 6.1 Add ACF admin head navigation icons to ACFE modules
230 * Starting ACF 6.1, ACF add custom submenus into a "More" menu, which doesn't show icons anymore
231 */
232 function admin_head_navigation(){
233
234 // base url
235 $base_url = acf_get_url('assets/images/');
236
237 // pages rules
238 $pages = array(
239 'categories' => 'field-type-icons/icon-field-taxonomy.svg',
240 'edit-tagsphptaxonomyacf-field-group-category' => 'field-type-icons/icon-field-taxonomy.svg',
241 'block-types' => 'icons/icon-fields.svg',
242 'acfe-dbt' => 'icons/icon-fields.svg',
243 'forms' => 'field-type-icons/icon-field-post-object.svg',
244 'acfe-form' => 'field-type-icons/icon-field-post-object.svg',
245 'options-pages' => 'field-type-icons/icon-field-group.svg',
246 'acfe-dop' => 'field-type-icons/icon-field-group.svg',
247 'settings' => 'icons/icon-settings.svg',
248 'acfe-settings' => 'icons/icon-settings.svg',
249 'templates' => 'field-type-icons/icon-field-wysiwyg.svg',
250 'acfe-template' => 'field-type-icons/icon-field-wysiwyg.svg',
251 );
252
253 // generate css
254 ?>
255 <style>
256 <?php foreach($pages as $page => $icon): ?>
257 .acf-admin-toolbar .acf-header-tab-<?php echo $page; ?> i.acf-icon{
258 display: inline-flex;
259 -webkit-mask-image: url(<?php echo $base_url . $icon; ?>);
260 mask-image: url(<?php echo $base_url . $icon; ?>);
261 }
262 <?php endforeach; ?>
263
264 .acf-icon.acf-icon-plus{
265 -webkit-mask-image: url(<?php echo $base_url; ?>icons/icon-add.svg);
266 mask-image: url(<?php echo $base_url; ?>icons/icon-add.svg);
267 }
268 </style>
269 <?php
270
271 }
272
273 /**
274 * validate_field
275 *
276 * Change instructions to hint for appended field settings
277 *
278 * @param $field
279 *
280 * @return mixed
281 */
282 function validate_field($field){
283
284 if(acf_maybe_get($field, '_appended') && acf_maybe_get($field, 'instructions')){
285 $field['hint'] = $field['instructions'];
286 $field['instructions'] = '';
287 }
288
289 return $field;
290
291 }
292
293 }
294
295 acf_new_instance('acfe_admin');
296
297 endif;