### Quick Install Script Source: https://github.com/codepress/admin-columns/blob/main/CONTRIBUTING.md Run this script from the admin-columns/ folder for a full development setup, including PHP and frontend dependencies. ```bash ./install.sh ``` -------------------------------- ### Install Frontend Dependencies Source: https://github.com/codepress/admin-columns/blob/main/CONTRIBUTING.md Install frontend dependencies using npm and run the development setup script. This is only necessary if you plan to make frontend changes. ```bash npm install npm run setup:dev ``` -------------------------------- ### Complete ListScreenCollection Usage Example Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-collections.md Demonstrates the full lifecycle of a `ListScreenCollection`, including creation, adding screens, checking for existence, counting, retrieving the first item, iterating, getting an array copy, and removing screens. ```php use AC\ListScreenCollection; // Create collection $collection = new ListScreenCollection(); // Add screens $collection->add($screen1); $collection->add($screen2); // Check contents if ($collection->contains($screen1)) { echo 'Screen found'; } // Count $total = count($collection); // Get first $first = $collection->first(); // Iterate foreach ($collection as $id => $screen) { echo $screen->get_title(); } // Get array copy $screens_array = $collection->get_copy(); // Remove $collection->remove($screen1); ``` -------------------------------- ### Complete ColumnCollection Usage Example Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-collections.md Provides a comprehensive example of using ColumnCollection, covering creation, adding columns, iteration, retrieving the first column, counting, and conversion from an iterator. ```php use AC\ColumnCollection; // Create empty $collection = new ColumnCollection(); // Add columns $collection->add($column1); $collection->add($column2); // Iterate foreach ($collection as $column) { echo $column->get_label(); } // Get first $first = $collection->first(); // Count $total = count($collection); // Convert from iterator $existing_iterator = $list_screen->get_columns(); $new_collection = ColumnCollection::from_iterator($existing_iterator); ``` -------------------------------- ### Complete List Screen Usage Example Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Demonstrates how to retrieve a list screen, access its properties, iterate through its columns, check user permissions, and get relevant URLs. This snippet is useful for understanding the core functionalities of the Admin Columns API. ```php use AC\Type\ColumnId; add_action('wp_loaded', function() { // Get a list screen $layout = ac_get_list_screen('post-posts'); if (!$layout) { return; } // Access basic properties echo 'Title: ' . $layout->get_title(); echo 'Table: ' . $layout->get_table_id(); echo 'Screen: ' . $layout->get_screen_id(); // Iterate columns foreach ($layout->get_columns() as $column) { echo $column->get_label() . ' (' . $column->get_type() . ')'; // Get column settings if ($column->get_setting('my_setting')) { // Process setting } } // Check user access $current_user = wp_get_current_user(); if ($layout->is_user_allowed($current_user)) { echo 'User can access this layout'; } // Get URLs echo 'View table: ' . $layout->get_table_url(); echo 'Edit layout: ' . $layout->get_editor_url(); }); ``` -------------------------------- ### Complete AdminColumns Plugin Usage Example Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-admin-columns.md A comprehensive example demonstrating how to access plugin information (version, paths, basename) and use it to enqueue admin styles within a WordPress admin menu action hook. ```php add_action('admin_menu', function() { $plugin = AC(); // Get plugin information $version = $plugin->get_version(); $dir_path = $plugin->get_dir_path(); $dir_url = $plugin->get_dir_url(); $basename = $plugin->get_basename(); $file = $plugin->get_file(); // Use in your code if (is_plugin_active($basename)) { // Enqueue assets wp_enqueue_style( 'my-admin-style', $dir_url . 'assets/css/admin.css', [], (string)$version ); } }); ``` -------------------------------- ### Install PHP Dependencies Source: https://github.com/codepress/admin-columns/blob/main/CONTRIBUTING.md Install the plugin's PHP dependencies using Composer. This also handles build tooling and namespace prefixing. ```bash composer install ``` -------------------------------- ### Plugin Initialization Hooks Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-admin-columns.md Hook into the plugin's setup process using `after_setup_theme`. Ensure the plugin is loaded and initialized correctly. ```php add_action('after_setup_theme', static function () { require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/api.php'; if ( ! defined('ACP_VERSION')) { $container = new Container( (new ContainerBuilder()) ->addDefinitions(require __DIR__ . '/settings/container-definitions.php') ->build() ); new Loader($container); } }, 1); add_action('after_setup_theme', static function () { do_action('ac/ready'); }, 2); ``` -------------------------------- ### Registry: Get, Check, and Set Services Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/quick-reference.md Interact with the service registry to get, check for the existence of, or register services. ```php // Get a service $service = Registry::get(string $id, $default = null) // Check existence $exists = Registry::has(string $id): bool // Register a service Registry::set(string $id, $value): void ``` -------------------------------- ### Displaying Column Information Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-column.md Example of how to retrieve and display basic information about columns. ```APIDOC ## Displaying Column Information ### Description Iterates through a list of columns and prints their ID, type, label, and group. ### Usage Example ```php add_action('wp_loaded', function() { $columns = ac_get_columns('post-posts'); foreach ($columns as $column) { printf( "ID: %s | Type: %s | Label: %s | Group: %s\n", $column->get_id(), $column->get_type(), $column->get_label(), $column->get_group() ); if ($column->get_description()) { echo "Description: " . $column->get_description() . "\n"; } } }); ``` ``` -------------------------------- ### Get All Registered Repositories Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen-repository.md Retrieves an array of all registered repositories from the Storage class. ```php public function get_repositories(): array ``` -------------------------------- ### ListScreenId Usage Example Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/types.md Demonstrates how to create a ListScreenId, retrieve its ID, and check for validity before instantiation. It also shows the __toString method. ```php use AC\Type\ListScreenId; $id = new ListScreenId('post-posts'); echo $id->get_id(); // "post-posts" echo $id; // "post-posts" (has __toString) // Check validity before constructing if (ListScreenId::is_valid_id($user_input)) { $id = new ListScreenId($user_input); } ``` -------------------------------- ### Instantiate ListScreen Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Example of creating a new ListScreen instance with a custom ID, title, table screen, and a collection of columns. User preferences can also be set during instantiation. ```php use AC\ListScreen; use AC\Type\ListScreenId; use AC\TableScreen; use AC\ColumnCollection; use AC\Type\TableId; use AC\Type\Labels; use AC\Type\Uri; $list_screen = new ListScreen( new ListScreenId('custom-layout-1'), 'My Custom Layout', $table_screen, new ColumnCollection([ $column1, $column2 ]), [ 'users' => [1, 2], 'roles' => ['editor', 'contributor'] ] ); ``` -------------------------------- ### ColumnId Usage Example Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/types.md Shows how to create a ColumnId instance and use it to retrieve a column from a list screen. ```php use AC\Type\ColumnId; $id = new ColumnId('post_title'); $column = $list_screen->get_column($id); ``` -------------------------------- ### Registry: Get Common Storage Service Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/quick-reference.md Retrieve the ListScreenRepository Storage service from the registry. ```php // Common service $storage = Registry::get(AC\ListScreenRepository\Storage::class) ``` -------------------------------- ### Graceful Degradation Examples Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/architecture-and-integration.md Demonstrates how the plugin handles non-existent list screens and collection operations without throwing exceptions, returning null or empty collections instead. ```php // No exception if list screen not found $screen = ac_get_list_screen('invalid-id'); // Returns null, not exception // No exception on collection operations $screens = ac_get_list_screens('post-posts'); // Returns empty collection, never null ``` -------------------------------- ### ListScreenStatus Usage Example Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/types.md Illustrates creating active and inactive ListScreenStatus objects using both the constructor and static factory methods, and how to set the status for a list screen. ```php use AC\Type\ListScreenStatus; // Create active status $status = new ListScreenStatus(); $status = ListScreenStatus::create_active(); // Create inactive status $status = ListScreenStatus::create_inactive(); // Use in list screen $list_screen->set_status($status); ``` -------------------------------- ### TableId Usage Example Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/types.md Demonstrates creating a TableId, using it with API functions, and validating input before creating an instance. ```php use AC\Type\TableId; // Create a table identifier $table_id = new TableId('post-posts'); // Use with API functions $screens = ac_get_list_screens('post-posts'); // Verify before creating if (TableId::validate($input)) { $id = new TableId($input); } ``` -------------------------------- ### Access Storage and Find/Save ListScreen Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/README.md Demonstrates how to get the Storage service from the Registry and use it to find a ListScreen by its ID, and then save it. This is used for managing the persistence of list screen configurations. ```php $storage = Registry::get(Storage::class); $screen = $storage->find(new ListScreenId('post-posts')); $storage->save($screen); ``` -------------------------------- ### Get Plugin Information Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-public-functions.md Retrieve the version, file path, and URL of the Admin Columns plugin instance. The plugin instance is a singleton and created lazily. ```php $plugin = AC(); echo $plugin->get_version(); echo $plugin->get_file(); echo $plugin->get_dir_path(); echo $plugin->get_dir_url(); ``` -------------------------------- ### Enumerating Available Layouts Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/architecture-and-integration.md Example of how to retrieve and iterate through all available list screen layouts for a specific table type, such as the post list table. ```php add_action('wp_loaded', function() { // Get all layouts for the post list table $screens = ac_get_list_screens('post-posts'); foreach ($screens as $screen) { printf( "Layout: %s (ID: %s, Status: %s)\n", $screen->get_title(), $screen->get_id(), $screen->get_status() ); } }); ``` -------------------------------- ### ListScreenCollection Constructor Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-collections.md Shows how to initialize a ListScreenCollection, optionally with an array of existing ListScreen objects. This is the primary way to start managing a group of list screens. ```php public function __construct(array $list_screens = []) ``` -------------------------------- ### Clone Plugin into WordPress Source: https://github.com/codepress/admin-columns/blob/main/CONTRIBUTING.md Manually place the plugin into your WordPress installation by cloning the repository into the wp-content/plugins directory. ```bash cd wp-content/plugins git clone https://github.com/codepress/admin-columns.git cd admin-columns ``` -------------------------------- ### ColumnCollection Constructor Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-collections.md Shows how to instantiate a ColumnCollection, optionally initializing it with an array of existing columns. This is the starting point for managing a set of columns. ```php use AC\Column\Base; use AC\ColumnCollection; $collection = new ColumnCollection([$column1, $column2]); ``` -------------------------------- ### AC() Instance Methods Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-public-functions.md Get the singleton instance of the Admin Columns plugin and access its core methods. ```APIDOC ## AC() ### Description Returns the singleton instance of the Admin Columns plugin. ### Usage ```php $plugin = AC(); echo $plugin->get_version(); echo $plugin->get_file(); echo $plugin->get_dir_path(); echo $plugin->get_dir_url(); ``` ### Notes - Returns the same instance on every call (singleton pattern). - The instance is created lazily on first call. - Safe to call at any time during plugin execution. ``` -------------------------------- ### Mocking Storage for Unit Tests Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/architecture-and-integration.md Provides an example of how to mock the Storage service using PHPUnit's mocking capabilities and register it with the Registry for use in unit tests. ```php // For unit tests, you might mock the Storage $mock_storage = $this->createMock(Storage::class); Registry::set(Storage::class, $mock_storage); // Now your code will use mock ``` -------------------------------- ### Processing All Columns for a List Screen Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-collections.md This example shows how to retrieve all list screens for a given post type and then iterate through each screen to access and count its associated columns. ```php add_action('wp_loaded', function() { $screens = ac_get_list_screens('post-posts'); foreach ($screens as $screen) { $columns = $screen->get_columns(); echo sprintf( '%s has %d columns: ', $screen->get_title(), count($columns) ); foreach ($columns as $column) { echo $column->get_label() . ', '; } } }); ``` -------------------------------- ### Start Development Watch Mode Source: https://github.com/codepress/admin-columns/blob/main/src/README.md Use these commands to continuously build JavaScript and CSS during development. The Tailwind CSS can be watched separately. ```bash npm run ac:build:development ``` ```bash npm run ac:tailwind ``` -------------------------------- ### Initialize TableScreen with Labels Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/types.md When creating a TableScreen instance, you can pass a Labels object to configure the table's display names. This example shows how to retrieve the plural label from the initialized TableScreen. ```php $table_screen = new TableScreen( new TableId('post-posts'), 'edit-post', new Labels('Post', 'Posts'), $url ); echo $table_screen->get_labels()->get_plural(); // "Posts" ``` -------------------------------- ### Find and Use a Specific Column Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Example of retrieving a single column by its ID and accessing its label if the column is found. ```php use AC\Type\ColumnId; $column = $list_screen->get_column(new ColumnId('post_title')); if ($column) { echo $column->get_label(); } ``` -------------------------------- ### Setting Up Test Environment with wp_loaded Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/architecture-and-integration.md Demonstrates how to set up a testing environment by hooking into the 'wp_loaded' action to ensure the plugin is ready before executing tests with the public API. It also shows how to manually trigger the initialization. ```php // In test setup add_action('wp_loaded', function() { // Plugin is ready // Can now test with public API }); do_action('wp_loaded'); // Trigger initialization ``` -------------------------------- ### Getting and Comparing Plugin Version Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/architecture-and-integration.md Shows how to retrieve the plugin's current version and use version comparison functions to implement feature detection for compatibility with newer plugin versions. ```php $plugin = AC(); $version = $plugin->get_version(); echo (string)$version; // "7.0.19" // Use for feature detection if (version_compare((string)$version, '7.0', '>=')) { // Use features available in 7.0+ } ``` -------------------------------- ### Get Plugin Information Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/quick-reference.md Access various plugin details like version, file path, directory, and base name using the AC() helper. ```php $plugin = AC() $plugin->get_version(): Version $plugin->get_file(): string $plugin->get_dir_path(): string $plugin->get_dir_url(): string $plugin->get_basename(): string // Example echo $plugin->get_dir_url() . 'assets/css/style.css' ``` -------------------------------- ### Access Storage and Find Screens Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen-repository.md Demonstrates how to retrieve the Storage instance from the registry and use it to find list screens by ID or table ID. ```php use AC\Registry; use AC\ListScreenRepository\Storage; use AC\Type\ListScreenId; use AC\Type\TableId; $storage = Registry::get(Storage::class); if (!$storage instanceof Storage) { error_log('Storage not available'); return; } // Find a specific screen $id = new ListScreenId('custom-layout-1'); $screen = $storage->find($id); // Find all screens for a table $table_id = new TableId('post-posts'); $screens = $storage->find_all_by_table_id($table_id); // Save changes if ($screen && !$screen->is_read_only()) { $screen->set_title('Updated Title'); $storage->save($screen); } ``` -------------------------------- ### Access Plugin Instance via Global Function Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-admin-columns.md Demonstrates how to get the singleton plugin instance using the global AC() function. This is the recommended way to access the plugin. ```php $plugin = AC(); ``` -------------------------------- ### Complete ColumnIterator Usage Example Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-collections.md Illustrates comprehensive usage of the ColumnIterator interface, including counting columns, retrieving the first column, iterating using a foreach loop, and manual iteration with while loop. ```php $columns = $list_screen->get_columns(); // Count columns $count = count($columns); // Get first without iteration $first_column = $columns->first(); // Iterate columns foreach ($columns as $column) { echo $column->get_label(); } // Manual iteration $columns->rewind(); while ($columns->valid()) { $column = $columns->current(); echo $column->get_id(); $columns->next(); } ``` -------------------------------- ### Get the First ListScreen from a Collection Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-collections.md Retrieve the first `ListScreen` object from the collection using the `first` method. Returns `null` if the collection is empty. ```php public function first(): ?ListScreen ``` -------------------------------- ### Instantiate Url\Documentation Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/types.md Create an instance of Url\Documentation to generate links to Admin Columns documentation. An optional path can be provided to link to a specific section. ```php new Url\Documentation($path = null); ``` -------------------------------- ### Build for Production Source: https://github.com/codepress/admin-columns/blob/main/src/README.md Execute these commands to create a full production build of the frontend assets, including or excluding language files as needed. ```bash npm run build ``` ```bash npm run build-nolanguage ``` -------------------------------- ### Instantiate Base Column Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-column.md Demonstrates how to create a new Base column instance with all its parameters. ```php use AC\Column\Base; use AC\Type\ColumnId; use AC\Setting\ComponentCollection; use AC\Column\Context; use AC\Setting\Config; use AC\FormatterCollection; $column = new Base( 'post_title', // type 'Post Title', // label new ComponentCollection(), // settings new ColumnId('post_title'), // id new Context( // context new Config(['type' => 'post_title']), 'Post Title' ), new FormatterCollection(), // formatters 'primary', // group 'The main post title' // description ); ``` -------------------------------- ### Column API - Context Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/quick-reference.md Get the context of a Column object. ```php // Context $column->get_context(): Context ``` -------------------------------- ### ContainerException Usage Example Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/errors.md Demonstrates how to catch a ContainerException, which is thrown by the dependency injection container for configuration or injection errors. This is useful for debugging container issues. ```php use AC\Exception\ContainerException; try { $container->make('missing-service'); } catch (ContainerException $e) { error_log('Container error: ' . $e->getMessage()); return false; } ``` -------------------------------- ### Countable Methods Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-collections.md Method for getting the number of items in the collection. ```APIDOC ## Countable Methods - **count(): int** — Total screens ``` -------------------------------- ### Filtering List Screens by Status and User Permissions Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-collections.md This example shows how to create a filtered `ListScreenCollection` containing only active screens that the current user is permitted to access. It utilizes `get_status` and `is_user_allowed` methods. ```php use AC\ListScreenCollection; $all_screens = ac_get_list_screens('post-posts'); $filtered = new ListScreenCollection(); foreach ($all_screens as $screen) { // Only include active screens for current user $user = wp_get_current_user(); if ($screen->get_status() === ListScreenStatus::create_active() && $screen->is_user_allowed($user)) { $filtered->add($screen); } } // Use filtered collection $first = $filtered->first(); ``` -------------------------------- ### Get Table URL Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-table-screen.md Retrieves the URL for the table view. ```php public function get_url(): Uri ``` ```php $url = $table_screen->get_url(); echo $url; // "https://example.com/wp-admin/edit.php" ``` -------------------------------- ### DI Container vs. Registry Usage Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-registry.md Illustrates the difference between using the DI Container for object construction and the Registry for runtime service access. Shows a common pattern for populating the Registry from the Container during initialization. ```php // DI Container: used during object construction $container->make(ListScreenRepository\Storage::class); // Registry: used for dynamic access $storage = Registry::get(ListScreenRepository\Storage::class); // Common pattern: populated from container during initialization foreach ($important_services as $id => $definition) { Registry::set($id, $container->make($definition)); } ``` -------------------------------- ### Get Table ID Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-table-screen.md Retrieves the unique identifier for the table. ```php public function get_id(): TableId ``` ```php $table_id = $table_screen->get_id(); echo $table_id; // e.g., "post-posts" ``` -------------------------------- ### Plugin Initialization Flow Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/architecture-and-integration.md Illustrates the sequence of events during plugin initialization, from WordPress loading the main file to the public API becoming available. ```text Plugin Entry ↓ Loader (initializes all services) ↓ Container (manages dependencies) ├── TableScreenRepository (knows all table types) ├── Storage (aggregates list screen repositories) └── Various factories (create specific objects) Public API ├── ac_get_list_screen() ├── ac_get_list_screens() ├── ac_get_column() └── ac_get_columns() ``` -------------------------------- ### Get Screen ID Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-table-screen.md Retrieves the WordPress screen ID for the table. ```php public function get_screen_id(): string ``` ```php $screen_id = $table_screen->get_screen_id(); if ($screen_id === 'edit-post') { // This is the post list table } ``` -------------------------------- ### Get ListScreen Title Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Retrieves the display title of the list screen layout. ```php public function get_title(): string ``` -------------------------------- ### Accessing ListScreenRepository Storage Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-registry.md Demonstrates retrieving the main storage service for list screen configurations from the Registry. ```php $storage = Registry::get(AC\ListScreenRepository\Storage::class); $list_screen = $storage->find(new ListScreenId('post-posts')); ``` -------------------------------- ### Get Table Labels Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-table-screen.md Retrieves the singular and plural labels associated with the table. ```php public function get_labels(): Labels ``` ```php $labels = $table_screen->get_labels(); echo $labels->get_singular(); // "Post" echo $labels->get_plural(); // "Posts" ``` -------------------------------- ### Instantiate Url\CouponCode Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/types.md Create an instance of Url\CouponCode to generate promotional URLs that include a coupon code. The constructor requires the coupon code string. ```php new Url\CouponCode($coupon_code); ``` -------------------------------- ### Get TableScreen Object Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Retrieves the TableScreen object associated with this list screen layout. ```php public function get_table_screen(): TableScreen ``` -------------------------------- ### Registry Internal Implementation: Lazy Loading Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-registry.md Demonstrates the internal mechanism of the Registry, including its static storage and lazy-loading behavior. When a Closure is stored, it is executed only when the service is first accessed via `get()`. ```php private static array $items = []; // Services are keyed by their identifier // Values can be any PHP type or a Closure // When get() is called with a Closure value, it executes the Closure if ($value instanceof Closure) { $value = $value(); // Lazy-load behavior } ``` -------------------------------- ### Get ListScreen ID Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Retrieves the unique identifier for the current list screen layout. ```php public function get_id(): ListScreenId ``` -------------------------------- ### Get Table DOM Selector Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-table-screen.md Retrieves the CSS selector for the table element in the DOM. ```php public function get_attr_id(): string ``` ```php $selector = $table_screen->get_attr_id(); // Use in JavaScript to target the table // document.querySelector('#the-list') ``` -------------------------------- ### Inspecting Column Configuration Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/architecture-and-integration.md Demonstrates how to access a specific list screen and iterate through its columns to inspect their labels, types, and settings. ```php add_action('wp_loaded', function() { $screen = ac_get_list_screen('post-posts'); if ($screen) { foreach ($screen->get_columns() as $column) { echo sprintf( "Column: %s (Type: %s, Group: %s)\n", $column->get_label(), $column->get_type(), $column->get_group() ); // Check for specific setting $width = $column->get_setting('width'); if ($width) { // Column has width setting } } } }); ``` -------------------------------- ### Displaying List Screen Information in Admin Notices Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/README.md This example demonstrates how to display list screen titles in admin notices. It includes a check to ensure the code runs after 'wp_loaded' to prevent timing errors. ```php add_action('admin_notices', function() { if (!did_action('wp_loaded')) { return; // Too early } $screens = ac_get_list_screens('post-posts'); foreach ($screens as $screen) { printf( '

