My Custom Header Content
'; 116 | return $content; 117 | } 118 | ``` 119 | 120 | **Footer Content** 121 | 122 | ``` 123 | add_filter('acf-options-page-adder/page-footer', 'my_custom_options_page_footer', 10, 2); 124 | 125 | function my_custom_options_page_footer($content, $hook) { 126 | // $content = content, by default it is '' or the value of the WYSIWYG editor 127 | // $hook = the current options page hook that is being called 128 | $content = 'My Custom Footer Content
'; 129 | return $content; 130 | } 131 | ``` 132 | 133 | **Filter Entire Options Page** 134 | 135 | ``` 136 | add_filter('acf-options-page-adder/page-content', 'my_custom_options_page_filter', 10, 2); 137 | 138 | function my_custom_options_page_filter($content, $hook) { 139 | // $content = entire content or options page, including all ACF fields 140 | // $hook = the current options page hook that is being called 141 | // caution should be taken when making modification to the page content 142 | return $content; 143 | } 144 | ``` 145 | 146 | ### Donations 147 | If you find my work useful and you have a desire to send me money, which will give me an incentive to continue 148 | offering and maintaining the plugins I've made public in my many repositories, I'm not going to turn it down 149 | and whatever you feel my work is worth will be greatly appreciated. You can send money through paypal to 150 | hube02[AT]earthlink[dot]net. 151 | 152 | #### Automatic Updates 153 | Github updater support has been removed. This plugin has been published to WordPress.Org here 154 | https://wordpress.org/plugins/options-page-admin-for-acf/. If you are having problems updating please 155 | try installing from there. 156 | 157 | #### Remove Nag 158 | You may notice that I've started adding a little nag to my plugins. It's just a box on some pages that lists my 159 | plugins that you're using with a request do consider making a donation for using them. If you want to disable them 160 | add the following filter to your functions.php file. 161 | ``` 162 | add_filter('remove_hube2_nag', '__return_true'); 163 | ``` 164 | -------------------------------------------------------------------------------- /lang/acf-options-page-adder-ru_RU.po: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2014 2 | # This file is distributed under the same license as the package. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: ACF Options Page Adder\n" 6 | "Report-Msgid-Bugs-To: Translator NameMy Custom Header Content
'; 129 | return $content; 130 | } 131 | ` 132 | 133 | **Footer Content** 134 | 135 | ` 136 | add_filter('acf-options-page-adder/page-footer', 'my_custom_options_page_footer', 10, 2); 137 | 138 | function my_custom_options_page_footer($content, $hook) { 139 | // $content = content, by default it is '' or the value of the WYSIWYG editor 140 | // $hook = the current options page hook that is being called 141 | $content = 'My Custom Footer Content
'; 142 | return $content; 143 | } 144 | ` 145 | 146 | **Filter Entire Options Page** 147 | 148 | ` 149 | add_filter('acf-options-page-adder/page-content', 'my_custom_options_page_filter', 10, 2); 150 | 151 | function my_custom_options_page_filter($content, $hook) { 152 | // $content = entire content or options page, including all ACF fields 153 | // $hook = the current options page hook that is being called 154 | // caution should be taken when making modification to the page content 155 | return $content; 156 | } 157 | ` 158 | 159 | == Remove Nag == 160 | 161 | If you would like to remove my little nag that appears on some admin pages add the following to your functions.php file 162 | ` 163 | add_filter('remove_hube2_nag', '__return_true'); 164 | ` 165 | 166 | 167 | == Changelog == 168 | 169 | = 3.10.0 = 170 | * added GraphQL schema support 171 | 172 | = 3.9.6 = 173 | * disable all functionality if acf options page functions do not exist 174 | 175 | = 3.9.5 = 176 | * moved acf/include_fields to __construct due to change is ACF timing 177 | 178 | = 3.9.4 = 179 | * removed bug introduced in 3.9.3 (post id shown) 180 | 181 | = 3.9.3 = 182 | * corrected bugs in options page custimizations 183 | 184 | = 3.9.2 = 185 | * recommit of 3.9.1 because it didn't take for some reason 186 | 187 | = 3.9.1 = 188 | * corrected bug/error when installed and not acf options pages active 189 | 190 | = 3.9.0 = 191 | * adjusted post type to ensure disabling glutenberg 192 | * removed donation nag 193 | * added slug options for saving fields to custom slugs 194 | 195 | = 3.8.9 = 196 | * Fixed bug in setting parent options page 197 | * Corrected display of were fields will be saved 198 | * Corrected all translation calls to not use variable for text domain 199 | * Corrected bug in get_option_page_id() for redirected parent pages 200 | * Minor text changes 201 | 202 | = 3.8.8 = 203 | * Increased init priority to prevent interferance with some poorly written plugins that alter queries without proper checking to make sure the query is for the correct post type. 204 | 205 | = 3.8.7 = 206 | * Removed admin/ajax check added in last update. Change in ACF caused options pages not to appear when generated by AJAX. 207 | 208 | = 3.8.6 = 209 | * corrected issue where options page query done on init can interfere with operation of other plugins. Disable option page setup when on front end and when doing ajax as this setup is not needed here. Removing this query at these times should also improve site performance. 210 | 211 | = 3.8.5 = 212 | * removed ACF from disallowed parent parent menus 213 | 214 | = 3.8.4 = 215 | * translation updates 216 | 217 | = 3.8.3 = 218 | * correcting some minor issues/erros introduced in 3.8.2 219 | 220 | = 3.8.2 = 221 | * added toggle to turn customize features on/off 222 | 223 | = 3.8.1 = 224 | * corrected bug in menu position 225 | * corrected bug in hook setting 226 | 227 | = 3.8.0 = 228 | * replaced register_field_group() call with acf_add_local_field_group() - #41 229 | * added tabs for basic/advanced settings 230 | * added page content customization options + new filters - #40 231 | * added performance optimization - #42 232 | * added internal correction for attaching files - #39 233 | * minor modifications 234 | 235 | = 3.7.5 = 236 | * more updates to Russian translation [@antonvyukov](https://wordpress.org/support/users/antonvyukov/) 237 | 238 | = 3.7.4 = 239 | * updated Russian translation [@antonvyukov](https://wordpress.org/support/users/antonvyukov/) 240 | 241 | = 3.7.3 = 242 | * added more missing text domains 243 | * completed adding Portuguese (pt_PT) translation 244 | * converted True/False radio fields to ACF true/false UI fields 245 | * added Russian (ru_RU) translations - thanks [@antonvyukov](https://wordpress.org/support/users/antonvyukov/) 246 | 247 | = 3.7.2 = 248 | * Added missing text domain 249 | * Typos corrected 250 | * Add Portuguese (pt_PT) translation - thanks [@pedro-mendonca](https://wordpress.org/support/users/pedromendonca) 251 | 252 | = 3.7.1 = 253 | * removed github updater support 254 | 255 | = 3.7.0 = 256 | * Added support for Font Awesome icons [See Other Notes](https://wordpress.org/plugins/options-page-admin-for-acf/other_notes/) 257 | 258 | = 3.6.1 = 259 | * First release to wordpress.org 260 | 261 | = 3.6.0 = 262 | * Added filter to use page tiles instead of menu title for location setting when editing ACF field group 263 | * Corrected some bugs 264 | * Removed fieldset duplicator 265 | 266 | = 3.5.3 = 267 | * correction to when filter is added to prevent multiple additions of filter 268 | 269 | = 3.5.2 = 270 | * ? 271 | 272 | = 3.5.1 = 273 | * fixed bug, titles being removed from all other post types 274 | 275 | = 3.5.0 = 276 | * Changed default redirect value to false 277 | * Added admin column for "Save To" 278 | * Added function get_option_page_id() and get_options_page_id() 279 | 280 | = 3.4.0 = 281 | * removed post title 282 | * added required title field 283 | * slug field now required 284 | * added validation to slug field 285 | * removed no longer needed message field about post title 286 | * updated instructions and messages for several fields 287 | 288 | = 3.3.0 = 289 | * changed capability to "manage_options" 290 | * added filter to allow changing of capability 291 | 292 | = 3.2.1 = 293 | * corrected conditional logic on slug field 294 | 295 | = 3.2.0 = 296 | * added remove nag filter 297 | 298 | = 3.1.6 = 299 | * corrected white-space error 300 | 301 | = 3.1.5 = 302 | * added donation box 303 | 304 | = 3.1.4 = 305 | * added support for github updater 306 | 307 | = 3.1.3 == 308 | * Removed comment from field group duplicator 309 | 310 | = 3.1.2 = 311 | * Corrects Issue #17 312 | 313 | = 3.1.1 = 314 | * Added checks to ensure that ACF5 Pro is installed and active 315 | 316 | = 3.1.0 = 317 | * Corrected bug, duplicated field groups not showing on options pages 318 | * Added support for save/loading to/from post objects added in ACF v5.2.7 319 | 320 | = 3.0.0 = 321 | * Added support for autoload option added in ACF v5.2.8 322 | 323 | = 2.2.0 = 324 | * Added field group duplicator 325 | 326 | = 2.1.0 = 327 | * Added support for redirect 328 | * Added support for menu position 329 | * Added support for icon (dashicons) 330 | * Added sorting of sub options pages 331 | 332 | = 2.0.0 = 333 | * Corrected bug in adding top level option page 334 | * Corrected bug in display of location 335 | * Corrected bug in options page slugs not being saved correctly 336 | * Removed support for ACF4 337 | * Changed default value of location to "None" 338 | 339 | = 1.1.1 = 340 | * Removed $post global in function admin_columns_content(), not needed, post_id is passed by hook. 341 | * Added code to prevent plugin from running if not included by WP. 342 | * Reworked function acf_add_options_sub_page() to not use have_posts() function so it's less likely to interfere with other queries. 343 | * Other minor code changes that don't effect operation 344 | 345 | = 1.1.0 = 346 | * Updated to be compatable with ACF-Pro (continues to work on ACF4) 347 | 348 | = 1.0.0 = 349 | * Initial Stable Version 350 | 351 | = 0.0.1 = 352 | * initial release 353 | 354 | == Upgrade Notice == 355 | -------------------------------------------------------------------------------- /options-pages.php: -------------------------------------------------------------------------------- 1 | post_type || 57 | !isset($this->options_pages[$id])) { 58 | return $allcaps; 59 | } 60 | remove_filter('user_has_cap', array($this, 'attach_files'), 10); 61 | 62 | $page = $this->options_pages[$id]; 63 | $cap = $page['acf']['capability']; 64 | if (current_user_can($cap)) { 65 | // add all $caps to $allcaps 66 | foreach ($caps as $add) { 67 | $allcaps[$add] = true; 68 | } 69 | } 70 | add_filter('user_has_cap', array($this, 'attach_files'), 10, 4); 71 | return $allcaps; 72 | } // end public function attach_files 73 | 74 | public function script() { 75 | $handle = 'acf-options-page-adder'; 76 | $src = plugin_dir_url(__FILE__).'options-pages.js'; 77 | $deps = array('jquery'); 78 | $ver = $this->version; 79 | $in_footer = false; 80 | wp_enqueue_script($handle, $src, $deps, $ver, $in_footer); 81 | } // end public function script 82 | 83 | public function options_page_rule_values_titles($choices) { 84 | if (!apply_filters('acf-options-page-adder/choice_titles', true)) { 85 | return $choices; 86 | } 87 | $pages = acf_get_options_pages(); 88 | if (!$pages) { 89 | return $choices; 90 | } 91 | foreach ($pages as $page) { 92 | $choices[$page['menu_slug']] = $page['page_title']; 93 | } 94 | return $choices; 95 | } // end public function options_page_rule_values_titles 96 | 97 | public function set_page_slug_field($value, $post_id, $field) { 98 | if (!empty($value)) { 99 | return $value; 100 | } 101 | // options page was created before the title field was added 102 | $slug = strtolower(trim(preg_replace('/[^a-z0-9]+/i', '-', get_the_title($post_id)), '-')); 103 | if ($slug != 'auto-draft') { 104 | $value = $slug; 105 | } 106 | return $value; 107 | } // end public function set_page_slug_field 108 | 109 | public function slug_characters($valid, $value, $post_id, $field) { 110 | // only allow leters, number, underscores, dashes 111 | if (!$valid) { 112 | return $valid; 113 | } 114 | if (!preg_match('/^[a-z]/i', $value) || preg_match('/[^-_0-9a-z]/i', $value)) { 115 | return $field['label'].' '.__('must begin with a letter and include only numbers, letters, underscores and hyphens', 'acf-options-page-adder'); 116 | } 117 | return $valid; 118 | } // end public function slug_characters 119 | 120 | public function unique_value($valid, $value, $field, $input) { 121 | // must be unique 122 | if (!$valid || (!isset($_POST['post_id']) && !isset($_POST['post_ID']))) { 123 | return $valid; 124 | } 125 | if (isset($_POST['post_id'])) { 126 | $post_id = intval($_POST['post_id']); 127 | } else { 128 | $post_id = intval($_POST['post_ID']); 129 | } 130 | if (!$post_id) { 131 | return $valid; 132 | } 133 | $post_type = get_post_type($post_id); 134 | $field_name = $field['name']; 135 | $args = array( 136 | 'post_type' => $post_type, 137 | 'post_status' => 'publish, draft, trash', 138 | 'post__not_in' => array($post_id), 139 | 'meta_query' => array( 140 | array( 141 | 'key' => $field_name, 142 | 'value' => $value 143 | ) 144 | ) 145 | ); 146 | $query = new WP_Query($args); 147 | if (count($query->posts)){ 148 | return __('This Value is not Unique. Please enter a unique', 'acf-options-page-adder').' '.$field['label']; 149 | } 150 | return $valid; 151 | } // end public function unique_value 152 | 153 | public function set_title_field($value, $post_id, $field) { 154 | if (!empty($value)) { 155 | return $value; 156 | } 157 | // options page was created before the title field was added 158 | $title = get_the_title(intval($post_id)); 159 | if ($title != 'Auto Draft') { 160 | $value = $title; 161 | } 162 | return $value; 163 | } // end public function set_title_field 164 | 165 | public function after_setup_theme() { 166 | if (!function_exists('acf_add_options_page')) { 167 | return; 168 | } 169 | // check to see if acf5 is installed 170 | // if not then do not run anything else in this plugin 171 | // move all other actions to this function except text domain since this is too late 172 | /* 173 | if (!class_exists('acf') || 174 | !function_exists('acf_get_setting') || 175 | intval(acf_get_setting('version')) < 5 || 176 | !class_exists('acf_pro')) { 177 | $this->active = false; 178 | return; 179 | } 180 | */ 181 | add_action('admin_menu', array($this, 'build_admin_menu_list'), 9999); 182 | //add_action('admin_menu', array($this, 'add_hooks'), 9999); // makes sure everything has been added 183 | add_filter('acf/load_field/name=_acfop_parent', array($this, 'acf_load_parent_menu_field')); 184 | add_filter('acf/load_field/name=_acfop_capability', array($this, 'acf_load_capabilities_field')); 185 | add_filter('manage_edit-'.$this->post_type.'_columns', array($this, 'admin_columns')); 186 | add_action('manage_'.$this->post_type.'_posts_custom_column', array($this, 'admin_columns_content'), 10, 2); 187 | require_once(dirname(__FILE__).'/api-template.php'); 188 | } // end public function after_setup_theme 189 | 190 | public function init() { 191 | if (!function_exists('acf_add_options_page')) { 192 | return; 193 | } 194 | $this->register_post_type(); 195 | $this->acf_add_options_pages(); 196 | do_action('acf_options_page/init'); 197 | } // end public function init 198 | 199 | public function acf_include_fields() { 200 | if (!function_exists('acf_add_options_page')) { 201 | return; 202 | } 203 | // this function is called when ACF5 is installed 204 | $field_group = array( 205 | 'key' => 'acf_options-page-details', 206 | 'title' => __('Options Page Details', 'acf-options-page-adder'), 207 | 'fields' => array( 208 | array( 209 | 'key' => 'field_acf_key_acfop_tab_basic', 210 | 'label' => __('Basic Settings', 'acf-options-page-adder'), 211 | 'name' => '', 212 | 'type' => 'tab', 213 | 'instructions' => '', 214 | 'required' => 0, 215 | 'conditional_logic' => 0, 216 | 'wrapper' => array( 217 | 'width' => '', 218 | 'class' => '', 219 | 'id' => '' 220 | ), 221 | 'placement' => 'left', 222 | 'endpoint' => 0 223 | ), 224 | array( 225 | 'key' => 'field_acf_key_acfop_title', 226 | 'label' => __('Title Text', 'acf-options-page-adder'), 227 | 'name' => '_acfop_title', 228 | 'prefix' => '', 229 | 'type' => 'text', 230 | 'instructions' => __('This will be used as the options page title.', 'acf-options-page-adder'), 231 | 'required' => 1, 232 | 'conditional_logic' => 0, 233 | 'default_value' => '', 234 | 'placeholder' => '', 235 | 'prepend' => '', 236 | 'append' => '', 237 | 'maxlength' => '', 238 | 'readonly' => 0, 239 | 'disabled' => 0 240 | ), 241 | array( 242 | 'key' => 'field_acf_key_acfop_menu', 243 | 'label' => __('Menu Text', 'acf-options-page-adder'), 244 | 'name' => '_acfop_menu', 245 | 'prefix' => '', 246 | 'type' => 'text', 247 | 'instructions' => __('Will default to title if left blank.', 'acf-options-page-adder'), 248 | 'required' => 0, 249 | 'conditional_logic' => 0, 250 | 'default_value' => '', 251 | 'placeholder' => '', 252 | 'prepend' => '', 253 | 'append' => '', 254 | 'maxlength' => '', 255 | 'readonly' => 0, 256 | 'disabled' => 0 257 | ), 258 | array( 259 | 'key' => 'field_acf_key_acfop_parent', 260 | 'label' => __('Menu Location (Parent)', 'acf-options-page-adder'), 261 | 'name' => '_acfop_parent', 262 | 'prefix' => '', 263 | 'type' => 'select', 264 | 'instructions' => __('Select the menu this options page will appear under. Will default to None.', 'acf-options-page-adder'), 265 | 'required' => 0, 266 | 'conditional_logic' => 0, 267 | 'choices' => array(), // dynamic populate 268 | 'default_value' => 'none', 269 | 'allow_null' => 0, 270 | 'multiple' => 0, 271 | 'ui' => 0, 272 | 'ajax' => 0, 273 | 'placeholder' => '', 274 | 'disabled' => 0, 275 | 'readonly' => 0 276 | ), 277 | array( 278 | 'key' => 'field_acf_key_acfop_slug', 279 | 'label' => __('Slug', 'acf-options-page-adder'), 280 | 'name' => '_acfop_slug', 281 | 'prefix' => '', 282 | 'type' => 'text', 283 | 'instructions' => __('This field is optional in ACF. It is required here. You must know what the slug is to enable get_options_page_post_id() added in 4.4.0', 'acf-options-page-adder'), 284 | 'required' => 1, 285 | 'conditional_logic' => 0, 286 | 'default_value' => '', 287 | 'placeholder' => '', 288 | 'prepend' => '', 289 | 'append' => '', 290 | 'maxlength' => '', 291 | 'readonly' => 0, 292 | 'disabled' => 0 293 | ), 294 | array( 295 | 'key' => 'field_acf_key_acfop_order', 296 | 'label' => __('Order', 'acf-options-page-adder'), 297 | 'name' => '_acfop_order', 298 | 'prefix' => '', 299 | 'type' => 'number', 300 | 'instructions' => __('The order that this child menu should appear under its parent menu.', 'acf-options-page-adder'), 301 | 'required' => 0, 302 | 'conditional_logic' => array( 303 | array( 304 | array( 305 | 'field' => 'field_acf_key_acfop_parent', 306 | 'operator' => '!=', 307 | 'value' => 'none', 308 | ), 309 | ), 310 | ), 311 | 'default_value' => 0, 312 | 'placeholder' => '', 313 | 'prepend' => '', 314 | 'append' => '', 315 | 'maxlength' => '', 316 | 'readonly' => 0, 317 | 'disabled' => 0, 318 | ), 319 | array( 320 | 'key' => 'field_acf_key_acfop_show_in_graphql', 321 | 'label' => __('Show in GraphQL', 'acf-options-page-adder'), 322 | 'name' => '_acfop_show_in_graphql', 323 | 'prefix' => '', 324 | 'type' => 'true_false', 325 | 'instructions' => '', 326 | 'required' => 0, 327 | 'conditional_logic' => 0, 328 | 'wrapper' => array( 329 | 'width' => '', 330 | 'class' => '', 331 | 'id' => '', 332 | ), 333 | 'show_in_graphql' => 1, 334 | 'message' => '', 335 | 'default_value' => 0, 336 | 'ui' => 1, 337 | 'ui_on_text' => '', 338 | 'ui_off_text' => '', 339 | ), 340 | array( 341 | 'key' => 'field_acf_key_acfop_tab_advanced', 342 | 'label' => __('Advanced Settings', 'acf-options-page-adder'), 343 | 'name' => '', 344 | 'type' => 'tab', 345 | 'instructions' => '', 346 | 'required' => 0, 347 | 'conditional_logic' => 0, 348 | 'wrapper' => array( 349 | 'width' => '', 350 | 'class' => '', 351 | 'id' => '' 352 | ), 353 | 'placement' => 'left', 354 | 'endpoint' => 0 355 | ), 356 | array( 357 | 'key' => 'field_acf_key_acfop_capability', 358 | 'label' => __('Capability', 'acf-options-page-adder'), 359 | 'name' => '_acfop_capability', 360 | 'prefix' => '', 361 | 'type' => 'select', 362 | 'instructions' => __('The user capability to view this options page. Will default to manage_options.', 'acf-options-page-adder'), 363 | 'required' => 0, 364 | 'conditional_logic' => 0, 365 | 'choices' => array(), // dynamic populate 366 | 'default_value' => 'manage_options', 367 | 'allow_null' => 1, 368 | 'multiple' => 0, 369 | 'ui' => 0, 370 | 'ajax' => 0, 371 | 'placeholder' => '', 372 | 'disabled' => 0, 373 | 'readonly' => 0 374 | ), 375 | array( 376 | 'key' => 'field_acf_key_acfop_position', 377 | 'label' => __('Menu Position', 'acf-options-page-adder'), 378 | 'name' => '_acfop_position', 379 | 'prefix' => '', 380 | 'type' => 'text', 381 | 'instructions' => __('The position in the menu order this menu should appear. WARNING: if two menu items use the same position attribute, one of the items may be overwritten so that only one item displays! Risk of conflict can be reduced by using decimal instead of integer values, e.g. 63.3 instead of 63. Defaults to bottom of utility menu items.'; print_r($this->options_pages); die;
793 | foreach($this->options_pages as $id => $options_page) {
794 | if (isset($options_page['customize']) && !$options_page['customize']) {
795 | continue;
796 | }
797 | //echo get_plugin_page_hookname($options_page['acf']['menu_slug'], $options_page['acf']['parent_slug']);
798 | //echo ''; print_r($options_page); die;
799 | if (isset($options_page['hook'])) {
800 | $hook = $options_page['hook'];
801 | } else {
802 | $hook = get_plugin_page_hookname($options_page['acf']['menu_slug'], $options_page['acf']['parent_slug']);
803 | $this->options_pages[$id]['hook'] = $hook;
804 | }
805 | add_action($hook, array($this, 'customize_start'), 1);
806 | add_action($hook, array($this, 'customize_end'), 20);
807 | $this->hooks[$hook] = $id;
808 | }
809 | } // end public function add_hooks
810 |
811 | public function customize_start() {
812 | //echo 'here'; die;
813 | ob_start();
814 | } // end public function customize_start
815 |
816 | public function customize_end() {
817 |
818 | $replaces = 1;
819 |
820 | $content = ob_get_clean();
821 |
822 |
823 |
824 | $hook = current_filter();
825 |
826 | $options_page = $this->options_pages[$this->hooks[$hook]];
827 | //echo $this->hooks[$hook];
828 |
829 | $header = '';
830 | if (!$options_page['header']) {
831 | $header = trim(get_post_meta($this->hooks[$hook], '_acfop_header_content', true));
832 | } else {
833 | $header = apply_filters('acf_the_content', $options_page['header']);
834 | }
835 | $header = apply_filters('acf-options-page-adder/page-header', $header, $hook);
836 | if ($header) {
837 | $content = str_replace('', ''.$header, $content, $replaces);
838 | }
839 |
840 | $footer = '';
841 | if (!$options_page['footer']) {
842 | $footer = trim(get_post_meta($this->hooks[$hook], '_acfop_footer_content', true));
843 | } else {
844 | $footer = apply_filters('acf_the_content', $options_page['footer']);
845 | }
846 | $footer = apply_filters('acf-options-page-adder/page-footer', $footer, $hook);
847 | if ($footer) {
848 | $content = str_replace('', ''.$footer, $content, $replaces);
849 | }
850 |
851 | $content = apply_filters('acf-options-page-adder/page-content', $content, $hook);
852 |
853 | echo $content;
854 | } // end public function customize_end
855 |
856 | public function acf_save_post($post_id) {
857 | if (!is_numeric($post_id)) {
858 | return;
859 | }
860 | // post types that need titles set
861 | $post_type = get_post_type($post_id);
862 | if ($this->post_type != $post_type) {
863 | return;
864 | }
865 |
866 | remove_action('acf/save_post', array($this, 'acf_save_post'), 20);
867 |
868 | // set post title based on title field
869 | $title = get_post_meta($post_id, '_acfop_title', true);
870 | // strip all html
871 | $title = preg_replace('#?\w+[^>]*>#s', '', $title);
872 | $slug = sanitize_title($title);
873 | $args = array(
874 | 'ID' => $post_id,
875 | 'post_title' => $title,
876 | 'post_name' => $slug,
877 | 'post_content' => serialize($this->build_options_page_settings($post_id, $title))
878 | );
879 | wp_update_post($args);
880 | add_action('acf/save_post', array($this, 'acf_save_post'), 20);
881 |
882 | // remove header/footer content if customize is turned off
883 | $customize = intval(get_post_meta($post_id, '_acfop_customize', true));
884 | if (!$customize) {
885 | update_post_meta($post_id, '_acfop_header_content', '');
886 | update_post_meta($post_id, '_acfop_footer_content', '');
887 | }
888 |
889 | } // end public function acf_save_post
890 |
891 | public function acf_load_parent_menu_field($field) {
892 | //$this->build_admin_menu_list();
893 | $field['choices'] = $this->parent_menus;
894 | return $field;
895 | } // end public function acf_load_parent_menu_field
896 |
897 | public function acf_load_capabilities_field($field) {
898 | global $wp_roles;
899 | if (!$wp_roles || !count($wp_roles->roles)) {
900 | return $field;
901 | }
902 | $sorted_caps = array();
903 | $caps = array();
904 | foreach ($wp_roles->roles as $role) {
905 | foreach ($role['capabilities'] as $cap => $value) {
906 | if (!in_array($cap, $sorted_caps)) {
907 | $sorted_caps[] = $cap;
908 | }
909 | } // end foreach cap
910 | } // end foreach role
911 | sort($sorted_caps);
912 | foreach ($sorted_caps as $cap) {
913 | $caps[$cap] = $cap;
914 | } // end foreach sorted_caps
915 | $field['choices'] = $caps;
916 | return $field;
917 | } // end public function
918 |
919 | public function admin_columns($columns) {
920 | $new_columns = array();
921 | foreach ($columns as $index => $column) {
922 | if ($index == 'title') {
923 | $new_columns[$index] = $column;
924 | $new_columns['acfop_id'] = __('Post ID', 'acf-options-page-adder');
925 | $new_columns['acfop_menu_text'] = __('Menu Text', 'acf-options-page-adder');
926 | $new_columns['acfop_slug'] = __('Slug', 'acf-options-page-adder');
927 | $new_columns['acfop_location'] = __('Location (Parent)', 'acf-options-page-adder');
928 | $new_columns['acfop_redirect'] = __('Redirect', 'acf-options-page-adder');
929 | $new_columns['acfop_saveto'] = __('Save To', 'acf-options-page-adder');
930 | $new_columns['acfop_order'] = __('Order', 'acf-options-page-adder');
931 | $new_columns['acfop_capability'] = __('Capability', 'acf-options-page-adder');
932 | $new_columns['acfop_hook'] = __('Hook Suffix', 'acf-options-page-adder');
933 | } else {
934 | if (strtolower($column) != 'date') {
935 | $new_columns[$index] = $column;
936 | }
937 | }
938 | }
939 | return $new_columns;
940 | } // end public function admin_columns
941 |
942 | public function admin_columns_content($column_name, $post_id) {
943 | switch ($column_name) {
944 | case 'acfop_saveto':
945 | $save_to = get_post_meta($post_id, '_acfop_save_to', true);
946 | if ($save_to == 'options') {
947 | $redirect = intval(get_post_meta($post_id, '_acfop_redirect', true));
948 | $parent = get_post_meta($post_id, '_acfop_parent', true);
949 | if ($parent == 'none' && $redirect) {
950 | $save_to = '';
951 | }
952 | }
953 | $redirect = intval(get_post_meta($post_id, '_acfop_redirect', true));
954 | if ($redirect) {
955 | echo __('1st sub options page value
OR
', 'acf-options-page-adder');
956 | }
957 | if ($save_to == 'options') {
958 | echo __('Options', 'acf-options-page-adder');
959 | } elseif ($save_to == 'post') {
960 | echo __('Post', 'acf-options-page-adder'),' ',get_post_meta($post_id, '_acfop_post_page', true);
961 | } elseif ($save_to == 'this_post') {
962 | echo __('This Post', 'acf-options-page-adder'),' (',$post_id,')';
963 | } elseif ($save_to == 'page_slug') {
964 | $value = trim(get_post_meta($post_id, '_acfop_slug', true));
965 | if (!$value) {
966 | $value = trim(get_the_title($post_id));
967 | $value = strtolower(trim(preg_replace('/[^a-z0-9]+/i', '-', $value), '-'));
968 | }
969 | echo $value;
970 | } elseif ($save_to == 'custom_slug') {
971 | echo trim(get_post_meta($post_id, '_acfop_custom_slug', true));
972 | } else {
973 | $slug = trim(get_post_meta($post_id, '_acfop_slug', true));
974 | if (!$slug) {
975 | $slug = trim(get_the_title($post_id));
976 | $slug = strtolower(trim(preg_replace('/[^a-z0-9]+/i', '-', $value), '-'));
977 | }
978 | $save_to = get_options_page_id($slug);
979 | //echo __('1st sub option page value
OR
', 'acf-options-page-adder');
980 | if ($save_to == 'options') {
981 | echo __('Options', 'acf-options-page-adder');
982 | } elseif ($save_to == $post_id) {
983 | echo __('This Post', 'acf-options-page-adder'),' (',$post_id,')';
984 | } else {
985 | echo __('Post', 'acf-options-page-adder'),' ',$save_to;
986 | }
987 | }
988 | break;
989 | case 'acfop_id':
990 | echo $post_id;
991 | break;
992 | case 'acfop_menu_text':
993 | $value = trim(get_post_meta($post_id, '_acfop_menu', true));
994 | if (!$value) {
995 | $value = trim(get_the_title($post_id));
996 | }
997 | echo $value;
998 | break;
999 | case 'acfop_hook':
1000 | $slug = trim(get_post_meta($post_id, '_acfop_slug', true));
1001 | $parent = get_post_meta($post_id, '_acfop_parent', true);
1002 | $value = get_plugin_page_hookname($slug, $parent);
1003 | echo $value;
1004 | break;
1005 | case 'acfop_slug':
1006 | $value = trim(get_post_meta($post_id, '_acfop_slug', true));
1007 | if (!$value) {
1008 | $value = trim(get_the_title($post_id));
1009 | $value = strtolower(trim(preg_replace('/[^a-z0-9]+/i', '-', $value), '-'));
1010 | }
1011 | echo $value;
1012 | break;
1013 | case 'acfop_location':
1014 | $value = get_post_meta($post_id, '_acfop_parent', true);
1015 | if (isset($this->parent_menus[$value])) {
1016 | echo $this->parent_menus[$value];
1017 | } else {
1018 | global $acf_options_pages;
1019 | if (count($acf_options_pages)) {
1020 | foreach ($acf_options_pages as $key => $options_page) {
1021 | if ($key == $value) {
1022 | echo $options_page['menu_title'];
1023 | } // end if key == value
1024 | } // end foreach acf_options_page
1025 | } // end if cout acf_options_pages
1026 | } // end if esl
1027 | break;
1028 | case 'acfop_capability':
1029 | $value = get_post_meta($post_id, '_acfop_capability', true);
1030 | echo $value;
1031 | //the_field('_acfop_capability', $post_id);
1032 | break;
1033 | case 'acfop_order':
1034 | $value = get_post_meta($post_id, '_acfop_order', true);
1035 | if ($value != '') {
1036 | echo $value;
1037 | }
1038 | break;
1039 | case 'acfop_redirect':
1040 | $value = get_post_meta($post_id, '_acfop_redirect', true);
1041 | if ($value == 1) {
1042 | echo __('Yes', 'acf-options-page-adder');
1043 | } elseif ($value == 0 && $value != '') {
1044 | echo __('No', 'acf-options-page-adder');
1045 | }
1046 | break;
1047 | default:
1048 | // do nothing
1049 | break;
1050 | } // end switch
1051 | } // end public function admin_columns_content
1052 |
1053 | public function build_admin_menu_list() {
1054 | global $menu;
1055 | $parent_menus = array('none' => __('None', 'acf-options-page-adder'));
1056 | $this->exclude_locations = apply_filters('acf-options-page-adder/exlude-locations', $this->exclude_locations);
1057 | $options_pages = acf_get_options_pages();
1058 | if (isset($GLOBALS['acf_options_pages'])) {
1059 | $options_pages = $GLOBALS['acf_options_pages'];
1060 | }
1061 | if (!count($menu)) {
1062 | // bail early
1063 | $this->parent_menus = $parent_menus;
1064 | return;
1065 | }
1066 | foreach ($menu as $index => $item) {
1067 | if (isset($item[0]) && $item[0] != '' &&
1068 | isset($item[2]) && !in_array($item[2], $this->exclude_locations)) {
1069 | if ($item[2] == 'edit-comments.php') {
1070 | $parent_menus[$item[2]] = 'Comments';
1071 | } elseif ($item[2] == 'plugins.php') {
1072 | $parent_menus[$item[2]] = 'Plugins';
1073 | } elseif (isset($item[5]) && preg_match('/^toplevel_page_/i', $item[5]) &&
1074 | is_array($options_pages) && count($options_pages)) {
1075 | // search options pages to get correct slug
1076 | $found = false;
1077 | foreach ($options_pages as $slug => $options_page) {
1078 | if ($item[0] == $options_page['page_title']) {
1079 | //$slug = strtolower(trim(preg_replace('/[^a-z0-9]+/i', '-', $item[0]), '-'));
1080 | $parent_menus[$slug] = $item[0];
1081 | $found = true;
1082 | }
1083 | }
1084 | if (!$found) {
1085 | $key = $item[2];
1086 | $value = $item[0];
1087 | if (!preg_match('/\.php/', $key)) {
1088 | //$key = 'admin.php?page='.$key;
1089 | }
1090 | $parent_menus[$key] = $value;
1091 | }
1092 | } else {
1093 | $key = $item[2];
1094 | $value = $item[0];
1095 | if (!preg_match('/\.php/', $key)) {
1096 | //$key = 'admin.php?page='.$key;
1097 | }
1098 | $parent_menus[$key] = $value;
1099 | }
1100 | } // end if good parent menu
1101 | if (isset($item[6]) && substr($item[6], 0, 6) == 'fa fa-') {
1102 | $menu[$index][4] .= ' acfop-fontawesome-'.str_replace(' ', '_', $item[6]);
1103 | }
1104 | } // end foreach menu
1105 | $this->parent_menus = $parent_menus;
1106 | } // end public function build_admin_menu_listacf_load_capabilities_field
1107 |
1108 | public function load_text_domain() {
1109 | load_plugin_textdomain('acf-options-page-adder', false, dirname(plugin_basename(__FILE__)).'/lang/');
1110 | do_action('acf_options_page/load_text_domain');
1111 | } // end public function load_text_domain
1112 |
1113 | public function sort_by_order($a, $b) {
1114 | if ($a['order'] == $b['order']) {
1115 | return 0;
1116 | } elseif ($a['order'] < $b['order']) {
1117 | return -1;
1118 | } else {
1119 | return 1;
1120 | }
1121 | } // end public function sort_by_order
1122 |
1123 | private function register_post_type() {
1124 | // register the post type
1125 | $cap = 'manage_options';
1126 | $cap = apply_filters('acf-options-page-adder/capability', $cap);
1127 | $capabilities = array(
1128 | 'edit_post' => $cap,
1129 | 'delete_post' => $cap,
1130 | 'edit_posts' => $cap,
1131 | 'delete_posts' => $cap,
1132 | );
1133 | $args = array('label' => __('Options Pages', 'acf-options-page-adder'),
1134 | 'description' => '',
1135 | 'public' => false,
1136 | 'show_ui' => true,
1137 | 'show_in_menu' => true,
1138 | 'capability_type' => 'post',
1139 | 'capabilities' => $capabilities,
1140 | //'map_meta_cap' => true,
1141 | 'hierarchical' => false,
1142 | 'rewrite' => array('slug' => $this->post_type, 'with_front' => false),
1143 | 'query_var' => true,
1144 | 'exclude_from_search' => true,
1145 | 'menu_position' => 100,
1146 | 'menu_icon' => 'dashicons-admin-generic',
1147 | 'supports' => array('custom-fields','revisions'),
1148 | 'show_in_rest' => false,
1149 | 'labels' => array('name' => __('Options Pages', 'acf-options-page-adder'),
1150 | 'singular_name' => __('Options Page', 'acf-options-page-adder'),
1151 | 'menu_name' => __('Options Pages', 'acf-options-page-adder'),
1152 | 'add_new' => __('Add Options Page', 'acf-options-page-adder'),
1153 | 'add_new_item' => __('Add New Options Page', 'acf-options-page-adder'),
1154 | 'edit' => __('Edit', 'acf-options-page-adder'),
1155 | 'edit_item' => __('Edit Options Page', 'acf-options-page-adder'),
1156 | 'new_item' => __('New Options Page', 'acf-options-page-adder'),
1157 | 'view' => __('View Options Page', 'acf-options-page-adder'),
1158 | 'view_item' => __('View Options Page', 'acf-options-page-adder'),
1159 | 'search_items' => __('Search Options Pages', 'acf-options-page-adder'),
1160 | 'not_found' => __('No Options Pages Found', 'acf-options-page-adder'),
1161 | 'not_found_in_trash' => __('No Options Pages Found in Trash', 'acf-options-page-adder'),
1162 | 'parent' => __('Parent Options Page', 'acf-options-page-adder')));
1163 | register_post_type($this->post_type, $args);
1164 | } // end private function register_post_type
1165 |
1166 | private function acf_add_options_pages() {
1167 | if (!function_exists('acf_add_options_sub_page')) {
1168 | return;
1169 | }
1170 | // get all the options pages and add them
1171 | $options_pages = array('top' => array(), 'sub' => array());
1172 | $args = array('post_type' => $this->post_type,
1173 | 'post_status' => 'publish',
1174 | 'posts_per_page' => -1,
1175 | 'order' => 'ASC');
1176 |
1177 |
1178 | $page_query = new WP_Query($args);
1179 | if (count($page_query->posts)) {
1180 | foreach ($page_query->posts as $post) {
1181 | $content = $post->post_content;
1182 | if ($content) {
1183 | $content = unserialize($content);
1184 | } else {
1185 | $content = $this->build_options_page_settings($post->ID);
1186 | }
1187 | $this->options_pages[$post->ID] = $content;
1188 | } // end foreach $post;
1189 | } // end if have_posts
1190 |
1191 | if (!count($this->options_pages)) {
1192 | return;
1193 | }
1194 |
1195 | $top = array();
1196 | $sub = array();
1197 | foreach ($this->options_pages as $page) {
1198 | if ($page['type'] == 'page') {
1199 | $top[] = $page;
1200 | } else {
1201 | $sub[] = $page;
1202 | }
1203 | }
1204 | if (count($top)) {
1205 | foreach ($top as $page) {
1206 | acf_add_options_page($page['acf']);
1207 | }
1208 | }
1209 | if (count($sub)) {
1210 | usort($sub, array($this, 'sort_by_order'));
1211 | foreach ($sub as $page) {
1212 | acf_add_options_sub_page($page['acf']);
1213 | }
1214 | }
1215 | } // end private function acf_add_options_pages
1216 |
1217 | } // end class acfOptionsPageAdder
1218 | ?>
1219 |
--------------------------------------------------------------------------------