Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Change Post Ownership
- * Changes the post author to the user who purchased the post using
- * the myCRED Sell Content add-on.
- * @requires myCRED 1.4 or higher
- * @version 1.1
- */
- add_filter( 'mycred_add', 'change_post_ownership_on_content_purchase', 2, 3 );
- function change_post_ownership_on_content_purchase( $reply, $request, $mycred ) {
- // Make sure we hook in when someone purchases content
- if ( $request['ref'] != 'buy_content' ) return $reply;
- // Make sure this is not the author payout (if used)
- if ( !isset( $request['data']['seller'] ) ) return $reply;
- // Start by getting the post from the reference id
- $post = get_post( (int) $request['ref_id'] );
- // Make sure the post still exist
- if ( isset( $post->post_author ) && $post->post_author != $request['user_id'] ) {
- $new_post_args = array();
- // Supply ID to indicate that this is an update
- $new_post_args['ID'] = (int) $request['ref_id'];
- // Items required for post update
- $new_post_args['post_title'] = $post->post_title;
- $new_post_args['post_content'] = $post->post_content;
- $new_post_args['post_status'] = $post->post_status;
- $new_post_args['post_type'] = $post->post_type;
- // New author
- $new_post_args['post_author'] = $request['user_id'];
- // Update
- wp_insert_post( $new_post_args );
- }
- return $reply;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement