• Resolved cochii

    (@cochii)


    Hello

    I need to add an action when saving a post and choosing a user who can edit the post in the post permissions. When saving the post I want to get all the users who can edit this post

    I tried this

    add_action( 'post_updated', 'update_my_post', 1,3 );
    function update_my_post( $post_id, $post_after, $post_before ) {
        $user = wp_get_current_user();
        $roles = ( array )$user->roles;
        global $wpdb;
                    //on est dans le cas de la création de post, il faut envoyer un mail au contributeur assigné au post
                    $idPost = $post_after->ID;
                    $sql = "SELECT DISTINCT u.ID from  " . $wpdb->prefix . "ppc_exception_items pe_items
                                    LEFT JOIN " . $wpdb->prefix . "ppc_exceptions pe ON (pe_items.exception_id = pe.exception_id )
                                    LEFT JOIN " . $wpdb->prefix . "users u ON (pe.agent_id = u.ID)
                                    WHERE pe_items.item_id = " . $idPost . " AND pe.operation = 'edit' GROUP BY u.ID";
                    $req = $wpdb->get_results($sql);
                    //wp_die('<pre>Test:'.$req.'</pre>');
                    var_dump($req);
                    die();
    }

    but $req is an empty array
    I think when calling post_updated, PublishPress Permission has not modified the database yet. How to manually retrieve the list of users authorized to edit the post (selected in the permissions of the article) when saving a post?

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Steve Burge

    (@stevejburge)

    Hi @cochii

    Thanks for using PublishPress Permissions.

    Sorry, this is beyond the level of support that we can provide for the free version of the plugin.

    Support for custom code is available to PublishPress members.

    Thread Starter cochii

    (@cochii)

    Hi @stevejburge
    Before to buy this plugin, i need to know if I can put in place what I need. Once the plugin is bought, can I add an action at this moment?

    Plugin Author Kevin Behrens

    (@kevinb)

    @cochii

    If you have assigned Specific Permissions to a Permission Group, you should replace your users JOIN with a WHERE clause like this:

    
    "(pe.agent_type = 'pp_group' AND pe.agent_id IN ('$groups_csv'))"
    

    You can build $groups_csv like this:

    
    $pp_groups = array_keys(presspermit()->getUser()->groups['pp_group']);
    $groups_csv = implode("','", $pp_groups);
    
    Thread Starter cochii

    (@cochii)

    Thanks @kevinb but when I save post for first time, the permissions aren’t saved when I trigger post_updated…

    @stevejburge if i bought the plugin, can I add action when I set permission to a post ?

    Plugin Author Steve Burge

    (@stevejburge)

    Hi @cochii, yes and equally importantly – our developers will be able to give more help with your custom code.

    Plugin Author Kevin Behrens

    (@kevinb)

    @cochii When you leave your support ticket, please explain what you are trying to accomplish with this. Do you need to adjust the selected Permissions or just observe them?

    Thread Starter cochii

    (@cochii)

    I need to observe them. I have a specific workflow and I need to do an action when I saved post (not publish it, just save draft). This action is : get all user who can edit/read/revise post, save something into custom table in database and other thing. And I cannot retrieve this user list during the “save draft”, surely because PublishPress saves the data after the “post_updated” hook

    Plugin Author Kevin Behrens

    (@kevinb)

    There is a later action you can hook into instead:

    
    /**
    * Fires once a post has been saved.
    *
    * @since 2.0.0
    *
    * @param int     $post_ID Post ID.
    * @param WP_Post $post    Post object.
    * @param bool    $update  Whether this is an existing post being updated.
    */
    do_action( 'wp_insert_post', $post_ID, $post, $update );
    
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘add action when we have selected a user who can edit a post’ is closed to new replies.