| 1 |
<?php |
| 2 |
namespace ABlocksThemeBuilder; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
class Database { |
| 8 |
|
| 9 |
public static function init() { |
| 10 |
$self = new self(); |
| 11 |
add_action( 'init', [ $self, 'create_ablocks_tb_post_type' ] ); |
| 12 |
add_action( 'rest_api_init', [ $self, 'register_ablocks_tb_meta' ] ); |
| 13 |
} |
| 14 |
|
| 15 |
public function create_ablocks_tb_post_type() { |
| 16 |
$post_type = 'ablocks_tb'; |
| 17 |
register_post_type( |
| 18 |
$post_type, |
| 19 |
array( |
| 20 |
'labels' => array( |
| 21 |
'name' => esc_html__( 'Theme Builder', 'ablocks' ), |
| 22 |
'singular_name' => esc_html__( 'Theme Builder', 'ablocks' ), |
| 23 |
'search_items' => esc_html__( 'Search Theme Builder', 'ablocks' ), |
| 24 |
'parent_item_colon' => esc_html__( 'Parent Theme Builder:', 'ablocks' ), |
| 25 |
'not_found' => esc_html__( 'No Theme Builder found.', 'ablocks' ), |
| 26 |
'not_found_in_trash' => esc_html__( 'No Theme Builder found in Trash.', 'ablocks' ), |
| 27 |
'archives' => esc_html__( 'Theme Builder archives', 'ablocks' ), |
| 28 |
), |
| 29 |
'public' => true, |
| 30 |
'publicly_queryable' => true, |
| 31 |
'show_ui' => true, |
| 32 |
'show_in_menu' => false, |
| 33 |
'show_in_admin_bar' => false, |
| 34 |
'show_in_nav_menus' => false, |
| 35 |
'hierarchical' => false, |
| 36 |
'has_archive' => false, |
| 37 |
'rewrite' => false, |
| 38 |
'query_var' => true, |
| 39 |
'delete_with_user' => false, |
| 40 |
'supports' => array( 'title', 'editor', 'custom-fields' ), |
| 41 |
'show_in_rest' => true, |
| 42 |
'rest_base' => $post_type, |
| 43 |
'rest_namespace' => ABLOCKS_PLUGIN_SLUG . '/v1', |
| 44 |
'rest_controller_class' => 'WP_REST_Posts_Controller', |
| 45 |
'capability_type' => 'post', |
| 46 |
'map_meta_cap' => true, |
| 47 |
) |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
public function register_ablocks_tb_meta() { |
| 52 |
$course_meta = [ |
| 53 |
'ablocks_tb_template_type' => 'string', |
| 54 |
]; |
| 55 |
|
| 56 |
foreach ( $course_meta as $meta_key => $meta_value_type ) { |
| 57 |
register_meta( |
| 58 |
'post', |
| 59 |
$meta_key, |
| 60 |
array( |
| 61 |
'object_subtype' => 'ablocks_tb', |
| 62 |
'type' => $meta_value_type, |
| 63 |
'single' => true, |
| 64 |
'show_in_rest' => true, |
| 65 |
) |
| 66 |
); |
| 67 |
} |
| 68 |
// Display Rule |
| 69 |
register_meta( |
| 70 |
'post', |
| 71 |
'ablocks_tb_template_display_locations', |
| 72 |
array( |
| 73 |
'object_subtype' => 'ablocks_tb', |
| 74 |
'type' => 'array', |
| 75 |
'single' => true, |
| 76 |
'show_in_rest' => [ |
| 77 |
'schema' => array( |
| 78 |
'items' => array( |
| 79 |
'type' => 'object', |
| 80 |
'properties' => [ |
| 81 |
'label' => array( |
| 82 |
'type' => 'string', |
| 83 |
), |
| 84 |
'value' => array( |
| 85 |
'type' => 'string', |
| 86 |
), |
| 87 |
'specific' => array( |
| 88 |
'type' => 'array', |
| 89 |
'items' => array( |
| 90 |
'type' => 'object', |
| 91 |
'properties' => array( |
| 92 |
'label' => array( |
| 93 |
'type' => 'string', |
| 94 |
), |
| 95 |
'value' => array( |
| 96 |
'type' => 'string', |
| 97 |
), |
| 98 |
), |
| 99 |
), |
| 100 |
), |
| 101 |
], |
| 102 |
), |
| 103 |
), |
| 104 |
], |
| 105 |
) |
| 106 |
); |
| 107 |
// Exclusion Rule |
| 108 |
register_meta( |
| 109 |
'post', |
| 110 |
'ablocks_tb_template_not_display_locations', |
| 111 |
array( |
| 112 |
'object_subtype' => 'ablocks_tb', |
| 113 |
'type' => 'array', |
| 114 |
'single' => true, |
| 115 |
'show_in_rest' => [ |
| 116 |
'schema' => array( |
| 117 |
'items' => array( |
| 118 |
'type' => 'object', |
| 119 |
'properties' => [ |
| 120 |
'label' => array( |
| 121 |
'type' => 'string', |
| 122 |
), |
| 123 |
'value' => array( |
| 124 |
'type' => 'string', |
| 125 |
), |
| 126 |
'specific' => array( |
| 127 |
'type' => 'array', |
| 128 |
'items' => array( |
| 129 |
'type' => 'object', |
| 130 |
'properties' => array( |
| 131 |
'label' => array( |
| 132 |
'type' => 'string', |
| 133 |
), |
| 134 |
'value' => array( |
| 135 |
'type' => 'string', |
| 136 |
), |
| 137 |
), |
| 138 |
), |
| 139 |
), |
| 140 |
], |
| 141 |
), |
| 142 |
), |
| 143 |
], |
| 144 |
) |
| 145 |
); |
| 146 |
// Roles |
| 147 |
register_meta( |
| 148 |
'post', |
| 149 |
'ablocks_tb_template_target_user_roles', |
| 150 |
array( |
| 151 |
'object_subtype' => 'ablocks_tb', |
| 152 |
'type' => 'array', |
| 153 |
'single' => true, |
| 154 |
'show_in_rest' => [ |
| 155 |
'schema' => array( |
| 156 |
'items' => array( |
| 157 |
'type' => 'object', |
| 158 |
'properties' => [ |
| 159 |
'label' => array( |
| 160 |
'type' => 'string', |
| 161 |
), |
| 162 |
'value' => array( |
| 163 |
'type' => 'string', |
| 164 |
), |
| 165 |
], |
| 166 |
), |
| 167 |
), |
| 168 |
], |
| 169 |
) |
| 170 |
); |
| 171 |
|
| 172 |
} |
| 173 |
} |
| 174 |
|