' . $res['message'] . ' ' . $edit_link . '.
';
}
}
/**
* Build the success massage
*
* @param int $post_id
* @param string $post_type
* @return array
*/
private function get_success_response( $post_id, $post_type ) {
$post_type_object = get_post_type_object( $post_type );
$post_type_label = $post_type_object->labels->singular_name;
$edit_url = add_query_arg(
array(
'action' => 'edit',
'post' => $post_id,
),
admin_url( 'post.php' )
);
return [
'message' => sprintf( __( 'A new copied %s is created.', 'content-blocks-builder' ), strtolower( $post_type_label ) ),
'edit_url' => $edit_url,
'edit_label' => esc_attr__( 'Edit' ),
];
}
/**
* Enqueue editor assets
*
* @return void
*/
public function enqueue_block_editor_assets() {
$screen = get_current_screen();
if ( $this->validate_post_type( $screen->post_type ) ) {
// Access file.
$copy_post_asset = $this->the_plugin_instance->include_file( 'build/copy-post.asset.php' );
// Scripts.
wp_enqueue_script(
'cbb-copy-post',
$this->the_plugin_instance->get_file_uri( '/build/copy-post.js' ),
$copy_post_asset['dependencies'] ?? [],
$this->the_plugin_instance->get_script_version( $copy_post_asset ),
[ 'in_footer' => true ]
);
// Add translation.
wp_set_script_translations( 'cbb-copy-post', 'content-blocks-builder' );
}
}
/**
* Determine if the current user has edit access to the source post.
*
* @param int $post_id Source post ID (the post being copied).
* @return bool True if user has the meta cap of `edit_post` for the given post ID, false otherwise.
*/
protected function user_can_access_post( $post_id ) {
return current_user_can( 'edit_post', $post_id );
}
/**
* Validate the post type to be used for the target post.
*
* @param WP_Post $post Post object of current post in listing.
* @return bool True if the post type is in a list of supported psot types; false otherwise.
*/
protected function validate_post_type( $post_type, $post = null ) {
/**
* Fires when determining if the "Copy" row action should be made available.
* Allows overriding supported post types.
*
* @param array Post types supported by default.
* @param WP_Post $post Post object of current post in listing.
*/
$valid_post_types = apply_filters(
'cbb_copy_item_post_types',
[
'boldblocks_block',
'boldblocks_variation',
'boldblocks_pattern',
'post',
'page',
],
$post
);
return in_array( $post_type, $valid_post_types, true );
}
}
endif;