soberwp / models

WordPress plugin to create custom post types and taxonomies using JSON, YAML or PHP files
MIT License
172 stars 13 forks source link

Add extended-cpts support #5

Closed Log1x closed 7 years ago

Log1x commented 7 years ago

I know I hit you up on Roots Discourse before about extended-cpts support for models. I finally got around to changing it over and it works flawlessly with everything else still in tact.

Only difference is you can now add all the features that come with extended-cpts in 'config' => [] of your CPT or Taxonomy.

An alternative if you don't want to add the extra dependency is to merely just add detection for the register_extended_post_type / register_extended_taxonomy functions and otherwise use WordPress' defaults, but I do think extended-cpts is well maintained enough to implement long-term. The library its self has full unit-testing and is well written.

Also, FYI: extended-cpts' composer.json has a >= PHP7 requirement so I bumped it on models too. Giving that Sage and everything else is going >= PHP7, that shouldn't be too big of a deal. I also bumped dependency versions.

Here's a small example of adding column sorting, and post filtering provided by extended-cpts to a custom post type:

'config'   => [
    'menu_icon'    => 'dashicons-star-filled',
    'admin_cols' => [
        'niche'  => [
            'title'    => 'Niche',
            'taxonomy' => 'niche'
        ],
        'rating' => [
            'title'    => 'Rating',
            'meta_key' => 'rating'
        ],
        'published' => [
            'title'       => 'Published',
            'meta_key'    => 'published_date',
            'date_format' => 'd/m/Y'
        ]
    ],
    'admin_filters' => [
        'niche' => [
            'taxonomy' => 'niche'
        ],
        'rating' => [
            'meta_key' => 'rating'
        ]
    ]
]

Other features include:

Screenshot

Let me know your thoughts.