| @@ -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 | } |
| @@ -359,8 +363,30 @@ | ||
| 359 | 363 | * @param WP_Post $post Post object of current post in listing. |
| 360 | 364 | * @return bool True if the post type is in a list of supported psot types; false otherwise. |
| 361 | 365 | */ |
| 362 | 366 | protected function validate_post_type( $post_type, $post = null ) { |
| 367 | + /** | |
| 368 | + * Fires when determining if the "Copy" row action should be made available. | |
| 369 | + * Allows overriding supported post types. | |
| 370 | + * | |
| 371 | + * @param array Post types supported by default. | |
| 372 | + * @param WP_Post $post Post object of current post in listing. | |
| 373 | + */ | |
| 374 | + $valid_post_types = apply_filters( | |
| 375 | + 'cbb_copy_item_validate_post_types', | |
| 376 | + $this->get_supported_post_types(), | |
| 377 | + $post | |
| 378 | + ); | |
| 379 | + | |
| 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() { | |
| 363 | 389 | // Get all public post types. |
| 364 | 390 | $public_types = array_keys( get_post_types( [ 'public' => true ] ) ); |
| 365 | 391 | |
| 366 | 392 | /** |
| @@ -369,14 +395,11 @@ | ||
| 369 | 395 | * |
| 370 | 396 | * @param array Post types supported by default. |
| 371 | 397 | * @param WP_Post $post Post object of current post in listing. |
| 372 | 398 | */ |
| 373 | - $valid_post_types = apply_filters( | |
| 374 | - 'cbb_copy_item_post_types', | |
| 399 | + return apply_filters( | |
| 400 | + 'cbb_copy_item_supported_post_types', | |
| 375 | 401 | $public_types, |
| 376 | - $post | |
| 377 | 402 | ); |
| 378 | - | |
| 379 | - return in_array( $post_type, $valid_post_types, true ); | |
| 380 | 403 | } |
| 381 | 404 | } |
| 382 | 405 | endif; |