• Resolved coty10

    (@coty10)


    Hello,
    is it possibile to add the review to a user profile instead of a post?

    e.g.
    [site_reviews assigned_to = “{username}]?

    Thank you!

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    This is not currently possible.

    However, here is a possible workaround: https://www.ads-software.com/support/topic/reviews-for-dynamic-pages/#post-12457862

    Thread Starter coty10

    (@coty10)

    I have created a category with the username:

    add_action('user_register','email_insert_category');
    function email_insert_category($user_id) {
    	 $user_info = get_userdata($user_id);
         $usernameToLogin = $user_info->user_login;
    	wp_insert_term(
    		$usernameToLogin,
    		'category',
    		array(
    		  'slug' => $usernameToLogin,
              'parent'=> term_exists( 'Utenti', 'category' )['term_id']
    		)
    	);
    }
    

    and i have the username available in the page ({username})

    Can i use the short code like this: ?

    [site_reviews_form category=”{username}”]

    Thank you!

    • This reply was modified 4 years, 10 months ago by coty10.
    • This reply was modified 4 years, 10 months ago by coty10.
    Thread Starter coty10

    (@coty10)

    I think i get where the problem is…

    i have this [site_reviews category=”{username}”]
    and it won’t work… probably because the {username} value appears after the page is loaded.

    I have test to hard fill the field and it works…

    is there a way where i can use the var {username} and make it work?
    Or the only way is to modify the php file?

    thank you!

    • This reply was modified 4 years, 10 months ago by coty10.
    Plugin Author Gemini Labs

    (@geminilabs)

    Site Reviews uses a custom taxonomy for the category. The custom taxonomy is site-review-category

    wp_insert_term($usernameToLogin, 'site-review-category', [
        'slug' => $usernameToLogin,
    ]);
    Thread Starter coty10

    (@coty10)

    This is the function i use:

    add_action('user_register','username_insert_category');
    function username_insert_category($user_id) {
    	 $user_info = get_userdata($user_id);
         $usernameToLogin = $user_info->user_login;
    		if (!empty($usernameToLogin) && !term_exists($usernameToLogin, glsr()->taxonomy)) {
    				require_once ABSPATH.'wp-admin/includes/taxonomy.php';
    				wp_create_term($term, glsr()->taxonomy);
    		}
    }

    and it works fine.
    The problem is the i have a plugin for membership and in the wp editor i get the username with this constant : {username}
    So when i use the shortcode [site_reviews category=”{username}”] it will bring up all the reviews and not just the one belonging to the category.
    instead if hard code the value [site_reviews category=”test”]
    it works fine. I’m afraid that the shortcode is processed before that information {username} is available. In the inspector i see the correct value

    screenshot

    but it loads the wrong reviews. There are no reviews with test category and yet it loads up all the review

    Plugin Author Gemini Labs

    (@geminilabs)

    You will need to contact the support team of the membership plugin to help you get the user object.

    Plugin Author Gemini Labs

    (@geminilabs)

    It sounds like the shortcode HTML is generated before the membership plugin replaces the username template tag with the actual username.

    Once you find out how to access the user object (or ID) instead of the {username} tag, you should be able to fix it.

    • This reply was modified 4 years, 10 months ago by Gemini Labs.
    • This reply was modified 4 years, 10 months ago by Gemini Labs.
    • This reply was modified 4 years, 10 months ago by Gemini Labs.
    Thread Starter coty10

    (@coty10)

    ok thank you!
    I’ll contact them.

    Plugin Author Gemini Labs

    (@geminilabs)

    FYI:

    Site Reviews v5.0 will allow you to assign reviews to a user (there is no set release date yet).

    Thread Starter coty10

    (@coty10)

    Hello!
    Thanks! sounds like a good news!

    However i do need to set it dynamically…
    I have solved like this:

    I create the taxonomy as soon as a new user register.
    Than i’ve created a custom template where i get the page slug, extract the last part of it (which is the username of the user) and then use it to get the reviews.

    Here’s the code:

    <?php 
      global $wp;
      $current_url = home_url( $wp->request );
      $username = array_slice(explode('/', $current_url), -1)[0];
    ?>
    <div class="tab__content">
    <h3>Reviews</h3>
    <p><?php echo do_shortcode('[site_reviews category='.$username.']');?></p>
    </div>
    <div class="tab__content">
    <h3>write a review</h3>
    <p><?php echo do_shortcode('[site_reviews_form category='.$username.']');?></p>
    </div>

    I’m not sure if there is a better way to get the user informations.
    This is a normal wordpress user, but i’m not sure how to get the data (user_login).
    I know how to get the current user data but haven’t find a way to get data of the user in the public page.
    If you have any suggestion i will really appreciate it! ??

    Thank you for your help! ??

    • This reply was modified 4 years, 10 months ago by coty10.
    • This reply was modified 4 years, 10 months ago by coty10.
    Plugin Author Gemini Labs

    (@geminilabs)

    What membership plugin are you using?

    Thread Starter coty10

    (@coty10)

    Plugin Author Gemini Labs

    (@geminilabs)

    If the user account is logged in, you can get the User object like this:

    $user = wp_get_current_user();
    apply_filters('glsr_debug', null, $user);
    

    If the user is a guest, you can get the User object from the page URL slug:

    $username = ''; // extract the username from the page URL here
    $user = get_user_by('user_login', $username);
    apply_filters('glsr_debug', null, $user);
    
    Thread Starter coty10

    (@coty10)

    Exactly i’m getting the username from the page slug and than applying it directly to the shortcode:

    global $wp;
    $current_url = home_url( $wp->request );
    $username = array_slice(explode('/', $current_url), -1)[0];
    <p><?php echo do_shortcode('[site_reviews_summary category='.$username.']');?></p

    Thank you! ??

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Assign rate to a user’ is closed to new replies.