Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Change the query retrieves the user list #6

Merged
merged 4 commits into from

2 participants

@foxrain

No description provided.

and others added some commits
@rilwis Small improvement in code
Version 2.1.8: fix translation
6f66829
@rilwis Small improvement in code
Version 2.1.8: fix translation
30517ed
@rilwis Version 2.1.9 5a4214f
@foxrain foxrain Change the query retrieves the user list
+ use function: get_users for get user
+ add hook in file pm4wp.php
95da129
@rilwis rilwis merged commit d8c5ce3 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 2, 2012
  1. @foxrain

    Small improvement in code

    authored foxrain committed
    Version 2.1.8: fix translation
  2. @foxrain

    Small improvement in code

    authored foxrain committed
    Version 2.1.8: fix translation
  3. @foxrain

    Version 2.1.9

    authored foxrain committed
Commits on Nov 5, 2012
  1. @foxrain

    Change the query retrieves the user list

    foxrain authored
    + use function: get_users for get user
    + add hook in file pm4wp.php
This page is out of date. Refresh to see the latest.
Showing with 179 additions and 158 deletions.
  1. +4 −0 README.md
  2. +1 −0  css/style.css
  3. +16 −12 inc/send-page.php
  4. +153 −145 pm4wp.php
  5. +5 −1 readme.txt
View
4 README.md
@@ -22,6 +22,10 @@ Also, an email is sent to user when a new PM is received. Email template is full
### Changelog
+### 2.1.8
+
+* Bug fix: Load translation
+
### 2.1.7
* Improvement: Show notification in admin bar
View
1  css/style.css
@@ -3,4 +3,5 @@
}
.form-table select {
height: auto;
+ width: 99%;
}
View
28 inc/send-page.php
@@ -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.7
-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 ( empty( $num_unread ) )
- {
- $num_unread = 0;
- }
-
- if ( $num_unread )
- {
- echo '<div id="message" class="error"><p><b>', sprintf( _n( 'You have %d new message!', 'You have %d new messages!', $num_unread, 'pm4wp' ), $num_unread ), '</b> <a href="admin.php?page=rwpm_inbox">', __( 'Click here to go to inbox', 'pm4wp' ), ' &raquo;</a></p></div>';
- }
-}
-
-/**
- * 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 ) );
+}
View
6 readme.txt
@@ -4,7 +4,7 @@ Donate link: http://www.deluxeblogtips.com/donate
Tags: pm, private message, private messages, message, messages
Requires at least: 3.0
Tested up to: 3.4.2
-Stable tag: 2.1.7
+Stable tag: 2.1.9
The Private Messages For WordPress allows users of WordPress blog send private messages (PM) to each other, just like in a forum.
@@ -76,6 +76,10 @@ Note: the template file is just the backbone, you should modify it to fit your t
== Changelog ==
+= 2.1.8 =
+
+* Bug fix: Load translation
+
= 2.1.7 =
* Improvement: Show notification in admin bar
Something went wrong with that request. Please try again.