post_type, ['page', 'post'], true)) { return false; } $content = $post->post_content; $clean = preg_replace('/\[aiwest_header\s*\/?\]/i', '', $content); $clean = preg_replace('/\[aiwest_footer\s*\/?\]/i', '', $clean); if ($clean === $content) { return 'unchanged'; } if (class_exists('AIWEST_Undo')) { AIWEST_Undo::snapshot($post_id, 'canvas_clean_shortcodes', __('Snapshot before removing duplicated AI Header/Footer shortcodes.', 'ai-webmaster-studio')); } $result = wp_update_post([ 'ID' => $post_id, 'post_content' => $clean, ], true); if (is_wp_error($result)) { return $result; } return 'cleaned'; } public static function enable_for_page($post_id) { $post_id = intval($post_id); if (!$post_id || get_post_type($post_id) !== 'page') { return false; } if (!self::is_canvas_page($post_id)) update_post_meta($post_id, '_aiwest_canvas_previous_template', get_page_template_slug($post_id) ?: 'default'); update_post_meta($post_id, '_aiwest_canvas_enabled', 'yes'); update_post_meta($post_id, '_wp_page_template', self::TEMPLATE_SLUG); return true; } public static function disable_for_page($post_id) { $post_id = intval($post_id); if (!$post_id || get_post_type($post_id) !== 'page') { return false; } delete_post_meta($post_id, '_aiwest_canvas_enabled'); if (get_page_template_slug($post_id) === self::TEMPLATE_SLUG) { update_post_meta($post_id, '_wp_page_template', get_post_meta($post_id, '_aiwest_canvas_previous_template', true) ?: 'default'); delete_post_meta($post_id, '_aiwest_canvas_previous_template'); } return true; } } AIWEST_Canvas::init();