Categories
Code WordPress

Use Wildcards with WP_User_Query to Search for WordPress Users

Information about how to use the wildcard user search in WP to properly populate things like JSON arrays for use with autocomplete JS.

WP_User_Query()

<?php
/**
* Search for users by name and return a JSON object of matches
*
* An example method that demonstrates how to use wildcards (*'s) when
* looking up users. This particular example would be used to create
* a new endpoint that would output a JSON array of returned users.
* Something like this would be useful for JS autocomplete queries.
*/
function skw_user_autocomplete( $search_term ) {
// Note the astrisks
$user_query = new WP_User_Query( array(
'search' => '*' . $search_term . '*',
) );
// Get the results from the query, returning the first user
$users = $user_query->get_results();
$user_ids = array();
foreach( $users as $user ) {
$user_ids[] = array(
'ID' => $user->data->ID,
'label' => $user->data->user_login,
'display_name' => $user->data->display_name
);
}
header( 'Content-Type: application/x-json' );
echo $json = json_encode( $user_ids );
die;
}
Categories
WordPress WordPress Plugins

BuddyPress Amigos Automáticos está agora disponível em Português!

BuddyPress Automatic Friends  is now available in Portugeuse thanks to Renato Alves!

Categories
Raspberry Pi

Access Raspbian SD Cards in OSX

OSX does not provide native support for EXT2 and EXT3 file systems, thus preventing access to the data contained within.

raspberry-pi-and-sd-card-800x800For my first Raspberry Pi project, I had decided that I would attempt to create a speech-to-text-to-speech background service. For this concept, my Raspbian install needed to run headless, access a wireless network, and possess the ability to record and playback audio files.

In the early stages of the project, I was in the process of editing files within /etc/init.d, (initializes system processes during boot) and I made a code error in my script.  Since this script was configured to run during the boot process, when it crashed, it prevented the SSH server daemon from running.  Unable to use SSH and without access to a monitor, I began looking into a way to read my Raspbian file system from within OSX.

Through my research, I came across a solution that is relatively easy, but requires a few minutes to setup initially. First, you will need to download and install VirtualBox and install an image of your favorite linux distro.  I used Elementary OS since Raspbian will not run on x86 architecture, but Debian or Ubuntu should work just as well.  Once you have a virtual machine up and running, you will want to install Guest Additions to allow for access to USB devices.

Once installed, you can plug your EXT2/3 formatted SD card into an USB card reader and insert it into your Mac.  You will now need to “eject” any of the freshly mounted partitions in OSX in order to free them for use within the virtual machine.  Once ejected from within OSX, USB devices can be enabled from VirualBox’s Devices menu.

Using this process, I was able to mount my Raspbian partitions to /media/root/ from within VirtualBox and update my erroneous scripts. Good luck!

Categories
WordPress WordPress Plugins

Amigos automáticos BuddyPress ahora está disponible en español!

BuddyPress Automatic Friends  is now available in Spanish thanks to Maria Ramos!

Categories
WordPress WordPress Plugins

Plugin Update: BuddyPress Automatic Friends v2.0.0

BuddyPress Automatic Friends version 2.0.0 is now available.

What’s new in version 2.0.0

* Major OOP rewrite
* Admin Menu compliance with modern BuddyPress versions
* Themes options page
* Adds donate links
* Autocomplete on Global Friend suggestions
* Ajax actions for adding/removing global friends
* General beautification

screenshot-1

screenshot-2