• Resolved furi3r

    (@furi3r)


    Hello,

    I tried to use the hooks dp_duplicate_page and dp_duplicate_post (both just in case) to hook when a custom post type is duplicated.
    I need to remove some metadata.

    But it seems those hooks are never reached, I tried to die in the hook but nothing happens.
    I tried different priorities also..

    Do you have any idea what can possibly be happening?

    Regards.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Enrico Battocchi

    (@lopo)

    Hi,
    you can check if the hooks are being called by watching if the taxonomies or the custom fields are cloned with the post, as they are copied using the very hooks you’re mentioning…

    How are you registering functions with the hooks? Is it a custom plugin or is it in your theme’s functions.php?

    Thread Starter furi3r

    (@furi3r)

    Hello @lopo
    Yes, indeed it is duplicating all metadata associated with the custom post (including custom fields and taxonomy information)

    I added the filter on functions.php (also on my custom plugin) but with no success:

    add_action('dp_duplicate_post', 'test_clone', 90, 2);
    add_action('dp_duplicate_page', 'test_clone', 90, 2);
    
    function test_clone($new_post_id, $old_post_object)
    {
    	add_post_meta($new_post_id, 'test_duplication', 1);
    	wp_mail( 'xxx', 'duplicate', 'duplication od' . $new_post_id);
    }

    NEither I get the email, neither test_duplication is added as metadata.
    I tested different priorities to but same result.

    Any idea?

    Plugin Author Enrico Battocchi

    (@lopo)

    Hi @furi3r,
    I tested your code on a couple of sites but it looks like it’s working to me…

    Can you check the error log of your server to look for any message that can be relevant?
    Can you try to add the action with priority 5 instead of 90? (so it’s the first one called and if the others have any problems it’s already ended).

    Thread Starter furi3r

    (@furi3r)

    Hello Lopo

    I think I’m missing something,
    I went directly to the plugin and created the hook and still not working there.
    Then I went to
    duplicate_post_copy_post_meta_info
    And commented out
    //add_post_meta($new_id, $meta_key, duplicate_post_wp_slash($meta_value));
    That I believe is where the meta data is added to the clone, and still is cloning the metadata…

    Is there the metadata cloned somewhere else? Or I’m just becoming crazy, this is magic 😀

    Plugin Author Enrico Battocchi

    (@lopo)

    Hi @furi3r,
    first of all, I’d recommend to update the plugin, I’ve released version 3.2 a few hours ago. While I don’t think it will solve the issue, one never knows…

    Yes, that’s the line that copies the metadata, and there’s no other point in the code…
    That’s quite a mystery!
    Which custom post type are you trying to duplicate? Is it added by a plugin? If so, maybe the plugin has added its own duplicate feature? (For example, Woocommerce does)

    Thread Starter furi3r

    (@furi3r)

    You were right Lopo, my bad, that custom post type had integrated a duplicate option i was messing up with your plugin.
    Please close the ticket and sorry for the inconveniences.

    Thread Starter furi3r

    (@furi3r)

    Closing

    Plugin Author Enrico Battocchi

    (@lopo)

    Hi!
    Never mind, glad to hear it’s not my plugin’s fault 🙂

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘hooks not working’ is closed to new replies.