简体   繁体   English

如何仅使用“添加”和“编辑”选项向用户授予其自己的窗格页面内容的权限?

[英]how to give permission to user on their own pods pages content with 'add' and 'edit' options only?

How to give permission to user on their own pods pages content with 'add' and 'edit' options only? 如何仅使用“添加”和“编辑”选项向用户授予其自己的pod页面内容的权限? I am using PHP, Apache, MySql and wordpress. 我正在使用PHP,Apache,MySql和wordpress。 Please, give me code examples. 请给我代码示例。

I am using following code: 我正在使用以下代码:

<?php 
$object = new Pod('dreams');
$object->ui = array('title' => 'My Pod' ,'add_fields' => array('name' ,'position','photo','bio','eom'),'edit_fields' => array('name' ,'position','photo','bio','eom','approved'));
    //load Pod
    $pod = new Pod('dreams');

    if(current_user_can('administrator')) {
        //set publicForm() visible fields for admins
       $object->ui = array('title' => 'My Dream' ,'add_fields' => array('name' ,'position','photo','bio','eom'),'edit_fields' => array('name' ,'position','photo','bio','eom','approved'));
    pods_ui_manage($object);
    } else if(is_user_logged_in()) {
    // Get the last URL variable
    $slug = pods_url_variable('1');
    $Edit = new Pod('team', $slug);
    $name = $Edit->get_field('name');
    $author_id = $Edit->get_field('author_id'); // GET AUTHOR FROM POD
     $user_id = $current_user->ID;
    global $current_user;   // GET USER INFO
    get_currentuserinfo();
$object->ui = array('title' => 'My Dream' ,'add_fields' => array('name' ,'position','photo','bio','eom'),'edit_fields' => array('name' ,'position','photo','bio','eom','approved'));
    pods_ui_manage($object);
 // $edit_listing = (($author_id == $current_user->ID) || (current_user_can('manage_options') == true) ? true : false); //

}; ?> <br/><br/>
<table>
<div><h1>Create a Dream</h1>
<p>What is this Dream, what do I want to do, accomplish, achieve?</p>
<p>Does this Dream involve someone else?</p>
<p>What tools are available to help achieve this Dream?</p>
<p>What steps can I take to help me achieve this Dream?</p>

<?php  $pod->publicForm($fields); ?>
</div></table>

Now the user can also see and edit all other user posts. 现在,用户还可以查看和编辑所有其他用户帖子。 But this should not be so. 但是,事实并非如此。

In your "ui" array, you want to add an additional 'where' and 'edit_where' clause. 在“ ui”数组中,您想要添加一个附加的“ where”和“ edit_where”子句。

'where' => 'p.author_id = ' . $user_id,
'edit_where' => array('author_id' => $user_id)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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