| @@ -174,8 +174,9 @@ | ||
| 174 | 174 | 'post_author' => $new_author_id, |
| 175 | 175 | 'post_status' => 'draft', |
| 176 | 176 | 'post_type' => $post->post_type, |
| 177 | 177 | 'menu_order' => $post->menu_order, |
| 178 | + 'post_parent' => $post->post_parent, | |
| 178 | 179 | ); |
| 179 | 180 | |
| 180 | 181 | // Insert the post. |
| 181 | 182 | $new_post_id = wp_insert_post( $args ); |
| @@ -337,8 +338,11 @@ | ||
| 337 | 338 | $this->the_plugin_instance->get_script_version( $copy_post_asset ), |
| 338 | 339 | [ 'in_footer' => true ] |
| 339 | 340 | ); |
| 340 | 341 | |
| 342 | + // Load supported post types to JS. | |
| 343 | + wp_add_inline_script( 'cbb-copy-post', sprintf( 'const CBB_COPY_POST = %s;', wp_json_encode( [ 'postTypes' => $this->get_supported_post_types() ] ) ), 'before' ); | |
| 344 | + | |
| 341 | 345 | // Add translation. |
| 342 | 346 | wp_set_script_translations( 'cbb-copy-post', 'content-blocks-builder' ); |
| 343 | 347 | } |
| 344 | 348 | } |
| @@ -367,19 +371,35 @@ | ||
| 367 | 371 | * @param array Post types supported by default. |
| 368 | 372 | * @param WP_Post $post Post object of current post in listing. |
| 369 | 373 | */ |
| 370 | 374 | $valid_post_types = apply_filters( |
| 371 | - 'cbb_copy_item_post_types', | |
| 372 | - [ | |
| 373 | - 'boldblocks_block', | |
| 374 | - 'boldblocks_variation', | |
| 375 | - 'boldblocks_pattern', | |
| 376 | - 'post', | |
| 377 | - 'page', | |
| 378 | - ], | |
| 375 | + 'cbb_copy_item_validate_post_types', | |
| 376 | + $this->get_supported_post_types(), | |
| 379 | 377 | $post |
| 380 | 378 | ); |
| 381 | 379 | |
| 382 | 380 | return in_array( $post_type, $valid_post_types, true ); |
| 381 | + } | |
| 382 | + | |
| 383 | + /** | |
| 384 | + * Get the list of supported post types. | |
| 385 | + * | |
| 386 | + * @return array | |
| 387 | + */ | |
| 388 | + private function get_supported_post_types() { | |
| 389 | + // Get all public post types. | |
| 390 | + $public_types = array_keys( get_post_types( [ 'public' => true ] ) ); | |
| 391 | + | |
| 392 | + /** | |
| 393 | + * Fires when determining if the "Copy" row action should be made available. | |
| 394 | + * Allows overriding supported post types. | |
| 395 | + * | |
| 396 | + * @param array Post types supported by default. | |
| 397 | + * @param WP_Post $post Post object of current post in listing. | |
| 398 | + */ | |
| 399 | + return apply_filters( | |
| 400 | + 'cbb_copy_item_supported_post_types', | |
| 401 | + $public_types, | |
| 402 | + ); | |
| 383 | 403 | } |
| 384 | 404 | } |
| 385 | 405 | endif; |