• Resolved virtualgeorge

    (@virtualgeorge)


    I had someone create a shortcode for me to display users name & contact info etc.
    The shortcode seems to work on some pages but on others it shows the admins info instead of the users info.
    Here is one of the sites and on this page the shortcode shows the users info correctly:
    http://evantage360.com/chanyevans/backoffice/
    Now when I create a new page and use the same shortcode [lmn_user_info] it is showing the super admins data instead of the users/site owner:
    http://evantage360.com/chanyevans/test/

    I will post the shortcode below if that helps, I am not sure how much of this is related but if someone could point me in the right direction on how to troubleshoot this I would appreciate it.

    Or does this get complicated to the point of where I would better off to hire someone?

    I paid 2 different people to create this shortcode but it seems the people I find disappear after a few weeks or would go back to them for help 🙂

    I am not sure how much of this is related but will post my shortcode below, thanks!!!!!!

    add_shortcode('lmn','lmn_shortcode_func');
    
    function lmn_shortcode_func($options){
    
    	$extra_fields = array(
    		'first_name' => 'First Name',
    		'last_name' => 'Last Name',
    		'address_1' => 'Address 1',
    		'address_2' => 'Address 2',
    		'city' => 'City',
    		'state' => 'State',
    		'zipcode' => 'Zipcode',
    		'phone' => 'Phone'
    	);
    	$current_field = $options['field'];
    	$blog_id = get_current_blog_id();
    	$mail = get_blog_option($blog_id, 'admin_email');
    	$user_from_email = get_user_by('email', $mail);
    	$user_id = $user_from_email->ID;
    	$value = get_user_meta($user_id, $current_field, true);
    	ob_start();
    	?>
    
    	<?php
    		$output = ob_get_clean();
    		if($value){
    			echo $extra_fields[$current_field].': '.$value.'<br />';
    		}
    		return $output;
    }
    
    // here are the shortcodes
    
    add_shortcode( 'lmn_user_info' , 'z_get_current_info' );
    function z_get_current_info(){
    	$mail = get_the_author_meta('user_email');
    	$user_display_name = get_the_author_meta('display_name');
    	$user_fname = get_the_author_meta('user_firstname');
    	$user_lname = get_the_author_meta('user_lastname');
    	$user_phone = get_the_author_meta('phone');
    	$user_zipcode = get_the_author_meta('zipcode');
    	$user_address = get_the_author_meta('address_1');
    	$user_city = get_the_author_meta('city');
    	$user_state = get_the_author_meta('state');
    	$user_sitename = get_site_url();
        return '<ul class="lmn_user_info lmn_user_info_list"><li>username : ' . $user_display_name . '</li><li> Name : ' . $user_fname . '<span> ' . $user_lname . '</span></li><li> Site : ' . $user_sitename . '</li><li> email : ' . $mail . '</li><li> phone : ' . $user_phone . '</li><li> address : ' . $user_address . '</li><li> city : ' . $user_city . '</li><li> state : ' . $user_state . '</li><li> zipcode : ' . $user_zipcode . '</li></ul>';
    }
    
    add_shortcode( 'lmn_user_username' , 'z_get_current_username' );
    function z_get_current_username( $atts ){
    	$user_display_name = get_the_author_meta('display_name');
    	extract( shortcode_atts( array(
            'text' => null,
        ), $atts ) );
        return '<span class="lmn_user_info lmn_user_username">' . $text . '' . $user_display_name . '</span>';
    }
    /*
    add_shortcode( 'user_name' , 'z_get_current_name' );
    function z_get_current_name( $atts ){
    	$user_fname = get_the_author_meta('user_firstname');
    	$user_lname = get_the_author_meta('user_lastname');
    	extract( shortcode_atts( array(
            'text' => null,
        ), $atts ) );
        return '<span class="lmn_user_info lmn_user_fname">' . $text . '' . $user_fname . '</span><span class="lmn_user_lname"> ' . $user_lname . '</span>';
    }
    */
    
    add_shortcode( 'user_name' , 'z_get_current_name' );
    function z_get_current_name( $atts ){
    $user_id = get_current_user_id(); /*Added by George*/
    $user_fname = get_the_author_meta('user_firstname', $user_id);
    $user_lname = get_the_author_meta('user_lastname', $user_id);
    extract( shortcode_atts( array(
    'text' => null,
    ), $atts ) );
    return '<span class="lmn_user_info lmn_user_fname">' . $text . '' . $user_fname . '</span><span class="lmn_user_lname"> ' . $user_lname . '</span>';
    }
    
    add_shortcode( 'user_email' , 'z_get_current_email' );
    function z_get_current_email( $atts ){
    	$user_mail = get_the_author_meta('user_email');
    	extract( shortcode_atts( array(
            'text' => null,
        ), $atts ) );
        return '<span class="lmn_user_info lmn_user_email">' . $text . '' . $user_mail . '</span>';
    }
    
    add_shortcode( 'user_phone' , 'z_get_current_phone' );
    function z_get_current_phone( $atts ){
    	$user_phone = get_the_author_meta('phone');
    	extract( shortcode_atts( array(
            'text' => null,
        ), $atts ) );
        return '<span class="lmn_user_info lmn_user_phone">' . $text . '' . $user_phone . '</span>';
    }
    
    add_shortcode( 'user_address' , 'z_get_current_address' );
    function z_get_current_address( $atts ){
    	$user_address = get_the_author_meta('address_1');
    	extract( shortcode_atts( array(
            'text' => null,
        ), $atts ) );
        return '<span class="lmn_user_info lmn_user_address">' . $text . '' . $user_address . '</span>';
    }
    
    add_shortcode( 'user_city' , 'z_get_current_city' );
    function z_get_current_city( $atts ){
    	$user_city = get_the_author_meta('city');
    	extract( shortcode_atts( array(
            'text' => null,
        ), $atts ) );
        return '<span class="lmn_user_info lmn_user_city">' . $text . '' . $user_city . '</span>';
    }
    
    add_shortcode( 'user_state' , 'z_get_current_state' );
    function z_get_current_state( $atts ){
    	$user_state = get_the_author_meta('state');
    	extract( shortcode_atts( array(
            'text' => null,
        ), $atts ) );
        return '<span class="lmn_user_info lmn_user_state">' . $text . '' . $user_state . '</span>';
    }
    
    add_shortcode( 'user_zipcode' , 'z_get_current_zipcode' );
    function z_get_current_zipcode( $atts ){
    	$user_zipcode = get_the_author_meta('zipcode');
    	extract( shortcode_atts( array(
            'text' => null,
        ), $atts ) );
        return '<span class="lmn_user_info lmn_user_zipcode">' . $text . '' . $user_zipcode . '</span>';
    }
    
    add_shortcode( 'lmn_user_siteurl' , 'z_get_current_siteurl' );
    function z_get_current_siteurl( $atts ){
    	$user_sitename = get_site_url();
    	extract( shortcode_atts( array(
            'text' => null,
        ), $atts ) );
        return '<span class="lmn_user_info lmn_user_siteurl">' . $text . '' . $user_sitename . '</span>';
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • There are a number of shortcodes in the code you shared.

    1. [lmn]
    2. [lmn_user_info]
    3. [lmn_user_username]
    4. [user_name]
    5. [user_email]
    6. [user_phone]
    7. [user_address]
    8. [user_city]
    9. [user_state]
    10. [user_zipcode]
    11. [lmn_user_siteurl]

    As for [lmn_user_info] that you mentioned, it displays information based on who created the post/page. Since you created the post, even though it’s not your site, the shortcode will display your information.

    You can change the author information on a post by post basis.

    1. Go to “Edit Post”
    2. Show the author Meta Box (if hidden)
    1. Step 1 Screenshot
    2. Step 2 Screenshot
    • Change the dropdown to contain the appropriate user. [screenshot]
    • Save the changes
    • If you wanted to display the ‘Site Owner’ instead of the post’s author, that would require some modifications and may be different depending on how ownership is set for each site.

    Thread Starter virtualgeorge

    (@virtualgeorge)

    That’s it:)

    So I was using a plugin wpthree broadcast that allows you to update pages across your network. And when I updated that page it also made me the “author” and hence the problem.

    So I just have to correct my page update method so it doesn’t make the admin the author when updating and it will be good.

    Thanks so much!!

    Thread Starter virtualgeorge

    (@virtualgeorge)

    So any tips on how can change the author of that one page in ALL my subsites without logging in to each site and updating each page? Maybe a phpmyadmin trick 🙂

    thanks!!!

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    You could possibly construct a SQL query to look for the page slug (if it’s the same on all sites) and change the author that way, but it’s a high risk manuever.

    Thread Starter virtualgeorge

    (@virtualgeorge)

    Yeah wasn’t sure how to that, the page id is the same on all sites but each user id is different and has to be change from the admins id to to the users id for that site.

    However it was quicker for me to do it phpmyadmin then updating every pages author drop down.

    It took a while and then the site owner decided he was going to add a video to that page accidentally changed them all back to admin as the author LOL.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Shortcode displays user data/info on one page, but admin info on another?’ is closed to new replies.