简体   繁体   中英

WordPress if page is X don't check for logged in user id

I had a developer write a plugin for registered users to upload videos to their private profile page that would appear in the public video gallery. The developer has gone MIA so I can't get him to modify the code. He gave me a [shortcode] that I placed in the private profile page that gives the users the ability to upload, delete videos, etc.

Now that I need those user videos to display also on their public profile page, they won't because of some code in his plugin that checks if the user is logged in. If any user is logged in, they can see their videos on their public page, but no one else can that's not logged in. Users not logged in see a message saying they must be logged in to have the video functionality. I think I've identified the code below in the plugin that's causing this:

public function videoAdd() {


global $wpdb;



$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);

}

My question is (because I can't write php code), can else if statements take care of this by specifying a page name? For instance, if page X, require user to be logged in to upload, but if page Y, only display the user's videos. Here's some example code I found that looks like it can be modified to work, but I'm not savvy enough to do it:

<?php   if ( is_page(123) ) { 
?>
<div class="option one">my content</div>


<?php } elseif( is_page(124) ) {

?>
<div class="option one">abc content</div>

<?php } 
else {
echo  '<div class="option one">any content</div>';
}

?>

Can anyone please help me with a code example to make this work?

Yes, you should be able to do this. is_page() accepts both the page ID as well as the page name.

So you could do something like this:

is_page(123)

Where 123 is the ID in the page's URL. For example, in the Admin area: https://your-site.com/wp-admin/post.php?post=123&action=edit , you'd use the string of numbers after post= .

You can also identify a page by URL name. For example, the page https://your-site.com/about-us/ could be identified like this:

is_page('about-us')

Hope that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM