Letting users create a post that is a custom post type from a page
You can create a new role and name it anything you like. Then you can add any type of capability you like https://wordpress.stackexchange.com/a/129807/9884
You can create a new role and name it anything you like. Then you can add any type of capability you like https://wordpress.stackexchange.com/a/129807/9884
Changed the code in functions.php to this: function get_user_role() { global $current_user; $user_roles = $current_user->roles; $user_role = array_shift($user_roles); return $user_role; } And in the sidebar.php: <?php if (is_page(array(‘page1’)) && get_user_role(‘Administrator’)) : echo ‘<div class=”widget-title”>Title 1</div>’ . wp_nav_menu(array(‘theme_location’=>’menu1’ )); elseif (is_page(array(‘page2’))) : echo ‘<div class=”widget-title”>Page 2</div>’ . wp_nav_menu(array(‘theme_location’=>’menu2’ )); elseif (is_page(array(‘page 3’))) : echo ‘<div class=”widget-title”>Page … Read more
So I Migrated the contents of meta_Key ‘wp_user_roles’ from the wp_options table from one server to another after a backup and it worked , the Roles migration was successful.
This line in your wpo_add_caps() function is incorrect: $admin->add_cap( ‘administrator’, $admin_cap ); It should simply read: $admin->add_cap( $admin_cap ); Source: WP_Role::add_cap().
That’s the correct way to get what you need. Though I’m not sure why WordPress returns an array of roles since ( to my knowledge ) you can only have 1 role at a time. Roles being an array you can modify by just retrieving the role index 0: $blogusers = get_users(); // Array of … Read more
Don’t remove the capability – this will make all editors unable to edit all posts. Instead, use a filter to conditionally determine if the post can be edited: function wpse_187738_map_meta_cap( $caps, $cap, $user_ID, $args ) { if ( $cap === ‘edit_post’ && $args && ! current_user_can( ‘manage_options’ ) /** Only proceed for non-administrators */ ) … Read more
How about remove_meta_box( $id, $page, $context );? https://codex.wordpress.org/Function_Reference/remove_meta_box This will remove the Publish meta box which contains the save button… function disable_save() { if( !current_user_can( ‘edit_post’ ) ) { // Or whatever check you need to make remove_meta_box( ‘submitdiv’, ‘your-chosen-post-type’, ‘side’ ); } } // disable_save add_action( ‘admin_menu’, ‘disable_save’ );
Close, your date comparison is slightly off – user_registered will be a MySQL datetime, so your string comparison will never evaluate true. Instead, convert it to just the date: $registered = mysql2date( ‘Y-m-d’, $user->user_registered ); Now we’re talking: if ( ‘2015-10-01′ === $registered ) { // chocks away } Update: Here’s a complete snippet that … Read more
You could make a widget that updates the role: Widget has a drop down select input Select input submits a Ajax call to backend Backend Ajax call processor updades the user meta Pass the User ID along with the role ID Update user meta with update_user_meta( $user_id, $meta_key, $meta_value, $prev_value )
Try to use get_posts() $current_user = get_current_user_id(); $args = array( ‘post_type’ => ‘post’, ‘author’ => $current_user, ‘post_status’ => ‘publish’, ); $all_posts = get_posts( $args );