Display User Role Next To Comment

Just pass the user id to this function: function get_role($user_id) { if(is_int($user_id)) { $user = new WP_User( $user_id ); if ( !empty( $user->roles ) && is_array( $user->roles ) ) { foreach ( $user->roles as $role ) echo $role; } } else echo “Something else”; }

Membership subscription, change user role when subscription runs out

Presumably you’ve saved an expiration data somewhere, so setup a wp_cron job to run daily. That job should check the expiration dates, and change the roles for users whose dates are past. if ( ! wp_next_scheduled( ‘alter_user_role_hook’ ) ) { wp_schedule_event( strtotime(‘tomorrow’), ‘daily’, ‘alter_user_role_hook’ ); } function alter_user_role_function() { global $wpdb; $today = date(‘Y-m-d H:i:s’,strtotime(‘today’)); … Read more

Change post status based on user role

I’m then trying to figure out how to change the post status once their subscription is up function downgrade_user_role( $entry, $subscription_id, $transaction_id, $new_payment_amount ) { $user = GFUserData::get_user_by_entry_id( $entry[‘id’] ); $user->set_role( ‘subscriber’ ); global $wpdb; $wpdb->query( $wpdb->prepare( “UPDATE $wpdb->posts SET post_status=”draft” WHERE post_author = %d AND post_status IN (‘publish’, ‘future’)”, $user->ID ) ); } add_action( … Read more

how to give a user a role?

or / NOTE: Of course change 3 to the appropriate user ID $u = new WP_User( 3 ); // Remove role $u->remove_role( ‘subscriber’ ); // Add role $u->add_role( ‘editor’ ); Super Admin – somebody with access to the site network administration features and all other features. See the Create a Network article. Administrator – somebody … Read more

WordPress capabilities and restricted categories access

I think best hook should be ‘template_redirect’, when this hook is fired main query is already set, so you can look at queried object and if the user has no required capability you can redirect request somewhere: add_action( ‘template_redirect’, function() { if ( ( is_category( ‘special-category’ ) || is_singular() && has_category( ‘special-category’, get_queried_object() ) ) … Read more

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