• Resolved Malcolm

    (@malcolm-oph)


    This post details a customisation of this plugin which other users may find useful!

    I am developing a club website which will have “members only” pages, and am intending to use this plugin to import a my list of members. This will be done on a regular basis and will add any new members to the WP users database as they are added to the CSV file. As it stands the plugin does not provide a mechanism for identifying users that are no longer members, so I am intending to use the action and filter “hooks” to extend the plugin and provide this functionality. This adds a timestamp to each users meta data when their record is imported or updated by the plugin, and then any user records with old timestamps are listed along with a link to remove the user.

    I used the “Code Snippets” plugin to add my customisations, but they could also be added to the theme (or a child theme).

    Code is below:

    
    ****************************************************************************
    				Filters for input of Members CSV File
    ****************************************************************************
    */
    
    add_action('before_acui_import_users', 'FHGCBeforeUserImportData');
    
    function FHGCBeforeUserImportData()
    {
    	// Log the timestamp of the start of the user import process
    	global $acui_import_timestamp;
    	
    	$acui_import_timestamp = time();
    }
    
    add_action('post_acui_import_single_user', 'FHGCAfterUserImportData', 10, 3);
    
    function FHGCAfterUserImportData($headers, $data, $user_id)
    {
    	// Add the timestamp of the start of the user import process to each user
    	global $acui_import_timestamp;
    
    	update_user_meta( $user_id, 'acui_import_time', $acui_import_timestamp );
    }
    
    add_action('after_acui_import_users', 'FHGCAfterAllUserImports', 10, 3);
    
    function FHGCAfterAllUserImports()
    {
    	global $acui_import_timestamp;
    	global $wpdb;
    
    	// Get all the imported users that are no longer included in the upload
    	$metaTable = $wpdb->prefix.'usermeta';
    	
    	$sql  = "SELECT * FROM $metaTable ";
    	$sql .= "WHERE meta_key='acui_import_time' ";
    	$sql .= "AND CAST(meta_value AS UNSIGNED)<$acui_import_timestamp ";
    	$oldUsers = $wpdb->get_results($sql);
    	
    	if (count($oldUsers) > 0)
    	{
    		echo "Previously Imported Users That were Not Included: <br><br>\n";
    		echo "<table><tr>";
    		echo "<th>Username</th>\n";
    		echo "<th>Name</th>\n";
    		echo "<th>EMail</th>\n";
    		echo "<th>Remove Link</th>\n";
    		echo "</tr>";
    		    
    		foreach ($oldUsers as $oldUser)
    		{
    			$user_info = get_userdata($oldUser->user_id);
    			
    			$siteurl = get_option('siteurl');
    			$nonce = wp_create_nonce('bulk-users'); 
    			$link = $siteurl."/wp-admin/users.php?action=delete&user=".$user_info->ID."&_wpnonce=$nonce";
    			
    			echo "<tr>";
    	      		echo '<td>'.$user_info->user_login . "</td>\n";
    	 		echo '<td>'.$user_info->user_nicename . "</td>\n";
    	 		echo '<td>'.$user_info->user_email . "</td>\n";
    	 		echo '<td><a target="_blank" href="'.$link.'">Delete</a>' . "</td>\n";
    		    echo "</tr>";
    	    }
    	    echo "</table>";
    	}
    }
    
Viewing 1 replies (of 1 total)
  • Plugin Author Javier Carazo

    (@carazo)

    Good morning @malcolm-oph,

    And thanks for your work. It is great. I really appreciate users like you use not only the plugin as users, but also you use it as a developer thanks to the hooks we left.

    If it would be a general functionality I would have included it in the core of the plugin.

    Maybe we can create some repo with addons for the plugin. It could be a good idea to help other users to create with this one.

    We have to work in it.

Viewing 1 replies (of 1 total)
  • The topic ‘Customisation to Indentyfy Expired Users’ is closed to new replies.