dongshi9407 2016-09-23 18:44
浏览 14

WordPress如果页面是X不检查登录的用户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?

  • 写回答

1条回答 默认 最新

  • dsdtumf776629385 2016-09-23 19:30
    关注

    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!

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测