-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow use_filters
change when creating post
#267
base: trunk
Are you sure you want to change the base?
Conversation
Thank you @xipasduarte for working on this PR. I don't think this is the right solution as all of the filters will be activated. There is no way of only activating certain filters. duplicate-post/src/post-duplicator.php Lines 101 to 111 in 1b790c1
duplicate-post/src/post-duplicator.php Lines 207 to 216 in 1b790c1
duplicate-post/src/post-duplicator.php Lines 257 to 266 in 1b790c1
duplicate-post/src/post-duplicator.php Lines 283 to 292 in 1b790c1
|
@grappler Hello, I understand, but what you're saying is a level deeper. We could make this into a map that enables each use of [
'use_case_1' => true,
'use_case_2' => false,
] This would then allow us to change the conditions to: if ( $options['use_filters']['use_case_1'] ) {
// Run use_case_1
} Let me know if you have any other suggestions. |
Hello. Do you have any suggestions for this? Most There is an external (outside duplicate post) solution to do this. By hooking everything in the Something like: // Add excluded metas.
function my_custom_fields_filter( $meta_excludelist ) {
// Merges the defaults array with our own array of custom fields.
return array_merge( $meta_excludelist, [ 'my_custom_field1', 'my_custom_field2' ] );
}
add_filter( 'duplicate_post_excludelist_filter', 'my_custom_fields_filter' );
// Remove metas on insert.
add_action( 'wp_insert_post', function ( $post_id ) {
// Check if this is a rewrite
$is_rewrite = get_post_meta( '_dp_is_rewrite_republish_copy', $post_id, true );
if ( $is_rewrite ) {
// Get excluded metas.
$excluded_metas = apply_filters( 'duplicate_post_excludelist_filter', [] );
// Delete excluded metas.
foreach ( $excluded_metas as $meta_key ) {
delete_post_meta( $meta_key, $post_id );
}
}
}, 10 ); |
Context
This was an issue encountered while using the Distributor plugin, but fixing it can allow for greater compatibility with other plugins. When duplicating a post provide a way to enable filtering the original data that gets copied (post data, meta values and terms).
We opted not to include all instances of
use_filters
because one was already addressed in #244, even though the filter's name might need some adjusting.Summary
This PR can be summarized in the following changelog entry:
Adds a new filter
duplicate_post_create_duplicate_use_filters
to enable filtering the original data that gets copied (post data, meta values and terms).Relevant technical choices:
The prefix for the filter name was kept consistent with the rest of the plugin, while adding specific details with function and property being filtered.
Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
'excluded_meta_key'
is not present in the new post.Relevant test scenarios
Test instructions for QA when the code is in the RC
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
UI changes
Documentation
Quality assurance
Fixes #204