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
- How can I use WordPress functions in my stylesheet?
- How can I modify the Capability needed to access a plugin’s options?
- change plugin shortcode function [closed]
- Creating search filter through plugin
- WP-Members redirect if member ALREADY logged in
- How to edit/delete single row items in a table on my own menu page
- Get a list of galleries from an album in NextGEN Gallery [closed]
- Undefined property: WP_Post_Type::$ID
- How to generate CSS from a shortcode within a plugin
- How to trigger $_GET request within admin plugin page?
- Wp favorite posts get user favorites in profile using buddypress [closed]
- Preferred way of cacheing a value in php
- Automatically add attributes to woocommerce product?
- Edit Yoast SEO breadcrumbs output [closed]
- Adding a slider captcha to the comment system
- Query all customers/users and check for duplicate information
- wp_remote_get() returns 403 while file_get_contents() does not
- How to set add question capability for author role in wp pro quiz plugin
- WordPress Widget Not Saving Data
- How I can internationalize variables within the function _e () __ (), etc?
- How can i force wp-admin to use 2-column dashboard layout? [closed]
- get specific value of a array | PHP
- How to change shortcode’s default theme?
- dynamically create callback functions inside a for loop
- Mutliple users editing single document in wordspress
- WordPress truncate posts question (plugin related)
- Different registration form for different roles
- WordPress Post HTML after Posting
- Settings options not showing up on Sub Menu page in WordPress plugin
- uncaught TypeError: Cannot read properties of null (reading ‘classList’) custom plugin
- Use a hook or filter, or overwrite this Gamipress function?
- The Build menu theme is frozen with the wordpress theme
- Does anyone know why my SEO and title become one?
- strtotime not working
- Prefix WordPress Taxonomy Tags With Hashtag Symbol Like Twitter
- How To Toggle User_Meta in frontend in a form using PHP
- Change Woo Custom Endpoint Titles from a Plugin
- Optimized PHP & WordPress settings for speed/performance?
- Speeding up WordPress on a Local Network
- How can I store user preferences in WordPress and retreive them later?
- How to add php plugin code in theme
- how change my menu on submenu
- Plugin debugging with errors in activation routine
- Number format in thousands on highcharts in wpdatatable plugin
- How to set up php,javascript and css to allow for our finished product to be displayed within a page?
- W3 Total Cache Can’t Really Detect Things
- Is it right way to create shortcode?
- How do I add php to all links automatically?
- Shortcode cannot parse attributes within double quotes. ” is becoming ” breaking my shortcode