register_post_type(); } else { add_action( 'init', [ $this, 'register_post_type' ] ); } add_action( 'rest_api_init', [ $this, 'register_routes' ] ); } /** * Registers routes with WordPress. * * @return void */ public function register_routes(): void { register_rest_route( Constants::REST_BASE, '/group', [ [ 'methods' => WP_REST_Server::ALLMETHODS, 'callback' => [ $this, 'call_endpoint' ], 'permission_callback' => function () { return current_user_can( adpresso_get_capability( 'edit_group' ) ); }, ], ] ); } /** * Register the post type with all of his settings. * * @return void */ public function register_post_type(): void { if ( post_type_exists( Constants::POST_TYPE_GROUP ) ) { return; } $labels = [ 'name' => __( 'Ad Groups', 'adpresso' ), 'singular_name' => __( 'Ad Group', 'adpresso' ), 'add_new' => __( 'New Group', 'adpresso' ), 'add_new_item' => __( 'Add New Group', 'adpresso' ), 'edit_item' => __( 'Edit Group', 'adpresso' ), 'view_item' => __( 'View Group', 'adpresso' ), 'search_items' => __( 'Search Groups', 'adpresso' ), 'not_found' => __( 'No Groups found', 'adpresso' ), 'not_found_in_trash' => __( 'No Groups found in Trash', 'adpresso' ), ]; $args = [ 'label' => __( 'Groups', 'adpresso' ), 'public' => false, 'show_ui' => false, 'show_in_menu' => false, 'supports' => [ 'title', 'author' ], 'capability_type' => 'adpresso_group', 'map_meta_cap' => true, 'capabilities' => adpresso_get_post_type_capabilities( 'group' ), 'hierarchical' => false, 'has_archive' => false, 'menu_position' => null, 'show_in_rest' => false, 'exclude_from_search' => true, 'rewrite' => false, 'labels' => $labels, ]; register_post_type( Constants::POST_TYPE_GROUP, apply_filters( 'adpresso_post_type_group_args', $args ) ); /** * Fires after the core Group post type and its statuses are registered. * Allows adding custom post statuses or performing other actions. * * @param string $post_type The registered post type slug (Constants::POST_TYPE_GROUP). */ do_action( 'adpresso_after_register_group_post_type', Constants::POST_TYPE_GROUP ); } }