Astra_Ext_Advanced_Hooks_Loader::handle_duplicate_layout()

Handle duplicate layout action from admin table.


Description


Source

File: addons/advanced-hooks/classes/class-astra-ext-advanced-hooks-loader.php

		public function handle_duplicate_layout() {
			if ( ! isset( $_GET['action'] ) || 'ast_duplicate_layout' !== $_GET['action'] ) {
				return;
			}

			$post_id = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : 0;
			$nonce   = isset( $_GET['ast_duplicate_nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['ast_duplicate_nonce'] ) ) : '';

			if ( ! $post_id || ! wp_verify_nonce( $nonce, 'ast_duplicate_layout_' . $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
				wp_die( esc_html__( 'Security check failed', 'astra-addon' ) );
			}

			$original_post = get_post( $post_id );

			if ( ! $original_post || ASTRA_ADVANCED_HOOKS_POST_TYPE !== $original_post->post_type ) {
				wp_die( esc_html__( 'Invalid layout', 'astra-addon' ) );
			}

			// Use the common helper function from the Theme Builder class
			$theme_builder = Astra_Addon_Theme_Builder::get_instance();
			$new_post_id   = $theme_builder->create_layout_duplicate( $post_id );

			if ( is_wp_error( $new_post_id ) ) {
				wp_die( esc_html__( 'Failed to duplicate layout', 'astra-addon' ) );
			}

			wp_safe_redirect( admin_url( 'edit.php?post_type=' . ASTRA_ADVANCED_HOOKS_POST_TYPE ) );
			exit;
		}

Changelog

Changelog
Version Description
4.11.13 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.