- Author: Scott Reilly
- Version: 3.3
- First released: 2011-08-08
- Last update: 2021-11-21
- Compatibility: WP 4.6 – 5.8.10
- Download: [ zip ]
- Description:
Use widgets, shortcodes, and/or template tags to easily retrieve and display custom field values for users.
-
Extended Description
This plugin provides a powerful widget, shortcode (with shortcode builder tool), and template tags for easily retrieving and displaying custom field values for the currently logged in user or any specified user.
This plugin provides functionality similar to the Get Custom Field Values plugin, but for user custom fields (which WordPress manages in a separate database table).
This plugin does NOT help you in setting user custom field values, nor does it provide an interface to list or otherwise manage user custom fields.
The list of useful user custom field values that are provided by default in WordPress are:
- first_name
- last_name
- nickname
- description
- aim
- yim
- jabber
It is up to other plugins or custom code to add additional user custom fields that you may then be able to retrieve with this plugin.
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
Developer Documentation
Developer documentation can be found in DEVELOPER-DOCS.md. That documentation covers the numerous template tags, hooks, and shortcode provided by the plugin.
As an overview, these are the template tags provided the plugin:
c2c_get_current_user_custom()
: Template tag to get custom fields for the currently logged in user.c2c_get_author_custom()
: Template tag to get custom fields for the current author (when on the permalink page for a post, page, or in a loop).c2c_get_user_custom()
: Template tag to get custom fields for a specified user.
These are the hooks provided by the plugin:
c2c_get_current_user_custom
: An alternative approach to safely invokec2c_get_current_user_custom()
in such a way that if the plugin were deactivated or deleted, then your calls to the function won’t cause errors in your site.c2c_get_author_custom
: An alternative approach to safely invokec2c_get_author_custom()
in such a way that if the plugin were deactivated or deleted, then your calls to the function won’t cause errors in your site.c2c_get_user_custom
: An alternative approach to safely invokec2c_get_user_custom()
in such a way that if the plugin were deactivated or deleted, then your calls to the function won’t cause errors in your site.c2c_get_user_custom_field_values_shortcode
: Filter to customize the name of the plugin’s shortcode.c2c_get_user_custom-user_field_proxy
: Filter to prevent proxying to user object fields if no value for the custom field was found for the user.get_user_custom_field_values/can_author_use_shortcodes
: Filter to customize if post author can make use of the ‘user_custom_field’ shortcode.get_user_custom_field_values/show_metabox
: Filter to customize if the shortcode builder metabox is shown.
The shortcode provided is
, which has a number of attributes to customize its behavior and output.
Find out more at the plugin’s WordPress Plugin Repository page.
-
Screenshots
Click to see full-size image.
-
Installation
- Install via the built-in WordPress plugin installer. Or install the plugin code inside the plugins directory for your site (typically
/wp-content/plugins/
). - Activate the plugin through the ‘Plugins’ admin menu in WordPress
- Optional: Add filters for ‘the_user_meta’ to filter user custom field data (see the end of the file for commented out samples you may wish to include). And/or add per-meta filters by hooking ‘the_user_meta_$field’
- Give a user a custom field with a value, or have user custom fields already defined. (This generally entails use of plugin(s) that utilize the user custom fields feature built into WordPress. By default, in a practical sense WordPress only sets the ‘first_name’, ‘last_name’, and ‘nickname’ user custom fields, so you could try using one of them, even if just for testing even though WordPress provides functions to get those particular fields.)
- Optional: Use the provided ‘Get User Custom’ widget -or-
Use the available shortcode in a post or page -or-
Use the functionc2c_get_current_user_custom()
if you wish to access user custom fields for the currently logged
in user. Use the functionc2c_get_user_custom()
to access user custom fields for a specified user. Use the function
c2c_get_author_custom() to access custom fields for the current author (when on the permalink page for a post, page, or
in a loop). Prepend either of the three mentioned functions with ‘echo’ to display the contents of the custom field; or
use the return value as an argument to another function.
- Install via the built-in WordPress plugin installer. Or install the plugin code inside the plugins directory for your site (typically
-
Release Log
3.3 (2021-11-09)
- Change: Prevent users who cannot post unfiltered HTML from using the shortcode in posts. Props Francesco Carlucci and Erwan.
- Hardens security to prevent potentail information disclosure or XSS by authors with limited privileges
- New: Add shortcode class function
can_author_use_shortcodes()
- New: Add filter
'get_user_custom_field_values/can_author_use_shortcodes'
- Change: Prevent shortcodes created by users who cannot publish unfiltered HTML from being evaulated
- Change: Prevent display of shortcode builder metabox to users who cannot publish posts
- New: Add filter
'get_user_custom_field_values/show_metabox'
to customize if shortcode builder metabox is shown - New: Add DEVELOPER-DOCS.md and move template tag and shortcode documentation into it
- Change: Note compatibility through WP 5.8+
- Change: Update copyright date (2021)
- Change: Update shortcode builder widget to 008
- Change: Tweak installation instructions
- Unit tests:
- Change: Split shortcode-related tests out into their own file
- Change: Split widget-related tests out into their own file
- New: Add unit tests for
show_metabox()
- New: Add helper function
create_post()
- Change: Restructure unit test file structure
- Change: Move
phpunit/bin/
totests/bin/
- Change: Move
phpunit/bootstrap.php
intotests/phpunit/
- Change: Move tests from
phpunit/tests/
totests/phpunit/tests/
- Change: In bootstrap, store path to plugin file constant so its value can be used within that file and in test file
- Change: In bootstrap, check for test installation in more places and exit with error message if not found
- Change: Remove ‘test-‘ prefix from unit test files
- Change: Move
- New: Add a few more possible TODO items
3.2.2 (2020-09-18)
- Change: Restructure unit test file structure
- New: Create new subdirectory
phpunit/
to house all files related to unit testing - Change: Move
bin/
tophpunit/bin/
- Change: Move
tests/bootstrap.php
tophpunit/
- Change: Move
tests/
tophpunit/tests/
- Change: Rename
phpunit.xml
tophpunit.xml.dist
per best practices
- New: Create new subdirectory
- Change: Note compatibility through WP 5.5+
3.2.1 (2020-06-07)
- Change: Update shortcode builder widget to 007:
- New: Store object instantiated during
register()
- Change: Cast return value of
c2c_get_user_custom_field_values_post_types
filter as an array - Change: Sanitize string used in markup attributes (hardening)
- New: Store object instantiated during
- New: Add TODO.md and move existing TODO list from top of main plugin file into it (and added to it)
- Change: Note compatibility through WP 5.4+
- Change: Update links to coffee2code.com to be HTTPS
- Change: Update link to Get Custom Field Values plugin to point to wordpress.org instead of my site
- Change: Unit tests: Use HTTPS for link to WP SVN repository in bin script for configuring unit tests (and delete commented-out code)
- Change: Prevent users who cannot post unfiltered HTML from using the shortcode in posts. Props Francesco Carlucci and Erwan.
-
Copyright & Disclaimer
Copyright © 2011-2024 by Scott Reilly (aka coffee2code)This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -
Discussion / Support
Have any questions, comments, or suggestions? Please provide them via the plugin’s WordPress.org support forum. I’ll do my best to reply in a timely fashion and help as best I can.
Unfortunately, I cannot provide guaranteed support, nor do I provide support via any other means.
Was this plugin useful useful to you? Consider giving it a rating. If you’re inclined to give it a poor rating, please first post to the support forum to give me a chance to address or explain the situation.
Categories
2 replies on “Get User Custom Field Values”
[…] Get User Custom Field Values von Scott Reilly bietet eine vergleichbare Funktionalität wie das Plugin Get Custom Field Values des gleichen Autors. Es ermöglicht des einfachen Abruf und die Anzeige von Custom Field Werten und Meta Daten für den aktuell eingeloggten User. Verwandte Artikel […]
[…] about the detail. Code was borrowed from both Wp1stop’s wordpress car dealer plugin and the Get Custom Fields Values Plugin. Both of these wordpress plugins are free and so is this one. This will only work for […]