Tag Info

New answers tagged

1

The currently logged in user The \WP_User object/instance can be retrieved via: $user = get_current_user(); There's a shortcut API wrapper to fetch the ID: $user_id = get_current_user_id(); $wpdb and the WP "DBAL" WP basically uses $wpdb as DBAL/Database Abstraction Layer. It got plenty of public methods and some higher level wrappers for convenient ...


0

You need to pass the $profileuser->ID as the second argument when you call your function and define it accordingly: add_filter('wp_handle_upload_prefilter', 'my_pre_upload', 2, 2); // (3rd param is priority, 4th is number of args) // and pass the $userid as argument to your function function my_pre_upload($file, $userid = false){ // if no user ...


1

Check out get_users(): $subscriber_ids = get_users( array( 'fields' => 'ids', 'role' => 'subscriber', ) ); foreach ( $subscriber_ids as $id ) echo "$id<br />";


0

I recommend backing up the database before making any major/bulk changes to it. First you need to get all users with the role "contributors", then update their roles to "author". $contributors = get_users(array('role'=>'contributor')); foreach($contributors as $contributor){ wp_update_user(array( 'ID' => $contributor->ID, 'role' => ...


0

If you can stick to overriding just functions that are located in wp-includes/pluggable.php then you should be able to avoid any kind of plugin conflicts ... unless you are using plugins that are overriding the same pluggable functions. Just make sure that your functions are declared before pluggables is loaded. Plugins are loaded before the pluggables file ...


0

Best way to find if a code works or not is to actually try it ;) On the face of it, it doesn't look like you are trying to handle storing the user ids in an array or any serialized way at all.


0

Might be overkill, but you might want to take a look at BuddyPress - it's an actively developed project that extends WordPress with social networking features.


1

As noted at the codex page for get_user_meta(): NOTE If the meta value does not exist and $single is true the function will return an empty string. If $single is false an empty array is returned. So I would suggest to do the check like this: ! empty( $themeta ) Regrading your other question, you can save the array by simply doing it like ...


5

I am not sure why your query is returning more IDs than necessary. The $args for get_users look correct. By default get_users does not support orderby=rand, but you can overwrite that option. See below: function random_user_query( &$query ) { $query->query_orderby = "ORDER BY RAND()"; } // Usage: [random_users how_many = 3] add_shortcode( ...


0

Quoting from the WordPress VIP Development Best Practices: Remember that the database is not a tool box. Although you might be able to perform a lot of work on the database side, your code will scale much better by keeping database queries simple and performing necessary calculations and logic in PHP. That said, you might just try to get all ...


-1

It was a bug in Wordpress. Please see this track ticket #21581 for details.



Top 50 recent answers are included