Wp view config api

From Lonsdale201/wp-agent-skills · View interactive version

Wp view config api is an AI agent skill from the GitHub repository Lonsdale201/wp-agent-skills. Extend or audit WordPress 7.1 entity list and form defaults through the View Config API used by DataViews-based screens. Covers wp_get_entity_view_config, wp_get_entity_view_config_hook_name, dynamic get_entity_view_config filters, WP_View_Config_Data merge/replace/set/remove semantics, schema versi

How to use this skill

Skill file

WordPress View Config API

WordPress 7.1 builds DataViews-style defaults for an entity through wp_get_entity_view_config(). Plugins contribute versioned patches with WP_View_Config_Data; they do not replace REST controllers, entity data, or authorization.

Choose the exact entity hook

The filter is dynamic and its kind/name segments are lowercased. Generate it instead of guessing:

$hook = wp_get_entity_view_config_hook_name( 'postType', 'book' );
// get_entity_view_config_posttype_book

For a REST-exposed book post type:

add_filter(
    'get_entity_view_config_posttype_book',
    static function ( WP_View_Config_Data $data, array $entity ): WP_View_Config_Data {
        return $data->merge(
            array(
                'default_view' => array(
                    'type'    => 'table',
                    'perPage' => 30,
                    'fields'  => array( 'author', 'status', 'genre' ),
                ),
                'view_list' => array(
                    array(
                        'title' => __( 'Published', 'myplugin' ),
                        'slug'  => 'myplugin-published',
                        'view'  => array(
                            'filters' => array(
                                array(
                                    'field'    => 'status',
                                    'operator' => 'isAny',
                                    'value'    => 'publish',
                                ),
                            ),
                        ),
                    ),
                ),
            ),
            1
        );
    },
    10,
    2
);

Pass the schema version the patch was authored against—currently literal 1. Do not automatically substitute WP_View_Config_Data::LATEST_VERSION forever: a future schema bump should prompt review/migration of the patch.

Understand the four top-level keys

The container exposes mutation methods, not a public read accessor. Do not reflect into private data or branch on an undocumented materialized shape. Contribute a minimal patch.

Pick the least destructive method

| Method | Effect | Normal use |

|---|---|---|

| merge( $patch, 1 ) | Deeply composes maps; merges lists by id, slug, field, or scalar identity | Default choice for plugins |

| replace( $patch, 1 ) | Like merge, but named lists are replaced wholesale | Pin an exact list while preserving surrounding maps |

| set( $patch, 1 ) | Replaces every named top-level key wholesale | A plugin truly owns that full key |

| remove( $spec, 1 ) | Removes selected nested members; top-level removal resets the core default | Remove a precise inherited member |

Prefer merge(). Broad set()/replace() patches can erase core additions and other plugins' contributions.

Examples:

// Remove one field from the inherited default fields list.
return $data->remove(
    array( 'default_view' => array( 'fields' => array( 'author' ) ) ),
    1
);
// Replace only the fields list, not the whole default_view key.
return $data->replace(
    array( 'default_view' => array( 'fields' => array( 'title', 'status' ) ) ),
    1
);

A nested null deletes that leaf. A top-level null or top-level remove() resets the key to its original default rather than leaving the response key absent. Shape mismatches are rejected with a notice; do not merge a map where a list is expected.

Compose correctly with other callbacks

Every filter callback must return the WP_View_Config_Data object it received. Mutation methods return the object for chaining. Returning an array, null, or a new unrelated container breaks later priorities.

Use prefixed view slugs and field IDs. Make additions deterministic; the filter may run more than once in a request. Do not perform database writes or remote calls while building configuration.

The API keeps only documented top-level keys. Attaching arbitrary top-level plugin data will not survive materialization.

REST route and permissions

GET /wp-json/wp/v2/view-config?kind=postType&name=book exposes the built configuration and schema version. It is not anonymous:

The response is configuration only. Register the entity's REST fields/data separately and apply their own authorization. Hiding a field from a view config is not a data-access control.

Audit checklist

Critical rules

Cross-references

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.