Plugin Directory

Changeset 3447932


Ignore:
Timestamp:
01/27/2026 01:49:33 PM (2 months ago)
Author:
aarsiv
Message:

multi site support

Location:
shipi
Files:
15 added
2 edited

Legend:

Unmodified
Added
Removed
  • shipi/trunk/readme.txt

    r3409924 r3447932  
    33Tags: WooCommerce shipping, shipping label, shipping rates, DHL, FedEx, UPS, carrier integration, live rates, WooCommerce 
    44Requires at least: 4.0.1 
    5 Tested up to: 6.8
    6 Stable tag: 1.3.0 
    7 Requires PHP: 5.6 
     5Tested up to: 6.9
     6Stable tag: 1.3.1
     7Requires PHP: 5.6
     8Network: true 
    89License: GPLv3 or later 
    910License URI: https://www.gnu.org/licenses/gpl-3.0.html 
     
    7677Yes. Shipi automatically tracks shipment progress and updates WooCommerce order status accordingly.
    7778
     79= Does Shipi support WordPress Multisite? = 
     80Yes! Shipi is fully compatible with WordPress Multisite networks. You can network-activate the plugin or activate it on individual sites. Each site in your network can have its own Shipi account connection and configuration. Settings, integration keys, and shipping data are stored separately for each site.
     81
    7882== Third-Party Services ==
    7983
     
    96100
    97101== Changelog ==
     102
     103= 1.3.1 = 
     104* Added WordPress Multisite support
     105* Improved WooCommerce detection for multisite networks
     106* Added activation/deactivation hooks
     107* Added automatic initialization for new sites in network-activated scenarios
    98108
    99109= 1.3.0 = 
  • shipi/trunk/shipi.php

    r3409924 r3447932  
    33 * Plugin Name: Shipi
    44 * Description: 15+ Shipping carriers in one package.
    5  * Version: 1.3.0
     5 * Version: 1.3.1
    66 * Author: Shipi
    77 * Author URI: https://myshipi.com/
     
    3030);
    3131
     32// Helper function to check if WooCommerce is active (multisite-aware)
     33function shipi_is_woocommerce_active() {
     34    // Check if WooCommerce class exists (most reliable method)
     35    if ( class_exists( 'WooCommerce' ) ) {
     36        return true;
     37    }
     38   
     39    // Load plugin.php if needed for is_plugin_active function
     40    if ( ! function_exists( 'is_plugin_active' ) ) {
     41        require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
     42    }
     43   
     44    // Check if plugin is active (multisite-aware function)
     45    if ( function_exists( 'is_plugin_active' ) ) {
     46        if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
     47            return true;
     48        }
     49    }
     50   
     51    // Fallback: Check active plugins (site-specific)
     52    $active_plugins = get_option( 'active_plugins', array() );
     53    if ( in_array( 'woocommerce/woocommerce.php', $active_plugins ) ) {
     54        return true;
     55    }
     56   
     57    // Check network-active plugins in multisite
     58    if ( is_multisite() ) {
     59        $network_active_plugins = get_site_option( 'active_sitewide_plugins', array() );
     60        if ( isset( $network_active_plugins['woocommerce/woocommerce.php'] ) ) {
     61            return true;
     62        }
     63    }
     64   
     65    return false;
     66}
     67
    3268// check is woocommerce is installed already.
    33 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
     69if ( shipi_is_woocommerce_active() ) {
    3470    if( !class_exists('shipi_Parent') ){
    3571        Class shipi_Parent {
     
    10481084    new shipi_Parent();
    10491085}
     1086
     1087/**
     1088 * Activation hook for single-site activation
     1089 * Note: For network activation, this runs for each site individually
     1090 */
     1091function shipi_activate( $network_wide = false ) {
     1092    // If network activation, we'll handle each site separately via wp_initialize_site
     1093    if ( $network_wide && is_multisite() ) {
     1094        // For network activation, just flush rewrite rules network-wide
     1095        // Individual site initialization happens in shipi_new_site_init
     1096        return;
     1097    }
     1098   
     1099    // For single-site activation, check WooCommerce
     1100    if ( ! shipi_is_woocommerce_active() ) {
     1101        deactivate_plugins( plugin_basename( __FILE__ ) );
     1102        wp_die(
     1103            esc_html__( 'Shipi requires WooCommerce to be installed and active. Please install and activate WooCommerce first.', 'shipi' ),
     1104            esc_html__( 'Plugin Activation Error', 'shipi' ),
     1105            array( 'back_link' => true )
     1106        );
     1107    }
     1108   
     1109    // Clear any transients
     1110    delete_transient( 'shipi_nonce_temp' );
     1111   
     1112    // Flush rewrite rules for REST API
     1113    flush_rewrite_rules();
     1114}
     1115
     1116/**
     1117 * Deactivation hook
     1118 */
     1119function shipi_deactivate() {
     1120    // Clear transients on deactivation
     1121    delete_transient( 'shipi_nonce_temp' );
     1122   
     1123    // Flush rewrite rules
     1124    flush_rewrite_rules();
     1125}
     1126
     1127/**
     1128 * Initialize plugin on new site creation (for network-activated plugins)
     1129 */
     1130function shipi_new_site_init( $site ) {
     1131    if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
     1132        require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
     1133    }
     1134   
     1135    // Only initialize if plugin is network-activated
     1136    if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
     1137        switch_to_blog( $site->blog_id );
     1138       
     1139        // Check if WooCommerce is active on this site
     1140        if ( shipi_is_woocommerce_active() ) {
     1141            // Plugin will auto-initialize when WooCommerce is detected
     1142            // No additional setup needed as the main class handles initialization
     1143        }
     1144       
     1145        restore_current_blog();
     1146    }
     1147}
     1148
     1149// Register activation hook
     1150register_activation_hook( __FILE__, 'shipi_activate' );
     1151
     1152// Register deactivation hook
     1153register_deactivation_hook( __FILE__, 'shipi_deactivate' );
     1154
     1155// Hook into new site creation for network-activated plugins
     1156if ( is_multisite() ) {
     1157    add_action( 'wp_initialize_site', 'shipi_new_site_init', 10, 1 );
     1158}
Note: See TracChangeset for help on using the changeset viewer.