Support » Plugins » Hacks » Ignore wp get current user status, if page is X

  • Resolved NetMonkey

    (@headmonkey)



    I had a developer extend the functionality of a plugin in the repository by creating a new one. His plugin allows users to upload videos to their private user profile page that display in that page and the main gallery. Now that I want to display those users videos on their own public profile page also, I can’t.

    Because the developer wrote code that checks if that user is logged in. If not, it displays a dialog saying to view that functionality you have to be logged in.

    My modified code that’s not working is the two added — if is page and the echo line of code:

        public function videoList() {
    		
        global $wpdb;
    
        if ( is_page(myaccount) ) 
    		
        $displayMsg = null;
    
        $current_user = wp_get_current_user();
    
        if ($current_user->ID == 0) {
    			
        $view = new View(dirname(__FILE__) . '/views/not-logged-in.phtml');
    			
        return $view->render(true);
    		
        if( is_page(my-page) )
        
        echo do_shortcode ('[user-video-list]');
    
    }

    The echo shortcode is a valid shortcode the developer created. Can anyone suggest some code that may be a fix here? The developer has gone MIA on me…

Viewing 5 replies - 1 through 5 (of 5 total)
  • ThemeSumo

    (@themesumo)

    If the shortcode works fine, and you have added the page slugname correctly then I don’t see why this shouldn’t work for you.

    if(is_page('my-page')) {
        echo do_shortcode ('[user-video-list]');
    }

    is_page

    NetMonkey

    (@headmonkey)

    It seems that because this code is in place:

    $current_user = wp_get_current_user();
    
        if ($current_user->ID == 0) {
    			
        $view = new View(dirname(__FILE__) . '/views/not-logged-in.phtml');
    			
        return $view->render(true);

    It ignores the page that it’s being displayed on and processes the not-logged-phtml file. What if the code was reversed and my (if is page) code, came before the current_user code? Does it make a difference?

    Moderator bcworkz

    (@bcworkz)

    Yes it would, mainly because then your code would occur before return $view->render(true);. Any code after this would not be processed. Additionally, I’m not seeing the matching closing curly brace } to if ($current_user->ID == 0) {. This needs to exist somewhere. Maybe it got clipped when you pasted the snippet and this part is OK. Do double check this.

    NetMonkey

    (@headmonkey)

    Here’s the code with the lines reversed as it is now:

       public function videoList() {
        if(is_page('my-page')) 
        echo do_shortcode ('[user-video-list]');
    	
        if (is_page('myaccount')) 
    	
        global $wpdb;
    		
        $displayMsg = null;
        $current_user = wp_get_current_user();
    
        if ($current_user->ID == 0) {
    			
        $view = new View(dirname(__FILE__) . '/views/not-logged-in.phtml');
    	return $view->render(true);
    		
    	}

    Now I get an internal server error 500 when the page displays.

    Moderator bcworkz

    (@bcworkz)

    500 errors can be nearly anything. It’s reasonable to suspect your altered code if that was all that was changed since the site was working. You can get specific PHP error information by defining WP_DEBUG as true in your wp-config.php file. Do not leave debug mode enabled on a publicly accessible server for too long as it’s a slight security risk.

    It might be the closing curly brace issue, I still see two opening {{ but only one closing } to balance. They must always balance. You should maybe also swap the if (is_page(‘myaccount’)) and global $wpdb; lines, this restores the sequence in your original snippet. As it is now it doesn’t make much sense.

    The error might also be in the rendering of the shortcode. Echoing out content in this videoList() context may not be the right thing to do. If the curly braces are balanced and you still get errors, try commenting out the echo do_shortcode() line. (Put two slashes in front of the line // ) If that cures the error then echoing out content here is the wrong thing to do here.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Ignore wp get current user status, if page is X’ is closed to new replies.