Link to home
Start Free TrialLog in
Avatar of Chris Andrews
Chris AndrewsFlag for United States of America

asked on

Hack Peter's Collaboration Email Plugin to put Editor that published post into DB?

On my wordpress site - I need to record which editor (by user id) approved the post - who changed it from 'pending' to 'publish'. I'll have several editors authorized to publish contributor's posts - but I need to know who did so I can hold them responsible.

WP apparently doesn't do this on its own.

I see two solutions - writing a plugin to do this (I don't know how to do this) or hacking an existing plugin to do this (um, I don't really quite know how to do this either).

HELP!

Here's what I am thinking:

I have Peter's Collaboration Emails plugin installed.

There's a place in the plugin that triggers when an editor approves a post.

I copied that part of the code below, and I am attaching the full script from the plugin.

Is it possible to add a piece of code to it that will add the current user id (the person that is approving it) to the database somewhere, as the post approver, when this part of the script is triggered?

I know I will need to redo this whenever the plugin is updated. I'll also need the snippet to pull this data out of the database, so I can use it on single.php.

Ok, here the part of the code where I think it would need to go (full code attached).

Thanks for any possible help,      Chris

-------------------------------------------

// E-mail the post author when a post is approved
    elseif( $pce_emails_to_send['approved'] && 'pending' == $pce_oldstatus && 'publish' == $pce_newstatus )
    {

        // Header stuff for an approved post
        // Header stuff from http://ca.php.net/mail
        $pce_headers .= 'From: ' . $pce_fromname . ' <' . $pce_fromaddress . '>' . $pce_eol;
        $pce_headers .= 'Reply-To: ' . $pce_fromname . ' <' . $pce_fromaddress . '>' . $pce_eol;
        $pce_headers .= 'Return-Path: ' . $pce_fromname. ' <' . $pce_fromaddress .'>' . $pce_eol;

        // E-mail body for an approved post
        $pce_body = sprintf( __( 'Hi %s!', 'peters_collaboration_emails' ), $pce_thisuser->display_name ) . $pce_eol . $pce_eol;
        if( $pce_whoapproved )
        {
            $pce_body .= sprintf( __( 'Your post has been approved by %s and is now published', 'peters_collaboration_emails' ), $pce_fromname );
        }
        else
        {
            $pce_body .= __( 'Your post has been approved', 'peters_collaboration_emails' );
        }
        
        $pce_body .= $pce_eol . $pce_eol;
        
        // Insert note if applicable
        if(isset($pce_post_note)) {
            $pce_body .= __('Accompanying note:', 'peters_collaboration_emails') . $pce_eol;
            $pce_body .= $pce_post_note . $pce_eol . $pce_eol;
        }
        $pce_body .= __('See it here:', 'peters_collaboration_emails') . ' ' . get_permalink($pce_object->ID);

Open in new window

peters-collaboration-emails.php
ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chris Andrews

ASKER

Awesome!!!

Thank you so much! I had a feeling I had found the right place for some code to do this, but I didn't know how to write that code :)

It did put the correct post ID into the database.

It puts the 'display name' in the database though, not the userid.

So I tried this:

$approver = get_userdata( $userid );

$thepost = $pce_object->ID;
update_post_meta($thepost, 'approver', "$approver");

but that didn't work.  

I can probably figure out how to get the userid using the display name in my single.php file, if there isn't an easy way to do that here.  I need the userid because that's what the adsharing code in my single.php uses.

Thanks again, I am going to mark this as answered, as this has basically done the trick - but if you have any ideas on getting the userid, just let me know,

Chris
heh, not to mention, if:

$approver = get_userdata( $userid );

had worked, it would have messed up other parts of the script, I should have renamed rename that value - I realized after thinking it through a bit :)
Ugh, ignore that last post, I was thinking wrong.
Ah, got it :)

Had to add $user_ID to the global settings on line 4 (I think I had to do that, it worked, anyway)

then:

update_post_meta($thepost, 'approver', "$user_ID");

Learning as I go :)

Thanks again, this was a huge hurdle to get to where I want to go.

Chris
Sweet.  You should contact Peter and offer the code back to him. Maybe he'll update the plugin :)
I'll do that :) I had the same thought.