With what hook can I address all posts from all custom post types when they are published?

What about using save_post or wp_insert_post hook, both have @param     int               $post_ID     Post ID. @param     WP_Post     $post          Post object. @param     bool            $update     Whether this is an existing post being updated or not. as parameters. It is pretty self-explaining that the $update can be used to determine, if it … Read more

Check if current user has post in post type and is author role

Instead of using $chelseaRole ==1 it should be replaced with something like this !current_user_can(‘manage_categories’) since the author role cannot manage categories as seen here: https://codex.wordpress.org/Roles_and_Capabilities Polished it would look like this: function chelsea_user_has_posts($user_id) { $result = new WP_Query(array( ‘author’=>$user_id, ‘post_type’=>’ait-dir-item’, ‘post_status’=>’publish’, ‘posts_per_page’=>1, )); return (count($result->posts)!=0); } function cross_check_user_items() { $user = wp_get_current_user(); if (chelsea_user_has_posts($user->ID) && … Read more

How do I Make a custom post type get a custom post template in a plugin

function get_custom_post_type_template($single_template) { global $post; if ($post->post_type == ‘events’) { $single_template = dirname( __FILE__ ) . ‘/single-event.php’; } return $single_template; } add_filter( ‘single_template’, ‘get_custom_post_type_template’ ); Source Or you could use: add_filter( ‘template_include’, ‘single_event_template’, 99 ); function single_event_template( $template ) { if ( is_singular(‘event’) ) { $new_template = locate_template( array( ‘single-event.php’ ) ); if ( ” … Read more

Custom Post Type Capabilities — Enable Edit, Disable Create and Delete

There are a lot of capabilities, you can set for your post type. foreach ( self::$todo_roles as $role ) { $wp_roles->add_cap( $role, ‘edit_’ . self::$post_type_1 ); $wp_roles->add_cap( $role, ‘read_’ . self::$post_type_1 ); $wp_roles->add_cap( $role, ‘delete_’ . self::$post_type_1 ); $wp_roles->add_cap( $role, ‘edit_’ . self::$post_type_1 . ‘s’ ); $wp_roles->add_cap( $role, ‘edit_others_’ . self::$post_type_1 . ‘s’ ); $wp_roles->add_cap( … Read more