• Hi,

    I used this duplication function
    http://rudrastyh.com/wordpress/duplicate-post.html
    to achieve the ability to duplicate post from the front-end.

    The modification I did doesn’t seems to be the right way to integrate such a thing in WordPress

    This is what I did:-
    -Change the function so it accepts one parameter rd_duplicate_post_as_draft($post_id)
    -Remove the checking for the post/get etc if (! ( isse….
    -Remove the redirect code (stopped working!/error)
    -Add return new post id (didn’t help)
    -Removed the second function which add the duplicate link to wp-admin

    Then in the page template I want to add the button/link I added the same stuff from the original function at first which checks the posts/gets values if ( isset( $_GET[‘post’]) || …..
    then I call the function in function.php
    $new_post_id = rd_duplicate_post_as_draft($post_id);

    The duplication link reload the same page + passing the 2 arguments

    Issues:-
    I cant redirect to the new duplicated page (header already set…)
    The parameters stays on the address bar which means refreshing = new duplication!

    What is the right way to integrate duplication function on the frontend?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Have you tried to put the redirection function between

    ob_start();
    //redirect
    ob_end_flush();

    And remove the blank lines from code? cause if the redirect works then no posts will be made again as the parameter is gone, unless you make conditions..

    Thread Starter et3rnal

    (@et3rnal)

    Tried it and didn’t help 😐
    Is there a hook I can call the function with instead ?

    at the moment I used js to redirect but this is doesn’t look like a good solution.

    How about the condition ? what do you mean ?

    thanks

    Hi!

    I was thinking of something like this:

    http://pastebin.com/TM2sJ6uK

    If it didn’t work as well, then let us know, I’ll try to look it on my local installation..

    Thread Starter et3rnal

    (@et3rnal)

    So this is the function I’m using (the only difference is mine has no $verify ), however I have changed it to work from the front-end instead and here is what I have done

    Changed:
    rd_duplicate_post_as_draft()
    to
    rd_duplicate_post_as_draft($post_id)

    Then:
    removed the lines from 6 to 14

    and:
    removed line 84 and 85 (the redirect and exit as they through the error)
    and add instead
    return $new_post_id;

    Finally I removed the add_action, as I don’t know what to hook it with instead and decided to call it manually 🙁

    ————-

    In the front end file I have

    if ( isset( $_GET['post']) || isset( $_POST['post'])  || ( isset($_REQUEST['action']) && 'rd_duplicate_post_as_draft' == $_REQUEST['action'] ) ) {
    
    	//get the original post id
    	$post_id = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']);
    	$new_post_id = rd_duplicate_post_as_draft($post_id);
    
    	$page = get_permalink( $new_post_id );
    }

    Which will catch the request and duplicate the post and it is also where I have the JavaScript redirecting function called

    and finally this is the duplication button

    <a href="<?php echo site_url(); ?>/dashboard/?action=rd_duplicate_post_as_draft&post=<?php echo $post->ID ?>">Duplicate</a>

    and obviously I removed the rd_duplicate_post_link( $actions, $post ) function.
    —————-

    What I would love to do instead of all this, is re-using the add_action to have it triggered from the front-end

    Thanks for your help

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Duplication function’ is closed to new replies.