Display Author role in archive or author page

$authordata is not available before the first post is set up (before the first the_post();). But all the data you need are already there on an author archive: in get_queried_object(). It is a WP_User Object on the author archive. print ‘<pre>’ . htmlspecialchars( print_r( get_queried_object(), TRUE ) ) . ‘</pre>’; Result: WP_User Object ( [data] … Read more

Restrict dashboard access for specific user roles to specific actions

This is how I ended up solving this issue. Originally I used this code for the link to delete an individual post: <?php if( !(get_post_status() == ‘trash’) ) : ?> <a class=”delete-post” onclick=”return confirm(‘Are you sure you wish to delete post: <?php echo get_the_title() ?>?’)”href=”https://wordpress.stackexchange.com/questions/78144/<?php echo get_delete_post_link( get_the_ID() ); ?>”>Delete</a> <?php endif; ?> After checking … Read more

How can I have different groups of editors only allowed to edit certain parent+subpages?

UPDATE – this is easy to do with the press permit plugin, I recommend it for any setup like this To get this working I had to do a couple of things: Default all pages/posts/categories ‘revisor’ (via Revisionary plugin) users to be restricted to ‘WP_Administrators’ Create a “User Group” for each department ie: ‘Conference Services … Read more

WPMU – new users are automatically subscribed to the main blog – how to prevent that?

This is a known bug. A fix will be available in 3.6.1, see: http://core.trac.wordpress.org/ticket/25166 For now, either bulk remove the users in WP Admin or do something (ugly and temporary, remove when 3.6.1 is available) like: add_action( ‘wpmu_new_user’, function ( $user_id ) { global $current_site; remove_user_from_blog( $user_id, $current_site->blog_id ); // remove user from main blog. … Read more

How to stop contributors editing post type but allowing them to edit a custom post type?

Add the capabilities to the role. Replace ‘cpt’ with the name of your custom post type: $role = get_role( ‘contributor’ ); $role->add_cap( ‘delete_published_cpt’ ); $role->add_cap( ‘delete_others_cpt’ ); $role->add_cap( ‘delete_cpt’ ); $role->add_cap( ‘edit_others_cpt’ ); $role->add_cap( ‘edit_published_cpt’ ); $role->add_cap( ‘edit_cpt’ ); $role->add_cap( ‘publish_cpt’ ); But you shouldn’t add or remove caps on every page load. That’s why … Read more

Let new user role to ‘edit_others_posts’ of other user role, not of its own type

First add capabilities to the roles like this add_action( ‘after_setup_theme’, ‘add_caps_to_custom_roles’ ); function add_caps_to_custom_roles() { $caps = array( ‘read_cpt’, ‘edit_cpt’, ‘edit_others_cpt’, ); $roles = array( get_role( ‘third_party’ ), get_role( ‘data_entry_operator’ ), ); foreach ($roles as $role) { foreach ($caps as $cap) { $role->add_cap( $cap ); } } } THEN /** * Helper function getting roles … Read more

Allow Facebook to preview posts before published

Create a new plugin with the following code: class Facebook_Peeker { private static $facebook_bots = [ ‘facebookexternalhit/1.1 (+https://www.facebook.com/externalhit_uatext.php)’, ‘facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)’ ]; private $original_posts; public function make_scheduled_post_public() { add_filter( ‘posts_results’, [ &$this, ‘peek_into_private’ ], null, 2 ); } public function peek_into_private( $posts, &$query ) { if ( sizeof( $posts ) != 1 ) { return $posts; … Read more

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