WP Manifestindependent plugin directory
manifest / content / wpu_post_meta_rules

WPU Post Meta Rules

Block publication if some post metas dont match the defined rules

by Darklg · github.com/wordpressutilities/wpu_post_meta_rules · website

★ 0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/wordpressutilities/wpu_post_meta_rules/archive/refs/heads/main.zip

Block publication if some post metas dont match the defined rules

Usage

Define the rules via the wpu_post_meta_rules__fields filter. Each key is a post meta key, with name (label used in error messages), min / max (character length constraints) and an optional post_types array to restrict which post types the rule applies to.

add_filter('wpu_post_meta_rules__fields', function ($fields) {
    $fields['wpuseo_post_title'] = array(
        'name' => 'SEO title',
        'min' => 10,
        'max' => 70
    );
    $fields['wpuseo_post_description'] = array(
        'name' => 'SEO description',
        'min' => 10,
        'max' => 160
    );
    return $fields;
});

Exclude posts

Use the wpu_post_meta_rules__exclude_post filter to skip every rule for a given post.

add_filter('wpu_post_meta_rules__exclude_post', function ($excluded, $post_id, $post) {
    return in_array($post_id, array(42, 58));
}, 10, 3);