Linux 软件免费装
Banner图

Get User Custom Field Values

开发者 coffee2code
更新时间 2021年11月21日 15:59
捐献地址: 去捐款
PHP版本: 4.6 及以上
WordPress版本: 5.8
版权: GPLv2 or later
版权网址: 版权信息

标签

widget shortcode custom field user coffee2code user meta

下载

2.6 2.7 2.7.1 2.8 2.9 2.9.1 3.0 3.2 3.2.1 3.2.2 3.3 2.5.1 2.5

详情介绍:

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: 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

安装:

  1. Install via the built-in WordPress plugin installer. Or install the plugin code inside the plugins directory for your site (typically /wp-content/plugins/).
  2. Activate the plugin through the 'Plugins' admin menu in WordPress
  3. 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'
  4. 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.)
  5. Optional: Use the provided 'Get User Custom' widget -or- Use the available shortcode in a post or page -or- Use the function c2c_get_current_user_custom() if you wish to access user custom fields for the currently logged in user. Use the function c2c_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.

屏幕截图:

  • Screenshot of the 'Get User Custom' widget.
  • Screenshot of the 'Get User Custom' shortcode builder (not available in the block editor, aka Gutenberg).

升级注意事项:

3.3 Recommended update: Prevented users who can't post unfiltered HTML from using the shortcode in posts (security hardening), added some new filters, added DEVELOPER-DOCS.md, noted compatibility through WP 5.8+, and reorganized and improved unit tests. 3.2.2 Trivial update: Restructured unit test file structure and noted compatibility through WP 5.5+. 3.2.1 Trivial update: Added TODO.md file, tweaked shortcode builder code, updated a few URLs to be HTTPS, and noted compatibility through WP 5.4+. 3.2 Minor update: disabled shortcode builder under block editor (it's incompatible), modernized unit tests, noted compatibility through WP 5.3+, dropped compatibility with versions of WP older than 4.6, updated copyright date (2020), and other minor tweaks and documentation improvements 3.1 Recommended bugfix update: Properly handled serialized meta values, fixed output of wrapping markup in widget if 'id' or 'class' is specified, verified compatibility through WP 4.7+, widget and unit test updates, various fixes and improvements 3.0 Minor update: improved support for localization, minor unit test tweaks, verified compatibility through WP 4.4+, and updated copyright date (2016) 2.9.1 Minor bugfix update: Prevented PHP notice under PHP7+ for widget; added more unit tests; updated widget framework to 010; noted compatibility through WP 4.3+ 2.9 Minor update: added more unit tests; updated widget framework to 009; noted compatibility through WP 4.1+; added plugin icon 2.8 Recommended update: added 'id' and 'class' to widget and shortcode; shortcode handling improvements; added unit tests; noted compatibility through WP 3.8+ 2.7.1 Bug fix update: fix to properly output markup for widget 2.7 Trivial update: noted compatibility through WP 3.5+; explicitly stated license 2.6 Recommended update. Highlights: allow shortcode to return user fields (not just custom fields); noted compatibility through WP 3.3+; and more. 2.5.1 Critical bugfix release (if using shortcode): fixed fatal shortcode bug; minor change to bail out of processing if an empty string is passed a custom field key name 2.5 Recommended update. Highlights: re-implemented widget based on custom widget framework; localized text; noted compatibility through WP 3.2+; and more. 2.0 Recommended significant update. Highlights: added widget; added shortcode + shortcode builder; added c2c_get_author_custom(); added multiple hooks to allow customization; verified WP 3.0 compatibility; dropped support for versions of WP older than 2.8; other miscellaneous tweaks and fixes.

常见问题:

How do I assign users custom fields so that I can retrieve them using this plugin?

The user profile page within WordPress provides inputs for a handful of user custom fields (first_name, last_name, aim, yim, jabber, description, etc). However, you're probably more interested in creating your own user custom fields. In that case, you'll have to use another plugin to store custom fields for users, or directly use WordPress functions manually.

I don't plan on using the shortcode builder when writing or editing a post or page, so how do I get rid of it?

If you use the block editor (aka Gutenberg, which is the default editing experience as of WordPress 5.0), then the shortcode builder is not available yet so this situation would be moot for you. For the classic editor, when on the Write or Edit admin pages for a page or post, find the "Screen Options" link near the upper right-hand corner. Clicking it slides down a panel of options. In the "Show on screen" section, uncheck the checkbox labeled "Get User Custom Field Values - 代码". This must be done separately for posts and for pages if you want the shortcode builder disabled for both sections.

I don't see the shortcode builder; where is it?

If you use the block editor (aka Gutenberg, which is the default editing experience as of WordPress 5.0), then the shortcode builder is not available yet. If you aren't able to include scripts in your posts (i.e. you don't have the 'unfiltered_html' capability), then the shortcode builder is not available to you. Only those with the editor or administrator role (except on Multisite) or the super administrator role can make use of this plugin's shortcode. For the classic editor, the shortcode builder/wizard is available in the admin when writing or editing a page or post. On the edit/create page, it'll be a sidebar widget (in this context, also known as a metabox) labeled "Get User Custom Field Values - Shortcode". If you don't see it there (which may be the case since it is hidden by default), find the "Screen Options" link near the upper righthand corner of the page. Clicking it slides down a panel of options. In the "Show on screen" section, check the checkbox labeled "Get User Custom Field Values - Shortcode". This must be done separately for posts and for pages if you want the shortcode builder enabled for both sections.

Can I move the shortcode builder box because it is way down at the bottom of the right sidebar when I create/edit posts?

Yes, any of the boxes on the page when creating/editing posts can be rearranged by dragging and dropping the box name. At the very top of the shortcode builder box the cursor will turn into a four-way array indicating you can click to drag that box. You can move it under the post content box, or higher up on the right side.

Why didn't the shortcode get inserted into the editor after I clicked the "Send shortcode to editor" button?

Sometimes you have to ensure the text editor has focus. Click within the text editor and make sure the cursor is positioned at the location you want the shortcode to be inserted. Then click the button and the shortcode should get inserted there.

Is this plugin compatible with the new block editor (aka Gutenberg)?

Yes, except that the shortcode builder (a custom tool to facilitate making use of the plugin's shortcode when creating a post) has not been ported over yet. The template tags, widget, and shortcode itself all function properly.

Does this plugin include unit tests?

Yes.

更新日志:

3.3 (2021-11-09) Highlights: This recommended release prevents users who can't post unfiltered HTML from using the shortcode in posts (security hardening), adds some new filters, adds DEVELOPER-DOCS.md, notes compatibility through WP 5.8+, and reorganizes and improves unit tests. Details: 3.2.2 (2020-09-18) 3.2.1 (2020-06-07)