Changeset 3065321
- Timestamp:
- 04/05/2024 09:38:19 AM (2 years ago)
- Location:
- total-user-count-shortcode
- Files:
-
- 4 added
- 2 edited
-
tags/1.1.2 (added)
-
tags/1.1.2/index.php (added)
-
tags/1.1.2/readme.txt (added)
-
tags/1.1.2/total-user-count-shortcode.php (added)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/total-user-count-shortcode.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
total-user-count-shortcode/trunk/readme.txt
r2888925 r3065321 5 5 Author: Morgan Hvidt 6 6 Donate link: https://morganhvidt.com/donate 7 Requires at least: 4.08 Tested up to: 6. 29 Requires PHP: 5.77 Requires at least: 5.0 8 Tested up to: 6.5 9 Requires PHP: 7.5 10 10 Stable tag: trunk 11 11 License: GPLv2 or later … … 18 18 Total User Count adds a shortcode to display the number of user accounts in your WordPress site. There is no admin screen, just the shortcode **[total_user_count]** 19 19 20 ## NEWGet the user count for specific roles20 ## Get the user count for specific roles 21 21 You can now get the amount of users with any role. Use shortcode like this to insert the amount of WooCommerce customers into your page: `[total_user_count role="customer"]` 22 23 ## Tally multiple roles togethers 24 You can sum multiple user roles together by defining them in the shortcode. 25 Here's an enable of subscribers and authors be counted together. 26 27 `[total_user_count role="subscriber, author"]` 28 29 ## Custom User roles 22 30 23 31 Custom user roles can be added by any plugin. You just have to make sure the role name is correct, otherwise "N/A" will be displayed. Display the amount of registered WordPress subscribers with this shortcode `[total_user_count role="subscriber"]` … … 32 40 33 41 ## Use it for social proof 34 I just released Total User Count. Display the number of users any where on your Wordpress site using the shortcode [total_user_count]! Give it a go! 42 I just released Total User Count. Display the number of users any where on your Wordpress site using the shortcode `[total_user_count]` 43 44 ! Give it a go! 35 45 36 46 There is no admin screen, the plugin is **simple**, **lightweight** and **just works**. 37 47 38 48 Consider leaving a 5 star review! 39 40 49 41 50 == Installation == … … 61 70 62 71 == Changelog == 72 73 = 1.1.2 = 74 75 * Count (sum) multiple user roles within one shortcode. 76 * Tested and ready for WordPress 6.5 77 * Ready for PHP 8.3 63 78 64 79 = 1.1.1 = -
total-user-count-shortcode/trunk/total-user-count-shortcode.php
r2485340 r3065321 2 2 /** 3 3 * Plugin Name: Total User Count Shortcode 4 * Description: Display the total amount of users in your WP with the [total_user_count] shortcode. [total_user_count role="subscriber"]5 * Version: 1.1. 14 * Description: Display the total amount of users in your WP with a shortcode. [total_user_count role="subscriber, author"] 5 * Version: 1.1.2 6 6 * Author: Morgan Hvidt 7 7 * Author URI: https://puri.io/ … … 20 20 $atts = shortcode_atts( 21 21 array( 22 'role' => false, 22 'role' => false, // Now can be a comma-separated list of roles. 23 23 ), 24 24 $atts, … … 28 28 $usercount = count_users(); 29 29 30 // Saf tey check.30 // Safety check. 31 31 if ( empty( $usercount ) || ! is_array( $usercount ) ) { 32 32 return false; 33 33 } 34 34 35 $total_count = 0; 36 35 37 if ( ! empty( $atts['role'] ) ) { 36 // Get the custom role. could be 'customer', 'administrator', 'editor' etc.37 $ count = isset( $usercount['avail_roles'][ $atts['role'] ] ) ? $usercount['avail_roles'][ $atts['role'] ] : 'N/A';38 // Split the roles into an array. 39 $roles = explode( ',', $atts['role'] ); 38 40 39 return $count; 41 foreach ( $roles as $role ) { 42 $role = trim( $role ); // Trim spaces from role names. 43 // Sum the counts for each role. 44 $total_count += isset( $usercount['avail_roles'][ $role ] ) ? $usercount['avail_roles'][ $role ] : 0; 45 } 46 47 return $total_count; 40 48 } 41 49 50 // If no role attribute is provided, return the total user count. 42 51 $count = ! empty( $usercount['total_users'] ) ? $usercount['total_users'] : 'N/A'; 43 52 44 53 return $count; 45 54 } 46 // Creating a shortcode to display user count.47 add_shortcode( 'total_user_count', 'tusc_user_count' );48 add_shortcode( 'total-user-count', 'tusc_user_count' );55 // Creating a shortcode to display user count. 56 add_shortcode( 'total_user_count', 'tusc_user_count' ); 57 add_shortcode( 'total-user-count', 'tusc_user_count' );
Note: See TracChangeset
for help on using the changeset viewer.