post_type ) ) { return; } Pickers::enqueue_fields_assets(); wp_enqueue_script( 'deadbolt-list-table', Bootstrap::url() . 'inc/js/list-table.js', [ 'jquery', 'inline-edit-post', 'deadbolt-fields' ], Bootstrap::script_version(), true ); } // End enqueue() /** * Mark enabled list screens that show templates in the column, so the column can be wider. * * @param string $classes * @return string */ public function body_class( $classes ) : string { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( $screen && 'edit' === $screen->base && Access::is_enabled( (string) $screen->post_type ) && Settings::get( 'show_templates_column' ) ) { $classes .= ' deadbolt-show-templates'; } return (string) $classes; } // End body_class() /** * Add the column. * * @param array $columns * @return array */ public function add_column( array $columns ) : array { $columns[ self::COLUMN ] = __( 'Access', 'deadbolt' ); return $columns; } // End add_column() /** * Render the column, with the raw rule in data attributes for Quick Edit. * * @param string $column * @param int $post_id * @return void */ public function render_column( $column, $post_id ) : void { if ( self::COLUMN !== $column ) { return; } if ( Access::is_no_access_page( (int) $post_id ) ) { echo '' . esc_html__( 'Everyone (No Access Page)', 'deadbolt' ) . ''; return; } $raw = (string) get_post_meta( $post_id, Access::META_KEY, true ); $users = []; foreach ( Helpers::user_labels( Access::parse( $raw )[ 'users' ] ) as $id => $label ) { $users[] = [ 'id' => $id, 'text' => $label ]; } printf( '%3$s', esc_attr( $raw ), esc_attr( (string) wp_json_encode( $users ) ), esc_html( Access::describe( (int) $post_id ) ) ); if ( Settings::get( 'show_templates_column' ) ) { echo Templates::in_use_html( (int) $post_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- every part is escaped in Templates::in_use_html(). } } // End render_column() /** * Render the Quick Edit controls. * * @param string $column * @param string $post_type * @return void */ public function render_quick_edit( $column, $post_type ) : void { $this->render_inline( (string) $column, (string) $post_type, false ); } // End render_quick_edit() /** * Render the Bulk Edit controls. * * @param string $column * @param string $post_type * @return void */ public function render_bulk_edit( $column, $post_type ) : void { $this->render_inline( (string) $column, (string) $post_type, true ); } // End render_bulk_edit() /** * Render the shared Quick Edit and Bulk Edit fieldset. * * @param string $column * @param string $post_type * @param bool $bulk * @return void */ private function render_inline( string $column, string $post_type, bool $bulk ) : void { if ( self::COLUMN !== $column || ! Access::is_enabled( $post_type ) ) { return; } $name = $bulk ? 'deadbolt_bulk' : 'deadbolt'; $options = Access::options(); $default = Access::post_type_default( $post_type ); ?>
'default', 'roles' => [], 'users' => [] ], $options[ $default ] ?? $default, $bulk ); ?>