First, you’ll have to get shortcode parameter(s). Change function’s declaration to:
function display_user_roles( $atts ) {
Your shortcode will be either [hw_display_users]
or [hw_display_users role="roletopass"]
. The first (no parameter) will use role specified in $args array. Second will replace $args->role with parameter passed. Add
if ( !empty( $atts['role'] ) )
$args['role'] = $atts['role'];
before
$users = get_users( $args );
Remaining code should be ok.
For more information how to handle shortcodes with parameters read this.
Related Posts:
- PHP Deprecated: Non-static method should not be called statically
- Adding Custom Fields for Img in Posts
- How To Ignore a Filter On Applying Filter the Content In a Function
- Calling function from within functions.php returns unwanted value
- shortcode doesn’t work
- Checking for user role in a custom plugin
- Can’t get custom posts of taxonomy to show
- Shortcode to generate and save password in a file
- get shortcode value
- Storing Options in a Shortcode
- Error shown for Trying to get property ‘roles’ of non-object in WordPress After Content for User Roles
- How to remove html code in excel downloads using phpspreadsheet with wordpress plugins shortcode
- How to put JQuery/Ajax inside shortcode?
- WordPress Shortcode to get URL Parameters $_GET[‘name’] redirects for no reason at all
- Redirection of users away from wp-admin (but not administrators)
- WordPress function not being called from jQuery method
- WooCommerce specifc variations for specific user role [closed]
- Nested shortcode functions accessing variable
- Some code in shortcode function being ignored
- How to Create a shortcode to this php function
- Redirect to another page using contact form 7? [closed]
- What is @Action in WordPress?
- Return multiple values in a shortcode attribute
- Add User Role: Pre-saved in User-Meta [SOLVED]
- Is there a way to convert shortcodes to html content?
- Shortcode not working – quotes seems strange
- Get all the URLs of the pages that uses a specific shortcode
- Add the_post_thumbnail_url to a shortcode in function.php
- Echo out element to another page.
- Adding a Tag Parameter / Filter to My Shortcode
- Creating New Dynamic Fields for a Certificate (Number Generation, Code Referencing, and more)
- implement custom roles in custom plugin
- How to get current cart values using WC_Shortcodes?
- Allow a particular user to access a particular plugin?
- get_post_meta shortcode returns empty field
- How do I use a plugin’s shortcode attribute value in another function?
- Why does my custom plugin only function correctly once per page?
- Hide content for specific users with id
- Why is my shortcode not working?
- Get Shortcode output to database for static post_content
- Restrict role to use a plugin
- Query Shortcode from a multisite to appear on a different site?
- Find all strings between an enclosing shortcode
- Posting code inside the post instead of in the template file using shortcode
- How to Set Limit with WordPress Get Bookmarks Shortcode
- Creating Features List in WordPress Post
- Integrate Razorpay quick payments plugin with contact form7 plugin
- cURL External API request displays content above other content on page
- Subtract Using GravityWP Count Plugin
- How to get URL param for pagination in shortcode?
- qTranslate‑X is not translating all shortcodes
- Shortcode is not working in homepage page template (custom front page)
- force customers to add only single item to card per purchase EDD [closed]
- Undefined property: WP_Post_Type::$ID
- Plugin exceeds memory limit
- Can wp_localize_script be used within a shortcode?
- How to get post URL in the_content filter?
- How to remove xmlns on language_attributes()?
- How to write one comment and publish on every post using database or plugin?
- Add a plugin before main container
- How to get subscription key or id using Woocommerce Subscriptions [closed]
- How to get member list based on role by using buddypress?
- I don’t understand how this parameter works..?
- Why wp_mail() function isn’t sending any emails and displaying ‘0’ in Chrome ‘Network’ response
- How to initialize something in unit test before the init hook being called?
- Force [wordpress_social_login] shortcode to display where it is embedded [closed]
- Set user ID at time of wp_create_user
- Overriding Attributes values in Shortcode Plugins
- May i Use ShortCode in Template?
- Missing argument 3 for wp_register_sidebar_widget()
- Pass variable to nested shortcode
- Make id column as AUTO INCREMENT on plugin activation
- How to Include a Loop Template File in a Plugin
- Write to / remove from default .htaccess file from plugin?
- Add custom variable in Contact Form 7 mail body
- Update User Role
- Update Option Error: Notice: Undefined index
- Demystifying and understanding shortcode nomenclature
- How to modify shortcode attributes with data from current post
- How can I display a contact form for out of stock products in WooCommerce?
- Pass a php string to a javascript variable
- Confused about shortcode and settings values
- How to get number of Affected rows from wordpress dbDelta() function
- Running jquery script after shortcode [closed]
- Plugin to restrict access to pages in wp-admin
- Show price with Geo IP location
- WordPress Ajax Callback
- Add category to body class
- The called constructor method for WP_Widget in GFWidget is deprecated since version 4.3.0! Use
- Plugin Development sqlite or WordPress’ database
- How to review WordPress website php version compatibility?
- printf – problem to understand code
- Custom Post Type Plugin not loading category template and loading 404 instead
- Sending email from inside a plugin using PHP PEAR
- Getting user roles in plugin files
- Auto delete WordPress users according to time
- How to cancel WordPress’ action/filter when using OOP with anonymous callback
- How to achieve certain page (url) accessible to certain users
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- How to generate CSS from a shortcode within a plugin