Layout: %s

', esc_html($screen->get_title()) ); } }); ``` -------------------------------- ### Get Table URL Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Generates the URL for viewing the list table with the current layout applied. ```php public function get_table_url(): Uri ``` -------------------------------- ### Base Column Creation Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-column.md Demonstrates how to instantiate a new Base column with all its parameters. ```APIDOC ## Base Column Creation ### Description Instantiates a new `Base` column object, which serves as the foundation for custom columns. ### Parameters #### Path Parameters - **`$type`** (string) - Required - Column type identifier. - **`$label`** (string) - Required - Display label for the column. - **`$settings`** (ComponentCollection) - Required - Column settings. - **`$id`** (ColumnId) - Required - Unique identifier for the column. - **`$context`** (Context) - Required - Configuration context for the column. - **`$formatters`** (FormatterCollection) - Optional - Value formatters (default: null, empty collection). - **`$group`** (string) - Optional - Group identifier (default: 'custom'). - **`$description`** (string) - Optional - Optional description for the column. ### Usage Example ```php use AC\Column\Base; use AC\Type\ColumnId; use AC\Setting\ComponentCollection; use AC\Column\Context; use AC\Setting\Config; use AC\FormatterCollection; $column = new Base( 'post_title', // type 'Post Title', // label new ComponentCollection(), // settings new ColumnId('post_title'), // id new Context( new Config(['type' => 'post_title']), 'Post Title' ), // context new FormatterCollection(), // formatters 'primary', // group 'The main post title' // description ); ``` ``` -------------------------------- ### Set All Repositories Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen-repository.md Sets all repositories for the Storage class at once. Throws a LogicException if invalid repository objects are provided. ```php public function set_repositories(array $repositories): void ``` -------------------------------- ### Get All Columns Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Retrieves an iterable collection of all Column objects configured for this list screen layout. ```php public function get_columns(): ColumnIterator ``` -------------------------------- ### Get WordPress Screen ID Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Retrieves the WordPress screen ID associated with this table layout. ```php public function get_screen_id(): string ``` -------------------------------- ### ListScreen API - Status Management Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/quick-reference.md Get or set the status of a ListScreen (e.g., active or inactive). ```php // Status $screen->get_status(): ListScreenStatus $screen->set_status(ListScreenStatus $status): void ``` -------------------------------- ### Direct Instantiation of AdminColumns (Rare) Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-admin-columns.md Shows how to directly instantiate the AdminColumns class, typically used in specific scenarios where the global function is not suitable. Requires defining AC_FILE and AC_VERSION. ```php use AC\AdminColumns; use AC\Plugin\Version; $plugin = new AdminColumns(AC_FILE, new Version(AC_VERSION)); ``` -------------------------------- ### Get Table ID for ListScreen Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Retrieves the identifier of the table to which this list screen layout belongs. ```php public function get_table_id(): TableId ``` -------------------------------- ### Instantiate AdminColumns Plugin Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-admin-columns.md Shows how to create a new AdminColumns plugin instance using the constructor or the global AC() function wrapper. ```php use AC\AdminColumns; use AC\Plugin\Version; $plugin = new AdminColumns(__FILE__, new Version('7.0.19')); // Or use the global function wrapper $plugin = AC(); ``` -------------------------------- ### Get Column Group Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-column.md Retrieves the group identifier for the column, used for organization. Defaults to 'custom'. ```php public function get_group(): string ``` -------------------------------- ### Get Restore Link from Storage Model Source: https://github.com/codepress/admin-columns/blob/main/changelog.txt The CPAC_Column_Storagemodel::get_restore_link() method is now available for retrieving restore links. ```php CPAC_Column_Storagemodel::get_restore_link() ``` -------------------------------- ### Get Table View URL Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/quick-reference.md Generate the URL to view a table with a specific layout using get_table_url. ```php $screen = ac_get_list_screen('post-posts') // View table with this layout $url = $screen->get_table_url() echo $url // https://example.com/wp-admin/edit.php?layout=... ``` -------------------------------- ### Get Single Column by ID Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Retrieves a specific column object from the layout using its unique ColumnId. ```php public function get_column(ColumnId $id): ?Column ``` -------------------------------- ### Loading, Modifying, and Saving List Screens Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-collections.md Illustrates the typical workflow of loading a `ListScreenCollection` from storage, making modifications by adding new screens, and then saving individual screens back to storage. ```php // Load from storage $screens = ac_get_list_screens('post-posts'); // Returns ListScreenCollection // Modify $screens->add($new_screen); // Save individual screen $storage = Registry::get(Storage::class); foreach ($screens as $screen) { $storage->save($screen); } ``` -------------------------------- ### Get Column Label Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-column.md Retrieves the human-readable display label for a column. This is what users see in the table header. ```php public function get_label(): string ``` ```php $column = ac_get_column('post_title', 'post-posts'); echo $column->get_label(); // Outputs: "Title" or localized equivalent ``` -------------------------------- ### Get Column ID Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-column.md Retrieves the unique identifier for a column. Used to access specific column instances. ```php public function get_id(): ColumnId ``` ```php $column = ac_get_column('post_title', 'post-posts'); $id = $column->get_id(); echo $id->get_id(); // Outputs: "post_title" ``` -------------------------------- ### Handle Multiple Repositories Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen-repository.md Iterates through available repositories to check their write status. ```php $storage = Registry::get(Storage::class); // Check which repositories are available foreach ($storage->get_repositories() as $index => $repo) { $writable = $repo->is_writable() ? 'writable' : 'read-only'; echo "Repository $index: $writable\n"; } ``` -------------------------------- ### Get List Screen by ID Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/quick-reference.md Retrieve a specific layout by its ID. This function should be called after the `wp_loaded` hook. ```php $screen = ac_get_list_screen(string $id): ?ListScreen ``` -------------------------------- ### Get Columns from Storage Model Source: https://github.com/codepress/admin-columns/blob/main/changelog.txt The CPAC_Column_Storagemodel::get_columns() method has been changed. Use this to retrieve the current set of columns. ```php CPAC_Column_Storagemodel::get_columns() ``` -------------------------------- ### Creating a Custom TableScreen Instance Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-table-screen.md Shows how to manually instantiate a TableScreen object with custom properties. This is typically used for advanced scenarios where a table screen is not automatically generated by the plugin. ```php use AC\TableScreen; use AC\Type\TableId; use AC\Type\Labels; use AC\Type\Url; // Create a custom table screen (rare, usually created by plugin) $table_screen = new TableScreen( new TableId('my-custom-table'), 'my-custom-screen', new Labels('Item', 'Items'), new Url\AdminUrl('my-custom-page.php'), '#my-table', false // Not network ); // Access properties echo $table_screen->get_id(); // TableId echo $table_screen->get_labels(); // Labels echo $table_screen->get_screen_id(); // "my-custom-screen" echo $table_screen->get_url(); // URL echo $table_screen->get_attr_id(); // "#my-table" echo $table_screen->is_network(); // false ``` -------------------------------- ### Get ListScreen Label Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Retrieves the plural label for the table, typically derived from the associated TableScreen's labels. ```php public function get_label(): ?string ``` -------------------------------- ### Get All Columns from a List Screen Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/quick-reference.md Retrieve all columns associated with a specific layout. This function should be called after the `wp_loaded` hook. ```php $columns = ac_get_columns(string $list_screen_id): Column[] ``` -------------------------------- ### Instantiate Url\Site Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/types.md Create an instance of Url\Site to generate links to the Admin Columns website. An optional path can be specified to link to a particular page or resource. ```php new Url\Site($path = null); ``` -------------------------------- ### Get Specific Column Setting Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-column.md Retrieves a specific column setting by its name. Returns null if the setting is not found. ```php public function get_setting(string $name): ?Component ``` ```php $column = ac_get_column('post_date', 'post-posts'); $format_setting = $column->get_setting('date_format'); if ($format_setting) { // Setting exists and can be processed } ``` -------------------------------- ### Building a Custom Column List Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-collections.md Demonstrates creating a `ColumnCollection` and selectively adding columns based on a display condition. This allows for the creation of a filtered set of columns for custom rendering. ```php use AC\ColumnCollection; $custom_columns = new ColumnCollection(); // Add only visible columns foreach ($list_screen->get_columns() as $column) { if ($should_display($column)) { $custom_columns->add($column); } } // Now use custom collection foreach ($custom_columns as $column) { render_column($column); } ``` -------------------------------- ### Get All Column Settings Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-column.md Retrieves a collection of all setting components associated with the column. Useful for iterating through all available settings. ```php public function get_settings(): ComponentCollection ``` ```php $column = ac_get_column('post_title', 'post-posts'); $settings = $column->get_settings(); foreach ($settings as $setting) { echo $setting->get_name(); } ``` -------------------------------- ### Build Translation File Source: https://github.com/codepress/admin-columns/blob/main/src/README.md Generates the translation (.pot) file for internationalization. ```bash npm run ac:languages ``` -------------------------------- ### Get Column Type Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-column.md Retrieves the type identifier for a column, such as 'post_title' or 'custom_field'. Useful for determining column functionality. ```php public function get_type(): string ``` -------------------------------- ### Get Plugin Version Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-admin-columns.md Retrieves the plugin's version object. This method is inherited from the parent Plugin class. ```php public function get_version(): Version ``` ```php $plugin = AC(); $version = $plugin->get_version(); echo (string)$version; // Outputs: "7.0.19" ``` -------------------------------- ### Advanced Storage Query with Filters Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/README.md Demonstrates querying for ListScreens using the Storage service with specific filters, including table ID and status. This allows for targeted retrieval of screen configurations. ```php $storage = Registry::get(Storage::class); if ($storage instanceof Storage) { // Query with filters $screens = $storage->find_all_by_table_id( new TableId('post-posts'), null, ListScreenStatus::create_active() ); } ``` -------------------------------- ### Create and use Url subtypes Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/types.md Instantiate various Url subtypes like Editor, Documentation, Site, UtmTags, and CouponCode to generate specific types of URLs. Use the `get_url()` method to retrieve the final URL string. ```php use AC\Type\Url; // Get editor URL $editor_url = (new Url\Editor('post-posts'))->get_url(); // Get documentation link $docs_url = (new Url\Documentation('getting-started'))->get_url(); // Get site URL with UTM tags $promo_url = (new Url\UtmTags( new Url\Site('/features'), 'wordpress-plugin', 'settings-page' ))->get_url(); ``` -------------------------------- ### Get Storage Model from CPAC_Column Source: https://github.com/codepress/admin-columns/blob/main/changelog.txt The CPAC_Column $storage_model variable has become private. Use the CAPC_Column::get_storage_model() method to access it. ```php CAPC_Column::get_storage_model() ``` -------------------------------- ### Safely Get a List Screen Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/quick-reference.md Use ac_get_list_screen to retrieve a specific list screen. Returns null if the screen is not found. ```php add_action('wp_loaded', function() { $screen = ac_get_list_screen('post-posts'); if ($screen === null) { return; // Not found } // Use screen }); ``` -------------------------------- ### Iterate and Count Columns Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Demonstrates how to loop through all columns in a ListScreen to access their labels and how to count the total number of columns. ```php foreach ($list_screen->get_columns() as $column) { echo $column->get_label(); } // Count columns $count = count($list_screen->get_columns()); ``` -------------------------------- ### Get Table URL Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen.md Retrieve the URL for the table view of the current layout. This URL includes the layout ID parameter. ```php $url = $list_screen->get_table_url(); echo (string)$url; // Outputs the URL ``` -------------------------------- ### Instantiate Url\EditorNetwork Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/types.md Create an instance of Url\EditorNetwork for network admin editor URLs. Similar to Url\Editor, an optional slug can be provided. ```php new Url\EditorNetwork($slug = null); ``` -------------------------------- ### Get Column Context Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-column.md Retrieves the configuration context for the column, which includes details like type, name, and type label. ```php public function get_context(): Context ``` ```php $column = ac_get_column('post_date', 'post-posts'); $context = $column->get_context(); echo $context->get_type_label(); // Label for the column type echo $context->get_type(); // Column type echo $context->get_name(); // Column name ``` -------------------------------- ### Plugin Initialization Hook for Services Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/README.md The 'ac/ready' hook ensures the plugin is fully initialized and all services are available. Use this hook to safely access plugin functionalities after initialization. ```php add_action('ac/ready', function() { // Plugin is fully initialized // All services available $screen = ac_get_list_screen('post-posts'); }); ``` -------------------------------- ### Get Column Description Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-column.md Retrieves an optional descriptive text for the column, explaining its purpose. Returns null if no description is set. ```php public function get_description(): ?string ``` -------------------------------- ### AC() Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-public-functions.md Gets the main instance of the Admin Columns plugin. This singleton pattern provides access to the core plugin object. ```APIDOC ## AC() ### Description Get the main Admin Columns plugin instance. ### Method PHP Function ### Signature `function AC(): AC\AdminColumns` ### Returns `AC\AdminColumns` — The plugin instance (singleton). ### Usage ```php // Get the plugin instance $plugin_instance = AC(); // You can then use it to access other plugin functionalities if needed // For example: $plugin_instance->some_method(); ``` ``` -------------------------------- ### Get Empty Character for Columns Source: https://github.com/codepress/admin-columns/blob/main/changelog.txt The CPAC_Column::get_empty_char() method has been added to retrieve the character used to display empty values in columns. ```php CPAC_Column::get_empty_char() ``` -------------------------------- ### Add Repository to Storage Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen-repository.md Creates a new Storage instance with an additional repository. Useful for extending storage capabilities. ```php public function with_repository( string $name, ListScreenRepository\Storage\ListScreenRepository $repository ): self ``` ```php $storage = $original_storage->with_repository( 'custom-backend', $new_repository ); ``` -------------------------------- ### Get Column Types from Storage Model Source: https://github.com/codepress/admin-columns/blob/main/changelog.txt Methods added to CPAC_Column_Storagemodel to retrieve column types, including default and registered columns. ```php CPAC_Column_Storagemodel::get_column_types() ``` ```php CPAC_Column_Storagemodel::get_default_colummn_types() ``` ```php CPAC_Column_Storagemodel::get_column_type() ``` -------------------------------- ### Get Column Formatters Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-column.md Retrieves a collection of all formatter objects applied to the column. Formatters are used to transform the column's value. ```php public function get_formatters(): FormatterCollection ``` ```php $column = ac_get_column('post_date', 'post-posts'); $formatters = $column->get_formatters(); foreach ($formatters as $formatter) { // Each formatter transforms the column value } ``` -------------------------------- ### Exception Handling for Timing Errors Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/architecture-and-integration.md Shows how to catch specific exceptions like HookTimingException and FailedToSaveListScreen to handle plugin initialization timing issues or storage operation failures. ```php use AC\Exception\HookTimingException; use AC\Exception\FailedToSaveListScreen; try { $screen = ac_get_list_screen('post-posts'); } catch (HookTimingException $e) { // Called before wp_loaded die('Plugin not yet initialized'); } try { $storage->save($screen); } catch (FailedToSaveListScreen $e) { // Storage operation failed error_log($e->getMessage()); } ``` -------------------------------- ### ListScreenId Class Definition Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/types.md Defines the structure for a ListScreenId, including its constructor and methods for getting the ID, comparing IDs, and validating IDs. ```php final class ListScreenId { public function __construct(string $id) public function get_id(): string public function equals(ListScreenId $id): bool public static function is_valid_id($id): bool } ``` -------------------------------- ### Retrieve Specific Repository Source: https://github.com/codepress/admin-columns/blob/main/_autodocs/api-reference-list-screen-repository.md Fetches a specific repository by its key. Throws a LogicException if the repository is not found. ```php public function get_repository($key): Storage\ListScreenRepository ```