fix: plugin activation no longer modifies WooCommerce pages
- Removed shortcode replacement for Cart, Checkout, My Account pages - WooCommerce pages now keep their original [woocommerce_*] shortcodes - Plugin only creates dedicated SPA page (/store) with [woonoow_spa] - Auto-sets spa_page in appearance settings This aligns with template override approach - WC pages render normally when SPA is disabled, and redirect to SPA when mode is 'full'.
This commit is contained in:
@@ -23,100 +23,56 @@ class Installer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create or update WooNooW pages
|
* Create WooNooW SPA page only
|
||||||
* Smart detection: reuses existing WooCommerce pages if they exist
|
* No longer modifies WooCommerce pages - we use template overrides instead
|
||||||
*/
|
*/
|
||||||
private static function create_pages() {
|
private static function create_pages() {
|
||||||
$pages = [
|
// Only create the main SPA page (Store)
|
||||||
'shop' => [
|
// WooCommerce pages are NOT modified - we use template overrides
|
||||||
'title' => 'Shop',
|
|
||||||
'content' => '[woonoow_shop]',
|
|
||||||
'wc_option' => 'woocommerce_shop_page_id',
|
|
||||||
],
|
|
||||||
'cart' => [
|
|
||||||
'title' => 'Cart',
|
|
||||||
'content' => '[woonoow_cart]',
|
|
||||||
'wc_option' => 'woocommerce_cart_page_id',
|
|
||||||
],
|
|
||||||
'checkout' => [
|
|
||||||
'title' => 'Checkout',
|
|
||||||
'content' => '[woonoow_checkout]',
|
|
||||||
'wc_option' => 'woocommerce_checkout_page_id',
|
|
||||||
],
|
|
||||||
'account' => [
|
|
||||||
'title' => 'My Account',
|
|
||||||
'content' => '[woonoow_account]',
|
|
||||||
'wc_option' => 'woocommerce_myaccount_page_id',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($pages as $key => $page_data) {
|
$spa_page_id = get_option('woonoow_store_page_id');
|
||||||
$page_id = null;
|
|
||||||
|
|
||||||
// Strategy 1: Check if WooCommerce already has a page set
|
// Check if SPA page already exists
|
||||||
if (isset($page_data['wc_option'])) {
|
if ($spa_page_id && get_post($spa_page_id)) {
|
||||||
$wc_page_id = get_option($page_data['wc_option']);
|
return; // Already exists
|
||||||
if ($wc_page_id && get_post($wc_page_id)) {
|
}
|
||||||
$page_id = $wc_page_id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strategy 2: Check if WooNooW already created a page
|
// Search for existing "Store" page
|
||||||
if (!$page_id) {
|
$existing_page = get_page_by_title('Store', OBJECT, 'page');
|
||||||
$woonoow_page_id = get_option('woonoow_' . $key . '_page_id');
|
if ($existing_page) {
|
||||||
if ($woonoow_page_id && get_post($woonoow_page_id)) {
|
$spa_page_id = $existing_page->ID;
|
||||||
$page_id = $woonoow_page_id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strategy 3: Search for page by title
|
// Update with SPA shortcode if needed
|
||||||
if (!$page_id) {
|
if (!has_shortcode($existing_page->post_content, 'woonoow_spa')) {
|
||||||
$existing_page = get_page_by_title($page_data['title'], OBJECT, 'page');
|
update_post_meta($spa_page_id, '_woonoow_original_content', $existing_page->post_content);
|
||||||
if ($existing_page) {
|
wp_update_post([
|
||||||
$page_id = $existing_page->ID;
|
'ID' => $spa_page_id,
|
||||||
}
|
'post_content' => '[woonoow_spa]',
|
||||||
}
|
|
||||||
|
|
||||||
// If page exists, update its content with our shortcode
|
|
||||||
if ($page_id) {
|
|
||||||
$current_post = get_post($page_id);
|
|
||||||
|
|
||||||
// Only update if it doesn't already have our shortcode
|
|
||||||
if (!has_shortcode($current_post->post_content, 'woonoow_' . $key)) {
|
|
||||||
// Backup original content
|
|
||||||
update_post_meta($page_id, '_woonoow_original_content', $current_post->post_content);
|
|
||||||
|
|
||||||
// Update with our shortcode
|
|
||||||
wp_update_post([
|
|
||||||
'ID' => $page_id,
|
|
||||||
'post_content' => $page_data['content'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// No existing page found, create new one
|
|
||||||
$page_id = wp_insert_post([
|
|
||||||
'post_title' => $page_data['title'],
|
|
||||||
'post_content' => $page_data['content'],
|
|
||||||
'post_status' => 'publish',
|
|
||||||
'post_type' => 'page',
|
|
||||||
'post_author' => get_current_user_id(),
|
|
||||||
'comment_status' => 'closed',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($page_id && !is_wp_error($page_id)) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Create new SPA page
|
||||||
|
$spa_page_id = wp_insert_post([
|
||||||
|
'post_title' => 'Store',
|
||||||
|
'post_content' => '[woonoow_spa]',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
'post_type' => 'page',
|
||||||
|
'post_author' => get_current_user_id() ?: 1,
|
||||||
|
'comment_status' => 'closed',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
// Store page ID and update WooCommerce settings
|
// Save SPA page ID
|
||||||
if ($page_id && !is_wp_error($page_id)) {
|
if ($spa_page_id && !is_wp_error($spa_page_id)) {
|
||||||
update_option('woonoow_' . $key . '_page_id', $page_id);
|
update_option('woonoow_store_page_id', $spa_page_id);
|
||||||
|
|
||||||
if (isset($page_data['wc_option'])) {
|
// Also set it in appearance settings
|
||||||
update_option($page_data['wc_option'], $page_id);
|
$appearance_settings = get_option('woonoow_appearance_settings', []);
|
||||||
}
|
if (!isset($appearance_settings['general'])) {
|
||||||
|
$appearance_settings['general'] = [];
|
||||||
}
|
}
|
||||||
|
$appearance_settings['general']['spa_page'] = $spa_page_id;
|
||||||
|
update_option('woonoow_appearance_settings', $appearance_settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user