acf-extended / ACF-Extended

🚀 All-in-one enhancement suite that improves WordPress & Advanced Custom Fields
https://www.acf-extended.com
239 stars 27 forks source link

validate_post_type_archive not working (deprecated post_type_archive_capability) #114

Closed stilografico closed 1 year ago

stilografico commented 1 year ago

I was using this code to enable acfe_archive_editor for non administrators add_filter('acfe/post_type_archive_capability/name=prodotti', 'enable_acfe_archive_to_editor', 10, 2); function enable_acfe_archive_to_editor($capability) { return 'edit_posts'; }

post_type_archive_capability is now deprecated so I updated the filter like this add_filter('acfe/validate_post_type_archive/name=prodotti', 'enable_acfe_archive_to_editor', 10, 2); function enable_acfe_archive_to_editor($capability) { return 'edit_posts'; }

but doing so the acfe_archive_editor is disabled even for administrators

What should be the correct syntax?

acf-extended commented 1 year ago

Hello,

Thanks for the feedback!

The new acfe/validate_post_type_archive hook let you customize the entire "Archive" Options Page. This includes the menu title, page title... and of course the capability. This new hook gives more control to developers as they can now customize anything related to that Options Page.

Here is a usage example:

add_filter('acfe/validate_post_type_archive/name=my-post-type', 'my_validate_post_type_archive');
function my_validate_post_type_archive($args){

    /**
     * $args = array(
     *     'page_title'      => 'My Post Type Archive',
     *     'menu_title'      => 'Archive',
     *     'menu_slug'       => 'my-post-type-archive',
     *     'post_id'         => 'my-post-type_archive',
     *     'capability'      => 'manage_options',
     *     'redirect'        => false,
     *     'parent_slug'     => 'edit.php?post_type=my-post-type',
     *     'updated_message' => 'My Post Type Archive Saved.',
     * )
     */

    // change capability
    $args['capability'] = 'edit_posts';

    // return
    return $args;

}

I'll update the documentation regarding this specific hook later today.

Hope it helps!

Have a nice day!

Regards.

stilografico commented 1 year ago

Wonderful! That's perfect, thank you!