Plugin Directory

Changeset 3065321


Ignore:
Timestamp:
04/05/2024 09:38:19 AM (2 years ago)
Author:
morganhvidt
Message:

Updated 1.1.2

Location:
total-user-count-shortcode
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • total-user-count-shortcode/trunk/readme.txt

    r2888925 r3065321  
    55Author: Morgan Hvidt
    66Donate link: https://morganhvidt.com/donate
    7 Requires at least: 4.0
    8 Tested up to: 6.2
    9 Requires PHP: 5.7
     7Requires at least: 5.0
     8Tested up to: 6.5
     9Requires PHP: 7.5
    1010Stable tag: trunk
    1111License: GPLv2 or later
     
    1818Total 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]**
    1919
    20 ## NEW Get the user count for specific roles
     20## Get the user count for specific roles
    2121You 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
     24You can sum multiple user roles together by defining them in the shortcode.
     25Here's an enable of subscribers and authors be counted together.
     26
     27`[total_user_count role="subscriber, author"]`
     28
     29## Custom User roles
    2230
    2331Custom 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"]`
     
    3240
    3341## 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!
     42I 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!
    3545
    3646There is no admin screen, the plugin is **simple**, **lightweight** and **just works**.
    3747
    3848Consider leaving a 5 star review!
    39 
    4049
    4150== Installation ==
     
    6170
    6271== 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
    6378
    6479= 1.1.1 =
  • total-user-count-shortcode/trunk/total-user-count-shortcode.php

    r2485340 r3065321  
    22/**
    33 * 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.1
     4 * Description:       Display the total amount of users in your WP with a shortcode. [total_user_count role="subscriber, author"]
     5 * Version:           1.1.2
    66 * Author:            Morgan Hvidt
    77 * Author URI:        https://puri.io/
     
    2020    $atts = shortcode_atts(
    2121        array(
    22             'role' => false,
     22            'role' => false, // Now can be a comma-separated list of roles.
    2323        ),
    2424        $atts,
     
    2828    $usercount = count_users();
    2929
    30     // Saftey check.
     30    // Safety check.
    3131    if ( empty( $usercount ) || ! is_array( $usercount ) ) {
    3232        return false;
    3333    }
    3434
     35    $total_count = 0;
     36
    3537    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'] );
    3840
    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;
    4048    }
    4149
     50    // If no role attribute is provided, return the total user count.
    4251    $count = ! empty( $usercount['total_users'] ) ? $usercount['total_users'] : 'N/A';
    4352
    4453    return $count;
    4554}
    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.
     56add_shortcode( 'total_user_count', 'tusc_user_count' );
     57add_shortcode( 'total-user-count', 'tusc_user_count' );
Note: See TracChangeset for help on using the changeset viewer.