function mk_run_comment_optimizer($data) { // print_r($data->comments); $users = array(); foreach ($data->comments as $post) { $users[] = $post->user_id; } cache_users($users); }
function email_post_changes_emails($emails, $post_before, $post_after) { $post = get_post($post_after); $users = get_post_meta($post->ID, '_wporg_watchlist', true); if (!$users) { return $emails; } cache_users($users); $users = array_filter(array_map('get_userdata', $users)); foreach ($users as $user) { $emails[] = $user->user_email; } return $emails; }
/** * Prepare revisions for JavaScript. * * @since 3.6.0 * * @param object $post The post object. * @param int $selected_revision_id The selected revision id. * @param int $from (optional) The revision id to compare from. * * @return array An associative array of revision data and related settings. */ function wp_prepare_revisions_for_js($post, $selected_revision_id, $from = null) { $post = get_post($post); $revisions = $authors = array(); $now_gmt = time(); $revisions = wp_get_post_revisions($post->ID, array('order' => 'ASC', 'check_enabled' => false)); // If revisions are disabled, we only want autosaves and the current post. if (!wp_revisions_enabled($post)) { foreach ($revisions as $revision_id => $revision) { if (!wp_is_post_autosave($revision)) { unset($revisions[$revision_id]); } } $revisions = array($post->ID => $post) + $revisions; } $show_avatars = get_option('show_avatars'); cache_users(wp_list_pluck($revisions, 'post_author')); $can_restore = current_user_can('edit_post', $post->ID); foreach ($revisions as $revision) { $modified = strtotime($revision->post_modified); $modified_gmt = strtotime($revision->post_modified_gmt); if ($can_restore) { $restore_link = str_replace('&', '&', wp_nonce_url(add_query_arg(array('revision' => $revision->ID, 'action' => 'restore'), admin_url('revision.php')), "restore-post_{$revision->ID}")); } if (!isset($authors[$revision->post_author])) { $authors[$revision->post_author] = array('id' => (int) $revision->post_author, 'avatar' => $show_avatars ? get_avatar($revision->post_author, 32) : '', 'name' => get_the_author_meta('display_name', $revision->post_author)); } $autosave = (bool) wp_is_post_autosave($revision); $current = !$autosave && $revision->post_modified_gmt === $post->post_modified_gmt; if ($current && !empty($current_id)) { // If multiple revisions have the same post_modified_gmt, highest ID is current. if ($current_id < $revision->ID) { $revisions[$current_id]['current'] = false; $current_id = $revision->ID; } else { $current = false; } } elseif ($current) { $current_id = $revision->ID; } $revisions[$revision->ID] = array('id' => $revision->ID, 'title' => get_the_title($post->ID), 'author' => $authors[$revision->post_author], 'date' => date_i18n(__('M j, Y @ G:i'), $modified), 'dateShort' => date_i18n(_x('j M @ G:i', 'revision date short format'), $modified), 'timeAgo' => sprintf(__('%s ago'), human_time_diff($modified_gmt, $now_gmt)), 'autosave' => $autosave, 'current' => $current, 'restoreUrl' => $can_restore ? $restore_link : false); } // If a post has been saved since the last revision (no revisioned fields were changed) // we may not have a "current" revision. Mark the latest revision as "current". if (empty($current_id)) { if ($revisions[$revision->ID]['autosave']) { $revision = end($revisions); while ($revision['autosave']) { $revision = prev($revisions); } $current_id = $revision['id']; } else { $current_id = $revision->ID; } $revisions[$current_id]['current'] = true; } // Now, grab the initial diff $compare_two_mode = is_numeric($from); if (!$compare_two_mode) { $found = array_search($selected_revision_id, array_keys($revisions)); if ($found) { $from = array_keys(array_slice($revisions, $found - 1, 1, true)); $from = reset($from); } else { $from = 0; } } $from = absint($from); $diffs = array(array('id' => $from . ':' . $selected_revision_id, 'fields' => wp_get_revision_ui_diff($post->ID, $from, $selected_revision_id))); return array('postId' => $post->ID, 'nonce' => wp_create_nonce('revisions-ajax-nonce'), 'revisionData' => array_values($revisions), 'to' => $selected_revision_id, 'from' => $from, 'diffData' => $diffs, 'baseUrl' => parse_url(admin_url('revision.php'), PHP_URL_PATH), 'compareTwoMode' => absint($compare_two_mode), 'revisionIds' => array_keys($revisions)); }
/** * Execute the query, with the current variables. * * @since 3.1.0 * * @global wpdb $wpdb WordPress database abstraction object. */ public function query() { global $wpdb; $qv =& $this->query_vars; $this->request = "SELECT {$this->query_fields} {$this->query_from} {$this->query_where} {$this->query_orderby} {$this->query_limit}"; if (is_array($qv['fields']) || 'all' == $qv['fields']) { $this->results = $wpdb->get_results($this->request); } else { $this->results = $wpdb->get_col($this->request); } /** * Filter SELECT FOUND_ROWS() query for the current WP_User_Query instance. * * @since 3.2.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. */ if (isset($qv['count_total']) && $qv['count_total']) { $this->total_users = $wpdb->get_var(apply_filters('found_users_query', 'SELECT FOUND_ROWS()')); } if (!$this->results) { return; } if ('all_with_meta' == $qv['fields']) { cache_users($this->results); $r = array(); foreach ($this->results as $userid) { $r[$userid] = new WP_User($userid, '', $qv['blog_id']); } $this->results = $r; } elseif ('all' == $qv['fields']) { foreach ($this->results as $key => $user) { $this->results[$key] = new WP_User($user, '', $qv['blog_id']); } } }
/** * Execute the query, with the current variables * * @since 3.1.0 * @access private */ function query() { global $wpdb; if (is_array($this->query_vars['fields']) || 'all' == $this->query_vars['fields']) { $this->results = $wpdb->get_results("SELECT {$this->query_fields} {$this->query_from} {$this->query_where} {$this->query_orderby} {$this->query_limit}"); } else { $this->results = $wpdb->get_col("SELECT {$this->query_fields} {$this->query_from} {$this->query_where} {$this->query_orderby} {$this->query_limit}"); } if ($this->query_vars['count_total']) { $this->total_users = $wpdb->get_var(apply_filters('found_users_query', 'SELECT FOUND_ROWS()')); } if (!$this->results) { return; } if ('all_with_meta' == $this->query_vars['fields']) { cache_users($this->results); $r = array(); foreach ($this->results as $userid) { $r[$userid] = new WP_User($userid, '', $this->query_vars['blog_id']); } $this->results = $r; } }
/** * Prepare revisions for JavaScript. * * @since 3.6.0 * * @param object|int $post The post object. Also accepts a post ID. * @param int $selected_revision_id The selected revision ID. * @param int $from Optional. The revision ID to compare from. * * @return array An associative array of revision data and related settings. */ function wp_prepare_revisions_for_js($post, $selected_revision_id, $from = null) { $post = get_post($post); $authors = array(); $now_gmt = time(); $revisions = wp_get_post_revisions($post->ID, array('order' => 'ASC', 'check_enabled' => false)); // If revisions are disabled, we only want autosaves and the current post. if (!wp_revisions_enabled($post)) { foreach ($revisions as $revision_id => $revision) { if (!wp_is_post_autosave($revision)) { unset($revisions[$revision_id]); } } $revisions = array($post->ID => $post) + $revisions; } $show_avatars = get_option('show_avatars'); cache_users(wp_list_pluck($revisions, 'post_author')); $can_restore = current_user_can('edit_post', $post->ID); $current_id = false; foreach ($revisions as $revision) { $modified = strtotime($revision->post_modified); $modified_gmt = strtotime($revision->post_modified_gmt); if ($can_restore) { $restore_link = str_replace('&', '&', wp_nonce_url(add_query_arg(array('revision' => $revision->ID, 'action' => 'restore'), admin_url('revision.php')), "restore-post_{$revision->ID}")); } if (!isset($authors[$revision->post_author])) { $authors[$revision->post_author] = array('id' => (int) $revision->post_author, 'avatar' => $show_avatars ? get_avatar($revision->post_author, 32) : '', 'name' => get_the_author_meta('display_name', $revision->post_author)); } $autosave = (bool) wp_is_post_autosave($revision); $current = !$autosave && $revision->post_modified_gmt === $post->post_modified_gmt; if ($current && !empty($current_id)) { // If multiple revisions have the same post_modified_gmt, highest ID is current. if ($current_id < $revision->ID) { $revisions[$current_id]['current'] = false; $current_id = $revision->ID; } else { $current = false; } } elseif ($current) { $current_id = $revision->ID; } $revisions_data = array('id' => $revision->ID, 'title' => get_the_title($post->ID), 'author' => $authors[$revision->post_author], 'date' => date_i18n(__('M j, Y @ H:i'), $modified), 'dateShort' => date_i18n(_x('j M @ H:i', 'revision date short format'), $modified), 'timeAgo' => sprintf(__('%s ago'), human_time_diff($modified_gmt, $now_gmt)), 'autosave' => $autosave, 'current' => $current, 'restoreUrl' => $can_restore ? $restore_link : false); /** * Filter the array of revisions used on the revisions screen. * * @since 4.4.0 * * @param array $revisions_data { * The bootstrapped data for the revisions screen. * * @type int $id Revision ID. * @type string $title Title for the revision's parent WP_Post object. * @type int $author Revision post author ID. * @type string $date Date the revision was modified. * @type string $dateShort Short-form version of the date the revision was modified. * @type string $timeAgo GMT-aware amount of time ago the revision was modified. * @type bool $autosave Whether the revision is an autosave. * @type bool $current Whether the revision is both not an autosave and the post * modified date matches the revision modified date (GMT-aware). * @type bool|false $restoreUrl URL if the revision can be restored, false otherwise. * } * @param WP_Post $revision The revision's WP_Post object. * @param WP_Post $post The revision's parent WP_Post object. */ $revisions[$revision->ID] = apply_filters('wp_prepare_revision_for_js', $revisions_data, $revision, $post); } /** * If we only have one revision, the initial revision is missing; This happens * when we have an autsosave and the user has clicked 'View the Autosave' */ if (1 === sizeof($revisions)) { $revisions[$post->ID] = array('id' => $post->ID, 'title' => get_the_title($post->ID), 'author' => $authors[$post->post_author], 'date' => date_i18n(__('M j, Y @ H:i'), strtotime($post->post_modified)), 'dateShort' => date_i18n(_x('j M @ H:i', 'revision date short format'), strtotime($post->post_modified)), 'timeAgo' => sprintf(__('%s ago'), human_time_diff(strtotime($post->post_modified_gmt), $now_gmt)), 'autosave' => false, 'current' => true, 'restoreUrl' => false); $current_id = $post->ID; } /* * If a post has been saved since the last revision (no revisioned fields * were changed), we may not have a "current" revision. Mark the latest * revision as "current". */ if (empty($current_id)) { if ($revisions[$revision->ID]['autosave']) { $revision = end($revisions); while ($revision['autosave']) { $revision = prev($revisions); } $current_id = $revision['id']; } else { $current_id = $revision->ID; } $revisions[$current_id]['current'] = true; } // Now, grab the initial diff. $compare_two_mode = is_numeric($from); if (!$compare_two_mode) { $found = array_search($selected_revision_id, array_keys($revisions)); if ($found) { $from = array_keys(array_slice($revisions, $found - 1, 1, true)); $from = reset($from); } else { $from = 0; } } $from = absint($from); $diffs = array(array('id' => $from . ':' . $selected_revision_id, 'fields' => wp_get_revision_ui_diff($post->ID, $from, $selected_revision_id))); return array('postId' => $post->ID, 'nonce' => wp_create_nonce('revisions-ajax-nonce'), 'revisionData' => array_values($revisions), 'to' => $selected_revision_id, 'from' => $from, 'diffData' => $diffs, 'baseUrl' => parse_url(admin_url('revision.php'), PHP_URL_PATH), 'compareTwoMode' => absint($compare_two_mode), 'revisionIds' => array_keys($revisions)); }
break; default: if (!empty($_GET['_wp_http_referer'])) { wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']))); exit; } include './admin-header.php'; $usersearch = isset($_GET['usersearch']) ? $_GET['usersearch'] : null; $userspage = isset($_GET['userspage']) ? $_GET['userspage'] : null; $role = isset($_GET['role']) ? $_GET['role'] : null; // Query the user IDs for this page $wp_user_search = new WP_User_Search($usersearch, $userspage, $role); // Query the post counts for this page $post_counts = count_many_users_posts($wp_user_search->get_results()); // Query the users for this page cache_users($wp_user_search->get_results()); $messages = array(); if (isset($_GET['update'])) { switch ($_GET['update']) { case 'del': case 'del_many': $delete_count = isset($_GET['delete_count']) ? (int) $_GET['delete_count'] : 0; $messages[] = '<div id="message" class="updated"><p>' . sprintf(_n('%s user deleted', '%s users deleted', $delete_count), $delete_count) . '</p></div>'; break; case 'add': $messages[] = '<div id="message" class="updated"><p>' . __('New user created.') . '</p></div>'; break; case 'promote': $messages[] = '<div id="message" class="updated"><p>' . __('Changed roles.') . '</p></div>'; break; case 'err_admin_role':
/** * Execute the query, with the current variables * * @since 3.1.0 * @access private */ function query() { global $wpdb; $qv =& $this->query_vars; if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) { $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"); } else { $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"); } if ( $qv['count_total'] ) $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); if ( !$this->results ) return; if ( 'all_with_meta' == $qv['fields'] ) { cache_users( $this->results ); $r = array(); foreach ( $this->results as $userid ) $r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] ); $this->results = $r; } elseif ( 'all' == $qv['fields'] ) { foreach ( $this->results as $key => $user ) { $this->results[ $key ] = new WP_User( $user ); } } }
public function getSubscribedUsers($post_id) { $users = $this->_wpdb->get_col('SELECT user_id FROM ' . self::EMAIL_TABLE_STRING . ' WHERE type = "' . self::BLOG_COMMENT_STRING . '" AND item_id = ' . $post_id); if (empty($users)) { return false; } cache_users($users); return $users; }
function query() { global $wpdb; global $WishListMemberInstance; $qv =& $this->query_vars; // We will only sort by level registration date if we're filtering by membership level $level = $this->additional_filters['level']; if (!empty($level) && $level != 'incomplete' && $level != 'nonmembers') { //** REMOVE this part of the code because this was handled by the prepare_query ABOVE // if ($this->search_term) { // $searches = array(); // $term_search = '('; // foreach (array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col) // $searches[] = $col . " LIKE '%$this->search_term%'"; // $term_search .= implode(' OR ', $searches); // $term_search .= ')'; // $search_sql[] = $term_search; // } // $search_sql[] = $wpdb->prepare("ul.level_id=%d", $level); // if(!empty($search_sql)) { // $search_sql = ' WHERE ' . implode(' AND ' , $search_sql); // } // **** THE CODE AFTER THIS LINE REMOVES THE PREVIOUS WHERE QUERY //$this->query_where = "$search_sql"; $this->query_from = " FROM {$wpdb->users}" . " LEFT JOIN {$WishListMemberInstance->Tables->userlevels} ul on ({$wpdb->users}.ID=ul.user_id)" . " LEFT JOIN {$WishListMemberInstance->Tables->userlevel_options} ulo on (ulo.userlevel_id=ul.ID)" . " LEFT JOIN {$WishListMemberInstance->Tables->user_options} uo on ({$wpdb->users}.ID=uo.user_id)"; $query = "SELECT DISTINCT({$wpdb->users}.ID), ulo.option_value, ulo.option_name {$this->query_from} {$this->query_where} {$this->query_orderby} {$this->query_limit}"; $unprocessed_data = $wpdb->get_results($query, ARRAY_A); // Run this query without limit so we can get the total count of users found, (For Pagination) $wpdb->get_results("SELECT DISTINCT({$wpdb->users}.ID), ulo.option_value, ulo.option_name {$this->query_from} {$this->query_where} {$this->query_orderby} "); $levels_data = array(); // loop through results and convert date to timestamp for easier sorting foreach ($unprocessed_data as $data) { // if there's no registration_date, it means the level is not active, all non active members will // be at the bottom of the result, will be on top if sorted reveresed based on registration date if ($data['option_name'] == 'registration_date') { $date = explode("#", $data['option_value']); $timestamp = strtotime($date[0]); } else { $timestamp = strtotime(time()); } $levels_data[$timestamp . '-' . $data['ID']] = $data['ID']; } if ($this->SortOrder == 'ASC') { ksort($levels_data); } else { krsort($levels_data); } $this->results = $levels_data; } else { $query = "SELECT {$this->query_fields} {$this->query_from} {$this->query_where} {$this->query_orderby} {$this->query_limit}"; if (is_array($qv['fields']) || 'all' == $qv['fields']) { $this->results = $wpdb->get_results($query); } else { $this->results = $wpdb->get_col($query); } } /** * Filter SELECT FOUND_ROWS() query for the current WP_User_Query instance. * * @since 3.2.0 * * @global wpdb $wpdb WordPress database object. * * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. */ if (isset($qv['count_total']) && $qv['count_total']) { $this->total_users = $wpdb->get_var(apply_filters('found_users_query', 'SELECT FOUND_ROWS()')); } if (!$this->results) { return; } if ('all_with_meta' == $qv['fields']) { cache_users($this->results); $r = array(); foreach ($this->results as $userid) { $r[$userid] = new WP_User($userid, '', $qv['blog_id']); } $this->results = $r; } elseif ('all' == $qv['fields']) { foreach ($this->results as $key => $user) { $this->results[$key] = new WP_User($user); } } }
/** * Execute the query, with the current variables * * @since 3.1.0 * @access private */ function query() { global $wpdb; $this->results = $wpdb->get_col("SELECT DISTINCT({$wpdb->users}.ID)" . $this->query_from . $this->query_where . $this->query_orderby . $this->query_limit); if (!$this->results) { return; } if ($this->query_vars['count_total']) { $this->total_users = $wpdb->get_var("SELECT COUNT(DISTINCT({$wpdb->users}.ID))" . $this->query_from . $this->query_where); } if ('all' == $this->query_vars['fields']) { cache_users($this->results); $r = array(); foreach ($this->results as $userid) { $r[$userid] = new WP_User($userid); } $this->results = $r; } }
function notify($new_status, $old_status, $post) { global $current_site; if ('answer' != $post->post_type || 'publish' != $new_status || $new_status == $old_status) { return; } $author = get_userdata($post->post_author); $question_id = $post->post_parent; $question = get_post($question_id); $subscribers = get_post_meta($question_id, '_sub'); if (!in_array($question->post_author, $subscribers)) { $subscribers[] = $question->post_author; } // Notify question author too $subject = sprintf(__('[%s] New answer on "%s"'), get_option('blogname'), $question->post_title); $content = sprintf(__('%s added a new answer to %s:', QA_TEXTDOMAIN), _qa_html('a', array('href' => qa_get_url('user', $post->post_author)), $author->user_nicename), _qa_html('a', array('href' => qa_get_url('single', $question_id)), get_post_field('post_title', $question_id))); $content .= "<br/><br/>" . $post->post_content . "<br/><br/>"; cache_users($subscribers); $admin_email = get_site_option('admin_email'); if ($admin_email == '') { $admin_email = 'admin@' . $current_site->domain; } $from_email = $admin_email; $message_headers = "MIME-Version: 1.0\n" . "From: " . $current_site->site_name . " <{$from_email}>\n" . "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n"; foreach ($subscribers as $subscriber_id) { // Don't notify the author of the answer if ($post->post_author != $subscriber_id) { $msg = $content . sprintf(__('To manage your subscription, visit <a href="%s">the question</a>.', QA_TEXTDOMAIN), qa_get_url('single', $post->ID)); } else { $msg = $content; } wp_mail(get_user_option('user_email', $subscriber_id), $subject, $msg, $message_headers); } }