Advertisement
Guest User

Untitled

a guest
Feb 8th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. $main_config = [
  2.     'title' => __( 'Main Page', 'igm-reviews' ),
  3.     'id' => 'main-page',
  4.     'tab_style' => 'box',
  5.     'tab_default_active' => 'tab_main',
  6.     'tabs' => [
  7.         'tab_main' => [
  8.             'label' => 'Activate TABS',
  9.             'icon' => 'admin-home',
  10.         ],
  11.         'tab_1' => [
  12.             'label' => 'TAB 1',
  13.             'icon' => '',
  14.         ],
  15.         'tab_2' => [
  16.             'label' => 'TAB 2',
  17.             'icon' => '',
  18.         ]
  19.     ],
  20.     'fields' => [
  21.         [
  22.             'tab' => 'tab_main',
  23.             'name' => __( 'Activate Tab 1?', 'textdomain' ),
  24.             'id' => 'tab_1',
  25.             'type' => 'post',
  26.             'field_type' => 'switch',
  27.         ],
  28.         [
  29.  
  30.             'tab' => 'tab_main',
  31.             'name' => __( 'Activate Tab 2?', 'textdomain' ),
  32.             'id' => 'tab_2',
  33.             'type' => 'post',
  34.             'field_type' => 'switch'
  35.         ],
  36.  
  37.     ]
  38. ];
  39.  
  40. // Then after saving tabs you check if switch are activated and add configuration array to main array
  41.  
  42. $tab_1 = [
  43.     'tab' => 'tab_1',
  44.     'name' => __( 'Input Title', 'textdomain' ),
  45.     'id' => 'title',
  46.     'type' => 'post',
  47.     'field_type' => 'text',
  48. ];
  49.  
  50. $tab_2 = [
  51.  
  52.     'tab' => 'tab_2',
  53.     'name' => __( 'Input Name', 'textdomain' ),
  54.     'id' => 'name',
  55.     'type' => 'post',
  56.     'field_type' => 'text',
  57. ];
  58.  
  59.  
  60. // Read option of main tab saved
  61. $switch = get_option();
  62. // then check and add tabs
  63. if ( $switch( 'tab_1' ) == 'on' ) {
  64.     $main_array['fields'][] = $tab_1;
  65. }
  66.  
  67.  
  68.  
  69. return $main_array;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement