Skip to content

Instantly share code, notes, and snippets.

View gianghl1983's full-sized avatar

Giang Le gianghl1983

View GitHub Profile
@gianghl1983
gianghl1983 / usermeta-shortcode.php
Created March 19, 2019 12:15 — forked from dave-mills/usermeta-shortcode.php
A WordPress custom shortcode to display a piece of user metadata from the wp_usermeta table. Relies on Ultimate Member plugin
/* Create new shortcode for quickly displaying user metadata.
*** NOTE: This only works if you have the Ultimate Member plugin installed.
*** Use like regular wordpress shortcodes. Enter [USERMETA user_id="*id*" meta="*field_name*"] (replace *id* and *field_name* with actual values)
*** If you use it on an Ultimate Member profile page/tab, it will use the user currently being viewed.
*** On other pages, you must include the "user_id" within the shortcode.
*/
//Add the shortcode to WordPress
add_shortcode('USER_META', 'user_meta_shortcode_handler');
//create the function referenced by the add_shortcode()
function wpuf_post_umgroup( $post_id, $form_id ) {
/* Build the post content by adding the referer URL to the comment and update the post */
$lv_comment = $_POST['_my_comment'] . PHP_EOL . PHP_EOL . home_url() . wp_get_referer();
$lv_post = array();
$lv_post['ID'] = $post_id;
$lv_post['post_author'] = get_current_user_id();
$lv_post['post_content'] = $lv_comment;