permissions_helper = $permissions_helper; $this->register_hooks(); } /** * Adds hooks to integrate with WordPress. * * @return void */ public function register_hooks() { \add_filter( 'removable_query_args', [ $this, 'add_removable_query_args' ], 10, 1 ); \add_action( 'admin_notices', [ $this, 'add_clone_admin_notice' ] ); \add_action( 'admin_notices', [ $this, 'add_rewrite_and_republish_admin_notice' ] ); \add_action( 'enqueue_block_editor_assets', [ $this, 'add_rewrite_and_republish_block_editor_notice' ] ); } /** * Adds vars to the removable query args. * * @param array $removable_query_args Array of query args keys. * * @return array The updated array of query args keys. */ public function add_removable_query_args( $removable_query_args ) { if ( \is_array( $removable_query_args ) ) { $removable_query_args[] = 'cloned'; $removable_query_args[] = 'rewriting'; } return $removable_query_args; } /** * Shows a notice after the Clone link action has succeeded. * * @return void */ public function add_clone_admin_notice() { if ( ! empty( $_REQUEST['cloned'] ) ) { if ( ! $this->permissions_helper->is_classic_editor() ) { return; } $copied_posts = \intval( $_REQUEST['cloned'] ); \printf( '
' . \esc_html( /* translators: %s: Number of posts copied. */ \_n( '%s item copied.', '%s items copied.', $copied_posts, 'duplicate-post' ) ) . '
' . \esc_html__( 'You can now start rewriting your post in this duplicate of the original post. If you click "Republish", your changes will be merged into the original post and you’ll be redirected there.', 'duplicate-post' ) . '