base && Access::is_enabled( (string) $screen->post_type ); } // End is_edit_screen() /** * Enqueue the field assets on enabled edit screens. * * @return void */ public function enqueue() : void { if ( ! self::is_edit_screen() ) { return; } Pickers::enqueue_fields_assets(); wp_enqueue_script( 'deadbolt-meta-box', Bootstrap::url() . 'inc/js/meta-box.js', [ 'jquery', 'deadbolt-fields' ], Bootstrap::script_version(), true ); } // End enqueue() /** * Add the meta box to enabled post types. * * @param string $post_type * @param \WP_Post $post * @return void */ public function add_meta_box( $post_type, $post ) : void { if ( ! Access::is_enabled( (string) $post_type ) ) { return; } add_meta_box( 'deadbolt', __( 'Access', 'deadbolt' ), [ $this, 'render' ], $post_type, 'side', 'default' ); } // End add_meta_box() /** * Render the meta box. * * @param \WP_Post $post * @return void */ public function render( \WP_Post $post ) : void { if ( Access::is_no_access_page( $post->ID ) ) { echo '

' . esc_html__( 'This is the No Access Page. It is always visible to everyone.', 'deadbolt' ) . '

'; return; } $rule = Access::parse( (string) get_post_meta( $post->ID, Access::META_KEY, true ) ); $options = Access::options(); $default = Access::post_type_default( $post->post_type ); wp_nonce_field( Access::NONCE, 'deadbolt_nonce' ); Helpers::render_access_fields( 'deadbolt', $rule, $options[ $default ] ?? $default ); $this->render_templates( $post->ID ); } // End render() /** * Show which templates are used for this post, with links to edit them or create a unique one. * Every condition is rendered, and meta-box.js shows the ones the selected access can lead to. * * @param int $post_id * @return void */ private function render_templates( int $post_id ) : void { $conditions = Templates::rule_conditions( Access::get_rule( $post_id ) ); $in_use = Templates::in_use( $post_id, array_keys( Templates::conditions() ) ); $covered = ! empty( $conditions ) && empty( array_diff( $conditions, array_keys( array_filter( $in_use, fn( $template ) => $template[ 'unique' ] ) ) ) ); $labels = Templates::conditions(); ?>
> >