Limit Post Creation Count by Author or Role

I have a site that offers non-paying members up to 5 posts using this: function author_post_count($user_id, $post_type = array(‘YOUR_CUSTOM_POST_TYPE_NAME_HERE’)) { $args = array( ‘post_type’ => $post_type, ‘author’ => $user_id, ‘posts_per_page’ => -1 ); $query = new WP_Query($args); return $query->found_posts; } Then I use: if ( author_post_count(get_current_user_id()) >5) { SHOW RESTRICTION NOTICE CODE HERE FOR USERS … Read more

Saving user meta “member_id” based on user role

Try this: function assignuserid($user_id) { $user_meta = get_userdata($user_id); $user_roles = $user_meta->roles; if (in_array(“subscriber”, $user_roles)){ global $wpdb; $latestid=$wpdb->get_var(“SELECT meta_value from $wpdb->usermeta where meta_key=’member_id’ order by meta_value DESC limit 1;”); update_user_meta( $user_id, ‘member_id’, $latestid+1 ); } } add_action( ‘user_register’, ‘assignuserid’);

Edit a function to take different actions based on user role

wp_update_post() ends up using wp_insert_post(), which has wp_insert_post_data inside it. The filter “Filters slashed post data just before it is inserted into the database.” I think that would be suitable moment to add the custom logic you described as publishorpend method doesn’t seem to have other filters available in it. You could perhaps do something … Read more

Enable a role named ‘backend_user’ to access my plugin pages

Adding capabilities to custom user roles. Before adding capabilities please refer to the capability list and existing user roles. https://wordpress.org/support/article/roles-and-capabilities/ Adding user roles without proper knowledge / practical experience can lead your site to different vulnerability and in worst cases it can create back doors. If you are interested in solution only then please jump … Read more

Removing menus from users other than the administrator

If you want to exclude menu items by their labels: function hide_menu_items( $items ) { $items_to_exclude = [‘Menu Item 1’, ‘Menu Item 2’]; if ( !current_user_can( ‘manage_options’ ) ) foreach ($items as $key => $item) if ( in_array( $item->title, $items_to_exclude ) ) unset( $items[$key] ); return $items; } add_filter( ‘wp_get_nav_menu_items’, ‘hide_menu_items’, 20 );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)