Permalink
Browse files

seeding

  • Loading branch information...
etivite committed Jan 7, 2012
0 parents commit eb6578496f2d267ea6bcd94d9df42c35119f9364
Showing with 399 additions and 0 deletions.
  1. +219 −0 admin/bp-pending-activations-admin.php
  2. +71 −0 bp-pending-activations-loader.php
  3. +35 −0 bp-pending-activations.php
  4. +74 −0 readme.txt
@@ -0,0 +1,219 @@
+<?php
+
+function etivite_bp_pending_activations_users() {
+ global $wpdb;
+
+ return $wpdb->get_results( $wpdb->prepare( "SELECT u.*, m1.meta_value as activation_key FROM $wpdb->usermeta m1, $wpdb->users u WHERE u.ID = m1.user_id AND u.user_status = 2 AND m1.meta_key = 'activation_key' ORDER BY u.user_registered ASC" ) );
+}
+
+function etivite_bp_pending_activations_users_resent( $user_id ) {
+ global $wpdb;
+
+ return $wpdb->get_row( $wpdb->prepare( "SELECT meta_value as activation_key_resent FROM $wpdb->usermeta WHERE meta_key = 'activation_key_resent' AND user_id = %d", $user_id ) );
+}
+
+function etivite_bp_pending_activations_admin() {
+ global $bp, $wpdb;
+
+ if ( is_multisite() )
+ wp_die( __('This plugin is for single WordPress installs only w/BuddyPress') );
+
+ /* If the form has been submitted and the admin referrer checks out, save the settings */
+ if ( isset( $_POST['submit'] ) && check_admin_referer('etivite_bp_pending_activations_admin') ) {
+
+ if ( isset($_POST['action'] ) && !empty( $_POST['action'] ) && !empty( $_POST['users'] ) ) {
+
+ $userids = $_POST['users'];
+
+ if ( $_POST['action'] == 'delete' ) {
+
+ if ( !current_user_can( 'delete_users' ) )
+ wp_die(__('You can&#8217;t delete users.'));
+
+ foreach ( (array) $userids as $id) {
+
+ $id = (int) $id;
+
+ if ( !current_user_can( 'delete_user', $id ) )
+ wp_die(__( 'You can&#8217;t delete that user.' ) );
+
+ if ( is_super_admin( $id ) )
+ wp_die(__( 'You can&#8217;t delete that user.' ) );
+
+ if ( $id == $current_user->ID )
+ wp_die(__( 'You can&#8217;t delete that user.' ) );
+
+ wp_delete_user($id);
+
+ }
+
+ wp_cache_delete( 'etivite_bp_pending_activations_count' );
+ $deleteupdated = true;
+
+ } else if ( $_POST['action'] == 'resend' ) {
+
+ if ( is_array( $userids ) )
+ $userids = implode( ',', $userids );
+
+ $userids = $wpdb->escape( $userids );
+
+ if ( empty( $userids ) )
+ wp_die(__( 'No users selected' ) );
+
+ $resendusers = $wpdb->get_results( $wpdb->prepare( "SELECT m.meta_value, u.ID, u.user_email FROM $wpdb->usermeta m, $wpdb->users u WHERE u.ID = m.user_id AND m.meta_key = 'activation_key' AND u.ID IN ({$userids})" ) );
+
+ foreach ( $resendusers as $resend ) {
+
+ bp_core_signup_send_validation_email( $resend->ID, $resend->user_email, $resend->meta_value );
+
+ update_user_meta( $resend->ID, 'activation_key_resent', gmdate('Y-m-d H:i:s') );
+
+ }
+
+ $resendupdated = true;
+
+ } else if ( $_POST['action'] == 'activate' ) {
+
+ if ( is_array( $userids ) )
+ $userids = implode( ',', $userids );
+
+ $userids = $wpdb->escape( $userids );
+
+ if ( empty( $userids ) )
+ wp_die(__( 'No users selected' ) );
+
+ $resendusers = $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, m.meta_value FROM $wpdb->usermeta m, $wpdb->users u WHERE u.ID = m.user_id AND m.meta_key = 'activation_key' AND u.ID IN ({$userids})" ) );
+
+ foreach ( $resendusers as $resend ) {
+
+ /* Activate the signup */
+ $user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $resend->meta_value ) );
+
+ /* If there was errors, add a message and redirect */
+ if ( !empty( $user->errors ) )
+ echo 'There was an error activating this account, please try again: '. $resend->user_login;
+
+ /* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */
+ if ( file_exists( bp_core_avatar_upload_path() . '/avatars/signups/' . wp_hash( $user ) ) )
+ @rename( bp_core_avatar_upload_path() . '/avatars/signups/' . wp_hash( $user ), bp_core_avatar_upload_path() . '/avatars/' . $user );
+
+ }
+
+ wp_cache_delete( 'etivite_bp_pending_activations_count' );
+ $activateupdated = true;
+
+ }
+
+ }
+ }
+
+ // Get the proper URL for submitting the settings form. (Settings API workaround) - boone
+ $url_base = function_exists( 'is_network_admin' ) && is_network_admin() ? network_admin_url( 'admin.php?page=bp-pending-activations-settings' ) : admin_url( 'admin.php?page=bp-pending-activations-settings' );
+
+?>
+ <div class="wrap">
+
+ <div class="icon32" id="icon-users"><br></div>
+
+ <h2><?php echo sprintf( __('Pending Activations (%s) Admin'), etivite_bp_pending_activations_users_count() ); ?></h2>
+
+ <?php if ( isset($deleteupdated) ) : echo "<div id='message' class='updated fade'><p>" . __( 'Users Deleted.', 'bp-pending-activations' ) . "</p></div>"; endif; ?>
+ <?php if ( isset($resendupdated) ) : echo "<div id='message' class='updated fade'><p>" . __( 'Resent Activation Keys.', 'bp-pending-activations' ) . "</p></div>"; endif; ?>
+ <?php if ( isset($activateupdated) ) : echo "<div id='message' class='updated fade'><p>" . __( 'Users Activated.', 'bp-pending-activations' ) . "</p></div>"; endif; ?>
+
+ <form action="<?php echo $url_base ?>" name="bp-pending-activations-settings-form" id="bp-pending-activations-settings-form" method="post">
+
+ <div class="tablenav">
+
+ <div class="alignleft actions">
+ <select name="action">
+ <option selected="selected" value="">Bulk Actions</option>
+ <option value="delete">Delete User</option>
+ <option value="resend">Resend Key</option>
+ <option value="activate">Activate</option>
+ </select>
+ <input type="submit" class="button-secondary action" id="submit" name="submit" value="Apply">
+ </div>
+
+ <br class="clear">
+ </div>
+
+ <table cellspacing="0" class="widefat fixed">
+
+ <thead>
+ <tr class="thead">
+ <th class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th>
+ <th class="manage-column column-username" id="username" scope="col">Username</th>
+ <th class="manage-column column-name" id="name" scope="col">Name</th>
+ <th class="manage-column column-email" id="email" scope="col">E-mail</th>
+ <th class="manage-column column-date" id="date" scope="col">Date Registered</th>
+ <th class="manage-column column-date" id="rdate" scope="col">Date Resent</th>
+ </tr>
+ </thead>
+
+ <tfoot>
+ <tr class="thead">
+ <th class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th>
+ <th class="manage-column column-username" scope="col">Username</th>
+ <th class="manage-column column-name" scope="col">Name</th>
+ <th class="manage-column column-email" scope="col">E-mail</th>
+ <th class="manage-column column-date" scope="col">Date Registered</th>
+ <th class="manage-column column-date" scope="col">Date Resent</th>
+ </tr>
+ </tfoot>
+
+ <tbody class="list:user user-list" id="users">
+
+ <?php
+ $pending_users = etivite_bp_pending_activations_users();
+
+ foreach ( $pending_users as $user ) { ?>
+
+ <tr class="alternate" id="user-<?php echo $user->ID; ?>">
+ <th class="check-column" scope="row"><input type="checkbox" value="<?php echo $user->ID; ?>" id="user_<?php echo $user->ID; ?>" name="users[]"></th>
+ <td class="username column-username"><img width="32" height="32" class="avatar" alt="" src="http://www.gravatar.com/avatar/<?php echo md5( strtolower( $user->email ) ) . '?&amp;s=32'; ?>"> <?php echo $user->user_login; ?></td>
+ <td class="name column-name"><?php echo $user->display_name; ?></td>
+ <td class="email column-email"><?php echo $user->user_email; ?></td>
+ <td class="date column-date"><?php echo bp_core_time_since( $user->user_registered ); ?></td>
+ <td class="date column-date"><?php $resent = etivite_bp_pending_activations_users_resent($user->ID );
+
+ if ( $resent ) echo bp_core_time_since( $resent->activation_key_resent ); ?></td>
+ </tr>
+
+ <?php
+ }
+ ?>
+
+ </tbody>
+
+ </table>
+
+ <?php wp_nonce_field( 'etivite_bp_pending_activations_admin' ); ?>
+
+ </form>
+
+ <h3>About:</h3>
+ <div id="plugin-about" style="margin-left:15px;">
+
+ <p>
+ <a href="http://etivite.com/wordpress-plugins/buddypress-pending-activations/">Pending Activations - About Page</a><br/>
+ </p>
+
+ <div class="plugin-author">
+ <strong>Author:</strong> <a href="http://profiles.wordpress.org/users/etivite/"><img style="height: 24px; width: 24px;" class="photo avatar avatar-24" src="http://www.gravatar.com/avatar/9411db5fee0d772ddb8c5d16a92e44e0?s=24&amp;d=monsterid&amp;r=g" alt=""> rich @etivite</a><br/>
+ <a href="http://twitter.com/etivite">@etivite</a>
+ </div>
+
+ <p>
+ <a href="http://etivite.com">Author's site</a><br/>
+ <a href="http://etivite.com/api-hooks/">Developer Hook and Filter API Reference</a><br/>
+ <a href="http://etivite.com/wordpress-plugins/">WordPress Plugins</a><br/>
+ </p>
+ </div>
+
+
+ </div>
+<?php
+}
+
+?>
@@ -0,0 +1,71 @@
+<?php
+/*
+Plugin Name: BuddyPress Pending Activations
+Plugin URI: http://wordpress.org/extend/plugins/buddypress-pending-activations/
+Description: Manage pending member activations (keys) for main BuddyPress installation - (not for multisite blogs signups - yet.)
+Author: rich @etiviti
+Author URI: http://etivite.com
+License: GNU GENERAL PUBLIC LICENSE 3.0 http://www.gnu.org/licenses/gpl.txt
+Version: 0.5.2
+Text Domain: bp-pending-activations
+Network: true
+*/
+
+//http://wordpress.org/extend/plugins/unconfirmed/ - boone for overall wp and ms
+
+function etivite_bp_pending_activations_init() {
+
+ //don't load for MS
+ if ( is_multisite() )
+ return false;
+
+ if ( file_exists( dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' ) )
+ load_textdomain( 'bp-pending-activiations', dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' );
+
+ require( dirname( __FILE__ ) . '/bp-pending-activations.php' );
+
+ add_action( bp_core_admin_hook(), 'etivite_bp_pending_activations_admin_add_admin_menu' );
+
+}
+add_action( 'bp_include', 'etivite_bp_pending_activations_init', 88 );
+//add_action( 'bp_init', 'etivite_bp_pending_activations_init', 88 );
+
+//add admin_menu page
+function etivite_bp_pending_activations_admin_add_admin_menu() {
+ global $bp;
+
+ if ( !is_super_admin() )
+ return false;
+
+ //Add the component's administration tab under the "BuddyPress" menu for site administrators
+ require ( dirname( __FILE__ ) . '/admin/bp-pending-activations-admin.php' );
+
+ $count = sprintf( __('Pending Activations (%s)'), etivite_bp_pending_activations_users_count() );
+
+ add_submenu_page( 'bp-general-settings', __( 'Pending Activations', 'bp-pending-activations' ), $count, 'manage_options', 'bp-pending-activations-settings', 'etivite_bp_pending_activations_admin' );
+
+}
+
+/* Stolen from Welcome Pack - thanks, Paul! then stolen from boone*/
+function etivite_bp_pending_activations_admin_add_action_link( $links, $file ) {
+
+ //don't load for MS
+ if ( is_multisite() )
+ return $links;
+
+ if ( 'buddypress-pending-activations/bp-pending-activations-loader.php' != $file )
+ return $links;
+
+ if ( function_exists( 'bp_core_do_network_admin' ) ) {
+ $settings_url = add_query_arg( 'page', 'bp-pending-activations-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
+ } else {
+ $settings_url = add_query_arg( 'page', 'bp-pending-activations-settings', is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
+ }
+
+ $settings_link = '<a href="' . $settings_url . '">' . __( 'Settings', 'bp-activity-edit' ) . '</a>';
+ array_unshift( $links, $settings_link );
+
+ return $links;
+}
+add_filter( 'plugin_action_links', 'etivite_bp_pending_activations_admin_add_action_link', 10, 2 );
+?>
@@ -0,0 +1,35 @@
+<?php
+if ( !defined( 'ABSPATH' ) ) exit;
+
+function etivite_bp_pending_activations_activated_user( $user_id, $key, $user ) {
+
+ delete_user_meta( $user_id, 'activation_key_resent' );
+ wp_cache_delete( 'etivite_bp_pending_activations_count' );
+
+}
+add_action( 'bp_core_activated_user', 'etivite_bp_pending_activations_activated_user', 3, 3 );
+
+function etivite_bp_pending_activations_users_count() {
+ global $wpdb;
+
+ //if no cache is found
+ if ( !$count = wp_cache_get( 'etivite_bp_pending_activations_count', 'bp' ) ) {
+
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(u.ID) FROM $wpdb->usermeta m1, $wpdb->users u WHERE u.ID = m1.user_id AND u.user_status = 2 AND m1.meta_key = 'activation_key' ORDER BY u.user_registered ASC" ) );
+
+ if ( empty($count) ) $count = 0;
+
+ /* Cache the link */
+ if ( !empty( $count ) )
+ wp_cache_set( 'etivite_bp_pending_activations_count', $count, 'bp' );
+ }
+
+ return $count;
+}
+
+function etivite_bp_pending_activations_clear_cache() {
+ wp_cache_delete( 'etivite_bp_pending_activations_count' );
+}
+add_action( 'bp_core_signup_user', 'etivite_bp_pending_activations_clear_cache' );
+
+?>
Oops, something went wrong.

0 comments on commit eb65784

Please sign in to comment.