Hooks & Filters

Developer reference for customizing Nixa Duplicate behavior.

Actions

nixa_duplicate_before_duplicate

Fires before a post is duplicated.

add_action('nixa_duplicate_before_duplicate', function($source_id) {
    // Do something before duplication
    error_log("About to duplicate post: $source_id");
}, 10, 1);

nixa_duplicate_after_duplicate

Fires after a post is duplicated.

add_action('nixa_duplicate_after_duplicate', function($new_id, $source_id) {
    // Do something after duplication
    update_post_meta($new_id, '_duplicated_from', $source_id);
    update_post_meta($new_id, '_duplicated_at', current_time('mysql'));
}, 10, 2);

Filters

nixa_duplicate_post_data

Modify the post data before insertion.

add_filter('nixa_duplicate_post_data', function($data, $source_id) {
    // Modify the title
    $data['post_title'] = 'COPY: ' . $data['post_title'];
    
    // Change the status
    $data['post_status'] = 'pending';
    
    return $data;
}, 10, 2);

nixa_duplicate_post_meta

Modify or filter meta data before copying.

add_filter('nixa_duplicate_post_meta', function($meta, $source_id, $new_id) {
    // Remove sensitive meta
    unset($meta['_secret_key']);
    unset($meta['_api_token']);
    
    // Add custom meta
    $meta['_is_duplicate'] = '1';
    
    return $meta;
}, 10, 3);

nixa_duplicate_taxonomies

Modify taxonomies before copying.

add_filter('nixa_duplicate_taxonomies', function($taxonomies, $source_id) {
    // Remove a specific taxonomy
    unset($taxonomies['post_tag']);
    
    return $taxonomies;
}, 10, 2);

nixa_duplicate_title_suffix

Customize the title suffix dynamically.

add_filter('nixa_duplicate_title_suffix', function($suffix, $source_id) {
    // Add date to suffix
    return ' (Copy - ' . date('Y-m-d') . ')';
}, 10, 2);

nixa_duplicate_can_duplicate

Control whether a user can duplicate a specific post.

add_filter('nixa_duplicate_can_duplicate', function($can, $post_id, $user_id) {
    // Prevent duplicating posts older than 1 year
    $post = get_post($post_id);
    $post_date = strtotime($post->post_date);
    $one_year_ago = strtotime('-1 year');
    
    if ($post_date < $one_year_ago) {
        return false;
    }
    
    return $can;
}, 10, 3);

Example: Complete Customization

// Custom duplication behavior
add_action('nixa_duplicate_after_duplicate', function($new_id, $source_id) {
    // Track duplication
    update_post_meta($new_id, '_source_post', $source_id);
    
    // Notify admin
    $post = get_post($new_id);
    $user = wp_get_current_user();
    
    wp_mail(
        get_option('admin_email'),
        'Post Duplicated',
        sprintf('%s duplicated "%s"', $user->display_name, $post->post_title)
    );
}, 10, 2);

// Exclude certain meta keys
add_filter('nixa_duplicate_post_meta', function($meta) {
    $exclude = ['_edit_lock', '_edit_last', '_wp_old_slug'];
    foreach ($exclude as $key) {
        unset($meta[$key]);
    }
    return $meta;
});
Pro Hooks

Pro version adds additional hooks for presets, bulk operations, multisite, and more.