Skip to content

Commit

Permalink
added (Copy) postfix to duplicated block title if needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fellan-91 committed Oct 8, 2024
1 parent 47ea1e4 commit 2521d00
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions classes/class-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,14 @@ public function duplicate_block( $block_id ) {
$new_post_author = $current_user->ID;

if ( isset( $post ) && $post ) {
$post_name = $post->post_name;
$post_name = $post->post_name;
$post_title = $post->post_title;
$copy_postfix = esc_html__( '(Copy)', 'lazy-blocks' );

// Added (Copy) postfix to duplicated block title if needed.
if ( ! empty( $post_title ) && ! str_contains( $post_title, $copy_postfix ) ) {
$post_title = $post_title . ' ' . $copy_postfix;
}

// New post data array.
$args = array(
Expand All @@ -634,7 +641,7 @@ public function duplicate_block( $block_id ) {
'post_password' => $post->post_password,
// We must set the status to publish for the slug generation function (wp_unique_post_slug) to work correctly.
'post_status' => 'publish',
'post_title' => $post->post_title,
'post_title' => $post_title,
'post_type' => $post->post_type,
'to_ping' => $post->to_ping,
'menu_order' => $post->menu_order,
Expand Down

0 comments on commit 2521d00

Please sign in to comment.