增强套件,可改进"高级自定义字段"管理
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1202 lines
39 KiB

  1. <?php
  2. if(!defined('ABSPATH'))
  3. exit;
  4. if(!class_exists('acfe_dynamic_options_pages')):
  5. class acfe_dynamic_options_pages extends acfe_dynamic_module{
  6. /*
  7. * Initialize
  8. */
  9. function initialize(){
  10. $this->active = acf_get_setting('acfe/modules/options_pages');
  11. $this->settings = 'modules.options_pages';
  12. $this->post_type = 'acfe-dop';
  13. $this->label = 'Options Page Title';
  14. $this->textdomain = 'ACF Extended: Options Pages';
  15. $this->tool = 'acfe_dynamic_options_pages_export';
  16. $this->tools = array('php', 'json');
  17. $this->columns = array(
  18. 'name' => __('Menu slug', 'acf'),
  19. 'post_id' => __('Post ID', 'acf'),
  20. 'autoload' => __('Autoload', 'acf'),
  21. );
  22. }
  23. /*
  24. * Actions
  25. */
  26. function actions(){
  27. add_action('admin_footer', array($this, 'admin_config'));
  28. add_action('pre_get_posts', array($this, 'admin_archive_posts'), 15);
  29. // Validate
  30. add_filter('acf/validate_value/key=field_acfe_dop_menu_slug', array($this, 'validate_name'), 10, 4);
  31. add_filter('acf/update_value/key=field_acfe_dop_menu_slug', array($this, 'update_name'), 10, 3);
  32. // Save
  33. add_filter('acfe/options_page/prepare_register', array($this, 'prepare_register'));
  34. add_filter('acfe/options_page/register', array($this, 'register'), 10, 2);
  35. add_filter('acfe/options_page/save_args', array($this, 'save_args'), 10, 3);
  36. add_action('acfe/options_page/save', array($this, 'save'), 10, 3);
  37. // Import
  38. add_action('acfe/options_page/import_fields', array($this, 'import_fields'), 10, 3);
  39. add_action('acfe/options_page/import', array($this, 'after_import'), 10, 2);
  40. $this->register_user_options_pages();
  41. }
  42. /*
  43. * Get Name
  44. */
  45. function get_name($post_id){
  46. return get_field('menu_slug', $post_id);
  47. }
  48. /*
  49. * Init
  50. */
  51. function init(){
  52. $this->register_post_type();
  53. }
  54. /*
  55. * Register Post Type
  56. */
  57. function register_post_type(){
  58. $capability = acf_get_setting('capability');
  59. if(!acf_get_setting('show_admin'))
  60. $capability = false;
  61. register_post_type($this->post_type, array(
  62. 'label' => 'Options Page',
  63. 'description' => 'Options Page',
  64. 'labels' => array(
  65. 'name' => 'Options Pages',
  66. 'singular_name' => 'Options Page',
  67. 'menu_name' => 'Options Pages',
  68. 'edit_item' => 'Edit Options Page',
  69. 'add_new_item' => 'New Options Page',
  70. ),
  71. 'supports' => array('title'),
  72. 'hierarchical' => true,
  73. 'public' => false,
  74. 'show_ui' => true,
  75. 'show_in_menu' => 'edit.php?post_type=acf-field-group',
  76. 'menu_icon' => 'dashicons-layout',
  77. 'show_in_admin_bar' => false,
  78. 'show_in_nav_menus' => false,
  79. 'can_export' => false,
  80. 'has_archive' => false,
  81. 'rewrite' => false,
  82. 'exclude_from_search' => true,
  83. 'publicly_queryable' => false,
  84. 'capabilities' => array(
  85. 'publish_posts' => $capability,
  86. 'edit_posts' => $capability,
  87. 'edit_others_posts' => $capability,
  88. 'delete_posts' => $capability,
  89. 'delete_others_posts' => $capability,
  90. 'read_private_posts' => $capability,
  91. 'edit_post' => $capability,
  92. 'delete_post' => $capability,
  93. 'read_post' => $capability,
  94. ),
  95. 'acfe_admin_orderby' => 'title',
  96. 'acfe_admin_order' => 'ASC',
  97. 'acfe_admin_ppp' => 999,
  98. ));
  99. }
  100. /*
  101. * Register User Options Pages
  102. */
  103. function register_user_options_pages(){
  104. $settings = apply_filters('acfe/options_page/prepare_register', acfe_get_settings($this->settings));
  105. if(empty($settings))
  106. return;
  107. foreach($settings as $name => $args){
  108. // Bail early
  109. if(empty($name) || acf_get_options_page($name))
  110. continue;
  111. // Filters
  112. $args = apply_filters("acfe/options_page/register", $args, $name);
  113. $args = apply_filters("acfe/options_page/register/name={$name}", $args, $name);
  114. if($args === false)
  115. continue;
  116. // Register
  117. acf_add_options_page($args);
  118. }
  119. }
  120. /*
  121. * Post Head
  122. */
  123. function post_head(){
  124. global $post;
  125. $post_id = $post->ID;
  126. $name = $this->get_name($post_id);
  127. $field_groups = acf_get_field_groups(array(
  128. 'options_page' => $name
  129. ));
  130. if($field_groups){
  131. add_meta_box( 'acfe-dop-field-groups', __('Field Groups', 'acf'), array($this, 'metabox_render'), $this->post_type, 'normal', 'default', $field_groups);
  132. }
  133. }
  134. /*
  135. * Metabox Render
  136. */
  137. function metabox_render($array, $data){
  138. $data = $data['args'];
  139. foreach($data as $field_group){ ?>
  140. <div class="acf-field">
  141. <div class="acf-label">
  142. <label for="acf-_post_title"><a href="<?php echo admin_url('post.php?post=' . $field_group['ID'] . '&action=edit'); ?>"><?php echo $field_group['title']; ?></a></label>
  143. <p class="description"><?php echo $field_group['key']; ?></p>
  144. </div>
  145. <div class="acf-input">
  146. <?php $fields = acf_get_fields($field_group); ?>
  147. <?php if(!empty($fields)){ ?>
  148. <table class="acf-table">
  149. <thead>
  150. <th class="acf-th" width="25%"><strong>Label</strong></th>
  151. <th class="acf-th" width="25%"><strong>Name</strong></th>
  152. <th class="acf-th" width="25%"><strong>Key</strong></th>
  153. <th class="acf-th" width="25%"><strong>Type</strong></th>
  154. </thead>
  155. <tbody>
  156. <?php
  157. $array = array();
  158. foreach($fields as $field){
  159. $this->get_fields_labels_recursive($array, $field);
  160. }
  161. foreach($array as $field_key => $field_label){
  162. $field = acf_get_field($field_key);
  163. $type = acf_get_field_type($field['type']);
  164. $type_label = '-';
  165. if(isset($type->label))
  166. $type_label = $type->label;
  167. ?>
  168. <tr class="acf-row">
  169. <td width="25%"><?php echo $field_label; ?></td>
  170. <td width="25%"><?php echo $field['name']; ?></td>
  171. <td width="25%"><code><?php echo $field_key; ?></code></td>
  172. <td width="25%"><?php echo $type_label; ?></td>
  173. </tr>
  174. <?php } ?>
  175. </tbody>
  176. </table>
  177. <?php } ?>
  178. </div>
  179. </div>
  180. <?php } ?>
  181. <script type="text/javascript">
  182. (function($){
  183. if(typeof acf === 'undefined')
  184. return;
  185. acf.newPostbox(<?php echo wp_json_encode(array(
  186. 'id' => 'acfe-dop-field-groups',
  187. 'key' => '',
  188. 'style' => 'default',
  189. 'label' => 'left',
  190. 'edit' => false
  191. )); ?>);
  192. })(jQuery);
  193. </script>
  194. <?php
  195. }
  196. /*
  197. * Edit Columns HTML
  198. */
  199. function edit_columns_html($column, $post_id){
  200. switch($column){
  201. // Name
  202. case 'name':
  203. echo '<code style="font-size: 12px;">' . $this->get_name($post_id) . '</code>';
  204. break;
  205. // Post ID
  206. case 'post_id':
  207. $p_id = get_field('post_id', $post_id);
  208. if(empty($p_id))
  209. $p_id = 'options';
  210. echo '<code style="font-size: 12px;">' . $p_id. '</code>';
  211. break;
  212. // Autoload
  213. case 'autoload':
  214. $al = __('No');
  215. $autoload = get_field('autoload', $post_id);
  216. if(!empty($autoload))
  217. $al = __('Yes');
  218. echo $al;
  219. break;
  220. }
  221. }
  222. /*
  223. * Edit Row Actions View
  224. */
  225. function edit_row_actions_view($post, $name){
  226. return '<a href="' . admin_url("admin.php?page={$name}") . '">' . __('View') . '</a>';
  227. }
  228. /*
  229. * ACF Save post
  230. */
  231. function save_post($post_id){
  232. // vars
  233. $args = array();
  234. $name = $this->get_name($post_id);
  235. // Filters
  236. $args = apply_filters("acfe/options_page/save_args", $args, $name, $post_id);
  237. $args = apply_filters("acfe/options_page/save_args/name={$name}", $args, $name, $post_id);
  238. $args = apply_filters("acfe/options_page/save_args/id={$post_id}", $args, $name, $post_id);
  239. if($args === false)
  240. return;
  241. // Actions
  242. do_action("acfe/options_page/save", $name, $args, $post_id);
  243. do_action("acfe/options_page/save/name={$name}", $name, $args, $post_id);
  244. do_action("acfe/options_page/save/id={$post_id}", $name, $args, $post_id);
  245. }
  246. /*
  247. * Save Args
  248. */
  249. function save_args($args, $name, $post_id){
  250. $page_title = get_post_field('post_title', $post_id);
  251. $name = get_field('menu_slug', $post_id);
  252. // Menu Title
  253. $menu_title = get_field('menu_title', $post_id);
  254. if(empty($menu_title))
  255. $menu_title = $page_title;
  256. // Register Args
  257. $parent_slug = get_field('parent_slug', $post_id);
  258. $capability = get_field('capability', $post_id);
  259. $position = get_field('position', $post_id);
  260. $icon_url = get_field('icon_url', $post_id);
  261. $redirect = get_field('redirect', $post_id);
  262. $p_id = get_field('post_id', $post_id);
  263. $autoload = get_field('autoload', $post_id);
  264. $update_button = get_field('update_button', $post_id);
  265. $updated_message = get_field('updated_message', $post_id);
  266. // Register: Args
  267. $args = array(
  268. 'page_title' => $page_title,
  269. 'menu_slug' => $name,
  270. 'menu_title' => $menu_title,
  271. 'capability' => $capability,
  272. 'position' => $position,
  273. 'parent_slug' => $parent_slug,
  274. 'icon_url' => $icon_url,
  275. 'redirect' => $redirect,
  276. 'post_id' => $p_id,
  277. 'autoload' => $autoload,
  278. 'update_button' => $update_button,
  279. 'updated_message' => $updated_message,
  280. );
  281. // Redirect
  282. $args['redirect'] = true;
  283. if(empty($redirect))
  284. $args['redirect'] = false;
  285. // Autoload
  286. $args['autoload'] = true;
  287. if(empty($autoload))
  288. $args['autoload'] = false;
  289. // Post ID
  290. if(empty($p_id))
  291. $args['post_id'] = 'options';
  292. return $args;
  293. }
  294. /*
  295. * Save
  296. */
  297. function save($name, $args, $post_id){
  298. // Parent
  299. $parent = 0;
  300. $parent_slug = $args['parent_slug'];
  301. if(!empty($parent_slug)){
  302. $get_dop_parent = get_posts(array(
  303. 'post_type' => $this->post_type,
  304. 'posts_per_page' => 1,
  305. 'fields' => 'ids',
  306. 'meta_query' => array(
  307. array(
  308. 'key' => 'menu_slug',
  309. 'value' => $parent_slug
  310. )
  311. )
  312. ));
  313. if(!empty($get_dop_parent)){
  314. $parent = $get_dop_parent[0];
  315. }
  316. }
  317. // Get ACFE option
  318. $settings = acfe_get_settings($this->settings);
  319. // Create ACFE option
  320. $settings[$name] = $args;
  321. // Sort keys ASC
  322. ksort($settings);
  323. // Update ACFE option
  324. acfe_update_settings($this->settings, $settings);
  325. // Update post
  326. wp_update_post(array(
  327. 'ID' => $post_id,
  328. 'post_name' => $name,
  329. 'post_parent' => $parent,
  330. ));
  331. }
  332. /*
  333. * Trashed Post Type
  334. */
  335. function trashed_post($post_id){
  336. $name = $this->get_name($post_id);
  337. // Get ACFE option
  338. $settings = acfe_get_settings($this->settings);
  339. // Unset ACFE option
  340. acfe_unset($settings, $name);
  341. // Update ACFE option
  342. acfe_update_settings($this->settings, $settings);
  343. }
  344. /*
  345. * Admin Config Button
  346. */
  347. function admin_config(){
  348. if(!acf_current_user_can_admin())
  349. return;
  350. global $plugin_page;
  351. if(!$plugin_page)
  352. return;
  353. $page = acf_get_options_page($plugin_page);
  354. if(!acf_maybe_get($page, 'menu_slug'))
  355. return;
  356. // Get Dynamic Options Page
  357. $acfe_dop_options_page = get_posts(array(
  358. 'post_type' => $this->post_type,
  359. 'posts_per_page' => 1,
  360. 'name' => $page['menu_slug']
  361. ));
  362. if(empty($acfe_dop_options_page))
  363. return;
  364. $acfe_dop_options_page = $acfe_dop_options_page[0];
  365. ?>
  366. <script type="text/html" id="tmpl-acfe-dop-title-config">
  367. <a href="<?php echo admin_url('post.php?post=' . $acfe_dop_options_page->ID . '&action=edit'); ?>" class="page-title-action acfe-dop-admin-config"><span class="dashicons dashicons-admin-generic"></span></a>
  368. </script>
  369. <script type="text/javascript">
  370. (function($){
  371. // Add button
  372. $('.wrap h1').append($('#tmpl-acfe-dop-title-config').html());
  373. })(jQuery);
  374. </script>
  375. <?php
  376. }
  377. /*
  378. * Admin: Archive Posts
  379. */
  380. function admin_archive_posts($query){
  381. global $pagenow;
  382. if (!is_admin() || !$query->is_main_query() || $pagenow !== 'edit.php' || $query->get('post_type') !== $this->post_type)
  383. return;
  384. $query->set('meta_key', 'position');
  385. $query->set('orderby', 'meta_value_num title');
  386. $query->set('order', 'ASC');
  387. }
  388. /*
  389. * Validate Name
  390. */
  391. function validate_name($valid, $value, $field, $input){
  392. if(!$valid)
  393. return $valid;
  394. // Editing Current Block Type
  395. $current_post_id = acf_maybe_get_POST('post_ID');
  396. if(!empty($current_post_id)){
  397. $current_name = get_field($field['name'], $current_post_id);
  398. if($value === $current_name)
  399. return $valid;
  400. }
  401. // Check existing ACF Options Pages
  402. $pages = acf_get_options_pages();
  403. if(!empty($pages)){
  404. foreach($pages as $slug => $page){
  405. if($slug !== $value)
  406. continue;
  407. $valid = __('This options page slug already exists');
  408. }
  409. }
  410. return $valid;
  411. }
  412. /*
  413. * Update Name
  414. */
  415. function update_name($value, $post_id, $field){
  416. // Previous value
  417. $_value = get_field($field['name'], $post_id);
  418. // Value Changed. Delete option
  419. if($_value !== $value){
  420. acfe_delete_settings("{$this->settings}.{$_value}");
  421. }
  422. return $value;
  423. }
  424. /*
  425. * Prepare Register
  426. */
  427. function prepare_register($settings){
  428. if(empty($settings))
  429. return $settings;
  430. // Init re-order
  431. $top_pages = $sub_pages = array();
  432. foreach($settings as $name => $args){
  433. // Sub pages
  434. if(acf_maybe_get($args, 'parent_slug')){
  435. $sub_pages[$name] = $args;
  436. continue;
  437. }
  438. // Top pages
  439. $top_pages[$name] = $args;
  440. }
  441. // Re-order sub pages
  442. if(!empty($sub_pages)){
  443. uasort($sub_pages, function($a, $b){
  444. return (int) $a['position'] - (int) $b['position'];
  445. });
  446. }
  447. // Merge
  448. $settings = array_merge($top_pages, $sub_pages);
  449. return $settings;
  450. }
  451. /*
  452. * Register
  453. */
  454. function register($args, $name){
  455. // Translate: Page Title
  456. if(isset($args['page_title'])){
  457. acfe__($args['page_title'], 'Menu_title', $this->textdomain);
  458. }
  459. // Translate: Menu Title
  460. if(isset($args['menu_title'])){
  461. acfe__($args['menu_title'], 'Menu_title', $this->textdomain);
  462. }
  463. // Translate: Update button
  464. if(isset($args['update_button'])){
  465. acfe__($args['update_button'], 'Update_button', $this->textdomain);
  466. }
  467. // Translate: Updated message
  468. if(isset($args['updated_message'])){
  469. acfe__($args['updated_message'], 'Updated_message', $this->textdomain);
  470. }
  471. return $args;
  472. }
  473. /*
  474. * Import
  475. */
  476. function import($name, $args){
  477. // Vars
  478. $settings = acfe_get_settings($this->settings);
  479. $title = $args['page_title'];
  480. // Already exists
  481. if(isset($settings[$name])){
  482. return new WP_Error('acfe_dop_import_already_exists', __("Options page \"{$title}\" already exists. Import aborted."));
  483. }
  484. // Import Post
  485. $post_id = false;
  486. $post = array(
  487. 'post_title' => $title,
  488. 'post_name' => $name,
  489. 'post_type' => $this->post_type,
  490. 'post_status' => 'publish'
  491. );
  492. $post = apply_filters("acfe/options_page/import_post", $post, $name);
  493. $post = apply_filters("acfe/options_page/import_post/name={$name}", $post, $name);
  494. if($post !== false){
  495. $post_id = wp_insert_post($post);
  496. }
  497. if(!$post_id || is_wp_error($post_id)){
  498. return new WP_Error('acfe_dop_import_error', __("Something went wrong with the options page \"{$title}\". Import aborted."));
  499. }
  500. // Import Args
  501. $args = apply_filters("acfe/options_page/import_args", $args, $name, $post_id);
  502. $args = apply_filters("acfe/options_page/import_args/name={$name}", $args, $name, $post_id);
  503. $args = apply_filters("acfe/options_page/import_args/name={$post_id}", $args, $name, $post_id);
  504. if($args === false)
  505. return $post_id;
  506. // Import Fields
  507. acf_enable_filter('local');
  508. do_action("acfe/options_page/import_fields", $name, $args, $post_id);
  509. do_action("acfe/options_page/import_fields/name={$name}", $name, $args, $post_id);
  510. do_action("acfe/options_page/import_fields/id={$post_id}", $name, $args, $post_id);
  511. acf_disable_filter('local');
  512. // Save
  513. $this->save_post($post_id);
  514. return $post_id;
  515. }
  516. function import_fields($name, $args, $post_id){
  517. update_field('menu_title', $args['menu_title'], $post_id);
  518. update_field('menu_slug', $args['menu_slug'], $post_id);
  519. update_field('capability', $args['capability'], $post_id);
  520. update_field('position', $args['position'], $post_id);
  521. update_field('parent_slug', $args['parent_slug'], $post_id);
  522. update_field('icon_url', $args['icon_url'], $post_id);
  523. update_field('redirect', $args['redirect'], $post_id);
  524. update_field('post_id', $args['post_id'], $post_id);
  525. update_field('autoload', $args['autoload'], $post_id);
  526. update_field('update_button', $args['update_button'], $post_id);
  527. update_field('updated_message', $args['updated_message'], $post_id);
  528. }
  529. /*
  530. * After Import
  531. */
  532. function after_import($ids, $data){
  533. $sub_pages = array();
  534. // Loop over json
  535. foreach($ids as $post_id){
  536. $parent_slug = get_field('parent_slug', $post_id);
  537. if(empty($parent_slug))
  538. continue;
  539. $sub_pages[$post_id] = $parent_slug;
  540. }
  541. // Update Options Sub Pages
  542. if(!empty($sub_pages)){
  543. foreach($sub_pages as $post_id => $parent_slug){
  544. // Get possible parent options pages
  545. $get_parent = get_posts(array(
  546. 'post_type' => $this->post_type,
  547. 'posts_per_page' => 1,
  548. 'fields' => 'ids',
  549. 'meta_query' => array(
  550. array(
  551. 'key' => 'menu_slug',
  552. 'value' => $parent_slug
  553. )
  554. )
  555. ));
  556. if(empty($get_parent))
  557. continue;
  558. // Update sub page post
  559. wp_update_post(array(
  560. 'ID' => $post_id,
  561. 'post_parent' => $get_parent[0],
  562. ));
  563. }
  564. }
  565. }
  566. /*
  567. * Export: Choices
  568. */
  569. function export_choices(){
  570. $choices = array();
  571. $settings = acfe_get_settings($this->settings);
  572. if(!$settings)
  573. return $choices;
  574. foreach($settings as $name => $args){
  575. $choices[$name] = esc_html($args['page_title']);
  576. }
  577. return $choices;
  578. }
  579. /*
  580. * Export: Data
  581. */
  582. function export_data($name){
  583. // Settings
  584. $settings = acfe_get_settings($this->settings);
  585. // Doesn't exist
  586. if(!isset($settings[$name]))
  587. return false;
  588. $args = $settings[$name];
  589. // Filters
  590. $args = apply_filters("acfe/options_page/export_args", $args, $name);
  591. $args = apply_filters("acfe/options_page/export_args/name={$name}", $args, $name);
  592. // Return
  593. return $args;
  594. }
  595. /*
  596. * Export: PHP
  597. */
  598. function export_php($data){
  599. // prevent default translation and fake __() within string
  600. acf_update_setting('l10n_var_export', true);
  601. $str_replace = array(
  602. " " => "\t",
  603. "'!!__(!!\'" => "__('",
  604. "!!\', !!\'" => "', '",
  605. "!!\')!!'" => "')",
  606. "array (" => "array("
  607. );
  608. $preg_replace = array(
  609. '/([\t\r\n]+?)array/' => 'array',
  610. '/[0-9]+ => array/' => 'array'
  611. );
  612. // Get settings.
  613. $l10n = acf_get_setting('l10n');
  614. $l10n_textdomain = acf_get_setting('l10n_textdomain');
  615. echo "if( function_exists('acf_add_options_page') ):" . "\r\n" . "\r\n";
  616. foreach($data as $args){
  617. // Translate settings if textdomain is set.
  618. if($l10n && $l10n_textdomain){
  619. $args['page_title'] = acf_translate($args['page_title']);
  620. $args['menu_title'] = acf_translate($args['menu_title']);
  621. $args['update_button'] = acf_translate($args['update_button']);
  622. $args['updated_message'] = acf_translate($args['updated_message']);
  623. }
  624. // code
  625. $code = var_export($args, true);
  626. // change double spaces to tabs
  627. $code = str_replace(array_keys($str_replace), array_values($str_replace), $code);
  628. // correctly formats "=> array("
  629. $code = preg_replace(array_keys($preg_replace), array_values($preg_replace), $code);
  630. // esc_textarea
  631. $code = esc_textarea($code);
  632. // echo
  633. echo "acf_add_options_page({$code});" . "\r\n" . "\r\n";
  634. }
  635. echo "endif;";
  636. }
  637. /*
  638. * Reset
  639. */
  640. function reset(){
  641. $args = apply_filters("acfe/options_page/reset_args", array(
  642. 'post_type' => $this->post_type,
  643. 'posts_per_page' => -1,
  644. 'fields' => 'ids',
  645. 'post_status' => array('publish', 'acf-disabled'),
  646. ));
  647. $posts = get_posts($args);
  648. if(empty($posts))
  649. return false;
  650. foreach($posts as $post_id){
  651. $this->save_post($post_id);
  652. }
  653. // Log
  654. acf_log('[ACF Extended] Reset: Options Pages');
  655. return true;
  656. }
  657. /*
  658. * Add Local Field Group
  659. */
  660. function add_local_field_group(){
  661. acf_add_local_field_group(array(
  662. 'key' => 'group_acfe_dynamic_options_page',
  663. 'title' => __('Options Page', 'acfe'),
  664. 'location' => array(
  665. array(
  666. array(
  667. 'param' => 'post_type',
  668. 'operator' => '==',
  669. 'value' => $this->post_type,
  670. ),
  671. ),
  672. ),
  673. 'menu_order' => 0,
  674. 'position' => 'normal',
  675. 'style' => 'default',
  676. 'label_placement' => 'left',
  677. 'instruction_placement' => 'label',
  678. 'hide_on_screen' => '',
  679. 'active' => 1,
  680. 'description' => '',
  681. 'fields' => array(
  682. array(
  683. 'key' => 'field_acfe_dop_menu_slug',
  684. 'label' => 'Menu slug',
  685. 'name' => 'menu_slug',
  686. 'type' => 'acfe_slug',
  687. 'instructions' => '(string) The URL slug used to uniquely identify this options page. Defaults to a url friendly version of Menu Title',
  688. 'required' => 1,
  689. 'conditional_logic' => 0,
  690. 'wrapper' => array(
  691. 'width' => '',
  692. 'class' => '',
  693. 'id' => '',
  694. ),
  695. 'acfe_validate' => '',
  696. 'acfe_update' => array(
  697. '5cd2a4d60fbf2' => array(
  698. 'acfe_update_function' => 'sanitize_title',
  699. ),
  700. ),
  701. 'acfe_permissions' => '',
  702. 'default_value' => '',
  703. 'placeholder' => '',
  704. 'prepend' => '',
  705. 'append' => '',
  706. 'maxlength' => '',
  707. ),
  708. array(
  709. 'key' => 'field_acfe_dop_menu_title',
  710. 'label' => 'Menu title',
  711. 'name' => 'menu_title',
  712. 'type' => 'text',
  713. 'instructions' => '(string) The title displayed in the wp-admin sidebar. Defaults to Page Title',
  714. 'required' => 0,
  715. 'conditional_logic' => 0,
  716. 'wrapper' => array(
  717. 'width' => '',
  718. 'class' => '',
  719. 'id' => '',
  720. ),
  721. 'acfe_validate' => '',
  722. 'acfe_update' => '',
  723. 'acfe_permissions' => '',
  724. 'default_value' => '',
  725. 'placeholder' => '',
  726. 'prepend' => '',
  727. 'append' => '',
  728. 'maxlength' => '',
  729. ),
  730. array(
  731. 'key' => 'field_acfe_dop_capability',
  732. 'label' => 'Capability',
  733. 'name' => 'capability',
  734. 'type' => 'text',
  735. 'instructions' => '(string) The capability required for this menu to be displayed to the user. Defaults to edit_posts.<br /><br />
  736. Read more about capability here: <a href="https://wordpress.org/support/article/roles-and-capabilities/">https://wordpress.org/support/article/roles-and-capabilities/</a>',
  737. 'required' => 0,
  738. 'conditional_logic' => 0,
  739. 'wrapper' => array(
  740. 'width' => '',
  741. 'class' => '',
  742. 'id' => '',
  743. ),
  744. 'acfe_validate' => '',
  745. 'acfe_update' => '',
  746. 'acfe_permissions' => '',
  747. 'default_value' => 'edit_posts',
  748. 'placeholder' => '',
  749. 'prepend' => '',
  750. 'append' => '',
  751. 'maxlength' => '',
  752. ),
  753. array(
  754. 'key' => 'field_acfe_dop_position',
  755. 'label' => 'Position',
  756. 'name' => 'position',
  757. 'type' => 'text',
  758. 'instructions' => '(int|string) The position in the menu order this menu should appear. Defaults to bottom of utility menu items.<br /><br />
  759. WARNING: if two menu items use the same position attribute, one of the items may be overwritten so that only one item displays!<br />
  760. Risk of conflict can be reduced by using decimal instead of integer values, e.g. \'63.3\' instead of 63 (must use quotes).',
  761. 'required' => 0,
  762. 'conditional_logic' => 0,
  763. 'wrapper' => array(
  764. 'width' => '',
  765. 'class' => '',
  766. 'id' => '',
  767. ),
  768. 'acfe_validate' => '',
  769. 'acfe_update' => '',
  770. 'acfe_permissions' => '',
  771. 'default_value' => '',
  772. 'placeholder' => '',
  773. 'prepend' => '',
  774. 'append' => '',
  775. 'maxlength' => '',
  776. ),
  777. array(
  778. 'key' => 'field_acfe_dop_parent_slug',
  779. 'label' => 'Parent slug',
  780. 'name' => 'parent_slug',
  781. 'type' => 'text',
  782. 'instructions' => '(string) The slug of another WP admin page. if set, this will become a child page.',
  783. 'required' => 0,
  784. 'conditional_logic' => 0,
  785. 'wrapper' => array(
  786. 'width' => '',
  787. 'class' => '',
  788. 'id' => '',
  789. ),
  790. 'acfe_validate' => '',
  791. 'acfe_update' => '',
  792. 'acfe_permissions' => '',
  793. 'default_value' => '',
  794. 'placeholder' => '',
  795. 'prepend' => '',
  796. 'append' => '',
  797. 'maxlength' => '',
  798. ),
  799. array(
  800. 'key' => 'field_acfe_dop_icon_url',
  801. 'label' => 'Icon url',
  802. 'name' => 'icon_url',
  803. 'type' => 'text',
  804. 'instructions' => '(string) The icon class for this menu. Defaults to default WordPress gear.<br /><br />
  805. Read more about dashicons here: <a href="https://developer.wordpress.org/resource/dashicons/">https://developer.wordpress.org/resource/dashicons/</a>',
  806. 'required' => 0,
  807. 'conditional_logic' => 0,
  808. 'wrapper' => array(
  809. 'width' => '',
  810. 'class' => '',
  811. 'id' => '',
  812. ),
  813. 'acfe_validate' => '',
  814. 'acfe_update' => '',
  815. 'acfe_permissions' => '',
  816. 'default_value' => '',
  817. 'placeholder' => '',
  818. 'prepend' => '',
  819. 'append' => '',
  820. 'maxlength' => '',
  821. ),
  822. array(
  823. 'key' => 'field_acfe_dop_redirect',
  824. 'label' => 'Redirect',
  825. 'name' => 'redirect',
  826. 'type' => 'true_false',
  827. 'instructions' => '(boolean) If set to true, this options page will redirect to the first child page (if a child page exists).
  828. If set to false, this parent page will appear alongside any child pages. Defaults to true',
  829. 'required' => 0,
  830. 'conditional_logic' => 0,
  831. 'wrapper' => array(
  832. 'width' => '',
  833. 'class' => '',
  834. 'id' => '',
  835. ),
  836. 'acfe_validate' => '',
  837. 'acfe_update' => '',
  838. 'acfe_permissions' => '',
  839. 'message' => '',
  840. 'default_value' => 1,
  841. 'ui' => 1,
  842. 'ui_on_text' => 'True',
  843. 'ui_off_text' => 'False',
  844. ),
  845. array(
  846. 'key' => 'field_acfe_dop_post_id',
  847. 'label' => 'Post ID',
  848. 'name' => 'post_id',
  849. 'type' => 'text',
  850. 'instructions' => '(int|string) The \'$post_id\' to save/load data to/from. Can be set to a numeric post ID (123), or a string (\'user_2\').
  851. Defaults to \'options\'.',
  852. 'required' => 0,
  853. 'conditional_logic' => 0,
  854. 'wrapper' => array(
  855. 'width' => '',
  856. 'class' => '',
  857. 'id' => '',
  858. ),
  859. 'acfe_validate' => '',
  860. 'acfe_update' => '',
  861. 'acfe_permissions' => '',
  862. 'default_value' => 'options',
  863. 'placeholder' => '',
  864. 'prepend' => '',
  865. 'append' => '',
  866. 'maxlength' => '',
  867. ),
  868. array(
  869. 'key' => 'field_acfe_dop_autoload',
  870. 'label' => 'Autoload',
  871. 'name' => 'autoload',
  872. 'type' => 'true_false',
  873. 'instructions' => '(boolean) Whether to load the option (values saved from this options page) when WordPress starts up.
  874. Defaults to false.',
  875. 'required' => 0,
  876. 'conditional_logic' => 0,
  877. 'wrapper' => array(
  878. 'width' => '',
  879. 'class' => '',
  880. 'id' => '',
  881. ),
  882. 'acfe_validate' => '',
  883. 'acfe_update' => '',
  884. 'acfe_permissions' => '',
  885. 'message' => '',
  886. 'default_value' => 0,
  887. 'ui' => 1,
  888. 'ui_on_text' => 'True',
  889. 'ui_off_text' => 'False',
  890. ),
  891. array(
  892. 'key' => 'field_acfe_dop_update_button',
  893. 'label' => 'Update button',
  894. 'name' => 'update_button',
  895. 'type' => 'text',
  896. 'instructions' => '(string) The update button text.',
  897. 'required' => 0,
  898. 'conditional_logic' => 0,
  899. 'wrapper' => array(
  900. 'width' => '',
  901. 'class' => '',
  902. 'id' => '',
  903. ),
  904. 'acfe_validate' => '',
  905. 'acfe_update' => '',
  906. 'acfe_permissions' => '',
  907. 'default_value' => 'Update',
  908. 'placeholder' => '',
  909. 'prepend' => '',
  910. 'append' => '',
  911. 'maxlength' => '',
  912. ),
  913. array(
  914. 'key' => 'field_acfe_dop_updated_message',
  915. 'label' => 'Updated Message',
  916. 'name' => 'updated_message',
  917. 'type' => 'text',
  918. 'instructions' => '(string) The message shown above the form on submit.',
  919. 'required' => 0,
  920. 'conditional_logic' => 0,
  921. 'wrapper' => array(
  922. 'width' => '',
  923. 'class' => '',
  924. 'id' => '',
  925. ),
  926. 'acfe_validate' => '',
  927. 'acfe_update' => '',
  928. 'acfe_permissions' => '',
  929. 'default_value' => 'Options Updated',
  930. 'placeholder' => '',
  931. 'prepend' => '',
  932. 'append' => '',
  933. 'maxlength' => '',
  934. ),
  935. ),
  936. ));
  937. }
  938. }
  939. acf_new_instance('acfe_dynamic_options_pages');
  940. endif;