Permalink
Browse files

Change the query retrieves the user list

+ use function: get_users for get user
+ add hook in file pm4wp.php
  • Loading branch information...
1 parent 5a4214f commit 95da129f4ae36c7f9f774a7d52c5af4d01bd9db6 @foxrain foxrain committed Nov 5, 2012
Showing with 170 additions and 157 deletions.
  1. +1 −0 css/style.css
  2. +16 −12 inc/send-page.php
  3. +153 −145 pm4wp.php
View
@@ -3,4 +3,5 @@
}
.form-table select {
height: auto;
+ width: 99%;
}
View
@@ -162,35 +162,39 @@ function rwpm_send()
{
$id = $_GET['id'];
$msg = $wpdb->get_row( 'SELECT * FROM ' . $wpdb->prefix . 'pm WHERE `id` = "' . $id . '" LIMIT 1' );
-
+
$content = '<p>&nbsp;</p>';
$content .= '<p>---</p>';
$content .= '<p><em>' . __( 'In: ', 'pm4wp' ) . $msg->date . "\t" . $msg->sender . __( ' Wrote:', 'pm4wp' ) . '</em></p>';
$content .= wpautop( $msg->content );
$content = stripslashes( $content );
}
- // Get all users of blog
- $users = $wpdb->get_results( "SELECT display_name FROM $wpdb->users ORDER BY display_name ASC" );
-
+ // if auto suggest feature is turned on
if ( $option['type'] == 'autosuggest' )
- { // if auto suggest feature is turned on
+ {
?>
<input id="recipient" type="text" name="recipient" class="large-text" />
<?php
}
- else
- { // classic way: select recipient from dropdown list
+ else // classic way: select recipient from dropdown list
+ {
+ // Get all users of blog
+ $args = array(
+ 'order' => 'ASC',
+ 'orderby' => 'display_name' );
+ $values = get_users( $args );
+ $values = apply_filters( 'rwpm_recipients', $values );
?>
- <select name="recipient[]" multiple="multiple" size="5">
+ <select name="recipient[]" multiple="multiple" size="5">
<?php
- foreach ( $users as $user )
+ foreach ( $values as $value )
{
- $selected = ( $user->display_name == $recipient ) ? ' selected="selected"' : '';
- echo "<option value='$user->display_name'$selected>$user->display_name</option>";
+ $selected = ( $value->display_name == $recipient ) ? ' selected="selected"' : '';
+ echo "<option value='$value->display_name'$selected>$value->display_name</option>";
}
?>
- </select>
+ </select>
<?php
}
?>
View
298 pm4wp.php
@@ -1,145 +1,153 @@
-<?php
-/*
-Plugin Name: Private Messages For WordPress
-Plugin URI: http://www.deluxeblogtips.com/private-messages-for-wordpress
-Description: Allow members of WordPress blog send and receive private messages (PM)
-Version: 2.1.9
-Author: Rilwis
-Author URI: http://www.deluxeblogtips.com
-License: GNU GPL 2+
-*/
-
-// Prevent loading this file directly
-defined( 'ABSPATH' ) || exit;
-
-define( 'PM4WP_DIR', plugin_dir_path( __FILE__ ) );
-define( 'PM4WP_INC_DIR', trailingslashit( PM4WP_DIR . 'inc' ) );
-
-define( 'PM4WP_URL', plugin_dir_url( __FILE__ ) );
-define( 'PM4WP_CSS_URL', trailingslashit( PM4WP_URL . 'css' ) );
-define( 'PM4WP_JS_URL', trailingslashit( PM4WP_URL . 'js' ) );
-
-include_once PM4WP_INC_DIR . 'widget.php';
-include_once PM4WP_INC_DIR . 'inbox-page.php';
-include_once PM4WP_INC_DIR . 'send-page.php';
-include_once PM4WP_INC_DIR . 'outbox-page.php';
-
-if ( is_admin() )
-{
- include_once PM4WP_INC_DIR . 'options.php';
-}
-
-register_activation_hook( __FILE__, 'rwpm_activate' );
-add_action( 'plugins_loaded', 'rwpm_load_text_domain' );
-add_action( 'admin_notices', 'rwpm_notify' );
-add_action( 'admin_bar_menu', 'rwpm_adminbar', 300 );
-add_action( 'wp_ajax_rwpm_get_users', 'rwpm_get_users' );
-
-/**
- * Load plugin text domain
- *
- * @return void
- */
-function rwpm_load_text_domain()
-{
- load_plugin_textdomain( 'pm4wp', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
-}
-
-/**
- * Create table and register an option when activate
- *
- * @return void
- */
-function rwpm_activate()
-{
- global $wpdb;
-
- // Create table
- $query = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'pm (
- `id` bigint(20) NOT NULL auto_increment,
- `subject` text NOT NULL,
- `content` text NOT NULL,
- `sender` varchar(60) NOT NULL,
- `recipient` varchar(60) NOT NULL,
- `date` datetime NOT NULL,
- `read` tinyint(1) NOT NULL,
- `deleted` tinyint(1) NOT NULL,
- PRIMARY KEY (`id`)
- ) COLLATE utf8_general_ci;';
-
- // Note: deleted = 1 if message is deleted by sender, = 2 if it is deleted by recipient
-
- $wpdb->query( $query );
-
- // Default numbers of PM for each group
- $default_option = array(
- 'administrator' => 0,
- 'editor' => 50,
- 'author' => 20,
- 'contributor' => 10,
- 'subscriber' => 5,
- 'type' => 'dropdown', // How to choose recipient: dropdown list or autocomplete based on user input
- 'email_enable' => 1,
- 'email_name' => '%BLOG_NAME%',
- 'email_address' => '%BLOG_ADDRESS%',
- 'email_subject' => __( 'New PM at %BLOG_NAME%', 'pm4wp' ),
- 'email_body' => __( "You have new private message from <b>%SENDER%</b> at <b>%BLOG_NAME%</b>.\n\n<a href=\"%INBOX_URL%\">Click here</a> to go to your inbox.\n\nThis email is sent automatically. Please don't reply.", 'pm4wp' )
- );
- add_option( 'rwpm_option', $default_option, '', 'no' );
-}
-
-/**
- * Show notification of new PM
- */
-function rwpm_notify()
-{
- global $wpdb, $current_user;
-
- // get number of unread messages
- $num_unread = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'pm WHERE `recipient` = "' . $current_user->user_login . '" AND `read` = 0 AND `deleted` != "2"' );
-
- if ( !$num_unread )
- return;
-
- printf(
- '<div id="message" class="error"><p><b>%s</b> <a href="%s">%s</a></p></div>',
- sprintf( _n( 'You have %d new message!', 'You have %d new messages!', $num_unread, 'pm4wp' ), $num_unread ),
- admin_url( 'admin.php?page=rwpm_inbox' ),
- __( 'Click here to go to inbox', 'pm4wp' )
- );
-}
-
-/**
- * Show number of unread messages in admin bar
- */
-function rwpm_adminbar()
-{
- global $wp_admin_bar;
- global $wpdb, $current_user;
-
- // get number of unread messages
- $num_unread = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'pm WHERE `recipient` = "' . $current_user->user_login . '" AND `read` = 0 AND `deleted` != "2"' );
-
- if ( $num_unread && is_admin_bar_showing() )
- {
- $wp_admin_bar->add_menu( array(
- 'id' => 'rwpm',
- 'title' => sprintf( _n( 'You have %d new message!', 'You have %d new messages!', $num_unread, 'pm4wp' ), $num_unread ),
- 'href' => admin_url( 'admin.php?page=rwpm_inbox' ),
- 'meta' => array( 'class' => "rwpm_newmessages" ),
- ) );
- }
-}
-
-/**
- * Ajax callback function to get list of users
- */
-function rwpm_get_users()
-{
- global $wpdb;
-
- $keyword = trim( strip_tags( $_POST['term'] ) );
- $values = $wpdb->get_col( "SELECT DISTINCT display_name FROM {$wpdb->users} WHERE display_name LIKE '{$keyword}%'" );
-
- die( json_encode( $values ) );
-}
+<?php
+/*
+Plugin Name: Private Messages For WordPress
+Plugin URI: http://www.deluxeblogtips.com/private-messages-for-wordpress
+Description: Allow members of WordPress blog send and receive private messages (PM)
+Version: 2.1.9
+Author: Rilwis
+Author URI: http://www.deluxeblogtips.com
+License: GNU GPL 2+
+*/
+
+// Prevent loading this file directly
+defined( 'ABSPATH' ) || exit;
+
+define( 'PM4WP_DIR', plugin_dir_path( __FILE__ ) );
+define( 'PM4WP_INC_DIR', trailingslashit( PM4WP_DIR . 'inc' ) );
+
+define( 'PM4WP_URL', plugin_dir_url( __FILE__ ) );
+define( 'PM4WP_CSS_URL', trailingslashit( PM4WP_URL . 'css' ) );
+define( 'PM4WP_JS_URL', trailingslashit( PM4WP_URL . 'js' ) );
+
+include_once PM4WP_INC_DIR . 'widget.php';
+include_once PM4WP_INC_DIR . 'inbox-page.php';
+include_once PM4WP_INC_DIR . 'send-page.php';
+include_once PM4WP_INC_DIR . 'outbox-page.php';
+
+if ( is_admin() )
+{
+ include_once PM4WP_INC_DIR . 'options.php';
+}
+
+register_activation_hook( __FILE__, 'rwpm_activate' );
+add_action( 'plugins_loaded', 'rwpm_load_text_domain' );
+add_action( 'admin_notices', 'rwpm_notify' );
+add_action( 'admin_bar_menu', 'rwpm_adminbar', 300 );
+add_action( 'wp_ajax_rwpm_get_users', 'rwpm_get_users' );
+
+/**
+ * Load plugin text domain
+ *
+ * @return void
+ */
+function rwpm_load_text_domain()
+{
+ load_plugin_textdomain( 'pm4wp', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
+}
+
+/**
+ * Create table and register an option when activate
+ *
+ * @return void
+ */
+function rwpm_activate()
+{
+ global $wpdb;
+
+ // Create table
+ $query = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'pm (
+ `id` bigint(20) NOT NULL auto_increment,
+ `subject` text NOT NULL,
+ `content` text NOT NULL,
+ `sender` varchar(60) NOT NULL,
+ `recipient` varchar(60) NOT NULL,
+ `date` datetime NOT NULL,
+ `read` tinyint(1) NOT NULL,
+ `deleted` tinyint(1) NOT NULL,
+ PRIMARY KEY (`id`)
+ ) COLLATE utf8_general_ci;';
+
+ // Note: deleted = 1 if message is deleted by sender, = 2 if it is deleted by recipient
+
+ $wpdb->query( $query );
+
+ // Default numbers of PM for each group
+ $default_option = array(
+ 'administrator' => 0,
+ 'editor' => 50,
+ 'author' => 20,
+ 'contributor' => 10,
+ 'subscriber' => 5,
+ 'type' => 'dropdown', // How to choose recipient: dropdown list or autocomplete based on user input
+ 'email_enable' => 1,
+ 'email_name' => '%BLOG_NAME%',
+ 'email_address' => '%BLOG_ADDRESS%',
+ 'email_subject' => __( 'New PM at %BLOG_NAME%', 'pm4wp' ),
+ 'email_body' => __( "You have new private message from <b>%SENDER%</b> at <b>%BLOG_NAME%</b>.\n\n<a href=\"%INBOX_URL%\">Click here</a> to go to your inbox.\n\nThis email is sent automatically. Please don't reply.", 'pm4wp' )
+ );
+ add_option( 'rwpm_option', $default_option, '', 'no' );
+}
+
+/**
+ * Show notification of new PM
+ */
+function rwpm_notify()
+{
+ global $wpdb, $current_user;
+
+ // get number of unread messages
+ $num_unread = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'pm WHERE `recipient` = "' . $current_user->user_login . '" AND `read` = 0 AND `deleted` != "2"' );
+
+ if ( !$num_unread )
+ return;
+
+ printf(
+ '<div id="message" class="error"><p><b>%s</b> <a href="%s">%s</a></p></div>',
+ sprintf( _n( 'You have %d new message!', 'You have %d new messages!', $num_unread, 'pm4wp' ), $num_unread ),
+ admin_url( 'admin.php?page=rwpm_inbox' ),
+ __( 'Click here to go to inbox', 'pm4wp' )
+ );
+}
+
+/**
+ * Show number of unread messages in admin bar
+ */
+function rwpm_adminbar()
+{
+ global $wp_admin_bar;
+ global $wpdb, $current_user;
+
+ // get number of unread messages
+ $num_unread = (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'pm WHERE `recipient` = "' . $current_user->user_login . '" AND `read` = 0 AND `deleted` != "2"' );
+
+ if ( $num_unread && is_admin_bar_showing() )
+ {
+ $wp_admin_bar->add_menu( array(
+ 'id' => 'rwpm',
+ 'title' => sprintf( _n( 'You have %d new message!', 'You have %d new messages!', $num_unread, 'pm4wp' ), $num_unread ),
+ 'href' => admin_url( 'admin.php?page=rwpm_inbox' ),
+ 'meta' => array( 'class' => "rwpm_newmessages" ),
+ ) );
+ }
+}
+
+/**
+ * Ajax callback function to get list of users
+ */
+function rwpm_get_users()
+{
+ $keyword = trim( strip_tags( $_POST['term'] ) );
+ $values = array();
+ $args = array( 'search' => '*' . $keyword . '*',
+ 'fields' => 'all_with_meta' );
+ $results_search_users = get_users( $args );
+ $results_search_users = apply_filters( 'rwpm_recipients', $results_search_users );
+ if ( !empty( $results_search_users ) )
+ {
+ foreach ( $results_search_users as $result )
+ {
+ $values[] = $result->display_name;
+ }
+ }
+ die( json_encode( $values ) );
+}

0 comments on commit 95da129

Please sign in to comment.