First things first, povestea. Recent, am facut un plugin pe Wordpress WordPress - WP - Keywords To Tooltip | CodeCanyon Dupa cateva zile, cineva a venit cu cererea sa fie compatibil cu WP Multi Site, nu am facut asa ceva niciodata, dar am reusit sa-l fac sa mearga in mai putin de o ora. De ce ? Am avut codul scris in OOP, aveam urmatoarele metode : public function _activationHook() { global $wpdb; $query = file_get_contents($this->scriptBasePath . 'model/install.sql'); $query = str_replace($this->database->_table_prefix , $wpdb->base_prefix . $this->database->_table_prefix, $query); $queries = explode(';', $query); foreach($queries as $query) if(strlen($query)> 20) $response = $wpdb->query($query); } public function _deactivationHook() { global $wpdb; $wpdb->query("DROP TABLE IF EXISTS " . $this->database->_keyword_table); } Ce mai trebuia sa adaug ca acesta sa mearga pe WP Multi site ? Nu prea multe defapt, a fost chiar simplu, trebuia sa fac urmatorul cod pentru fiecare site inainte de a executa metodele celalte doua ( cand era Network Activate si Deactive ) $old_blog = $wpdb->blogid; $blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}"); foreach ($blogids as $blog_id) { switch_to_blog($blog_id); // Actiunea Propriu zisa activate sau deactivate. } switch_to_blog($old_blog); Norocul meu era ca am scris totul in OOP, si aveam controll total, am schimbat repede putin functiile, am facut un proxy la activate si deactive public function _wpActivationHook($networkwide) { $this->_networkPropagationHook('_internalActivationHook', $networkwide); } public function _wpDeactivationHook($networkwide) { $this->_networkPropagationHook('_internalDeactivationHook', $networkwide); } De ce am scris aceasta functie de proxy ? La fiecare din astea, faceam acelas lucru inafara de o singura functie, asa ca am generalizat codul, for the "sake of clean", teoretic inainte de anterioarele active si deactivate mai trebuia sa faci niste pasi, si dupa activate sau deactivate sa dau switch inapoi la blogul initial. Well, cam ce a iesit ? public function _wpActivationHook($networkwide) { $this->_networkPropagationHook('_internalActivationHook', $networkwide); } public function _wpDeactivationHook($networkwide) { $this->_networkPropagationHook('_internalDeactivationHook', $networkwide); } public function _networkPropagationHook($propagationAction, $networkwide) { global $wpdb; if (function_exists('is_multisite') && is_multisite()) { if ($networkwide) { $old_blog = $wpdb->blogid; $blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}"); foreach ($blogids as $blog_id) { switch_to_blog($blog_id); $this->$propagationAction(); } switch_to_blog($old_blog); return; } } $this->$propagationAction(); } public function _internalActivationHook() { global $wpdb; $query = file_get_contents($this->scriptBasePath . 'model/install.sql'); $query = str_replace($this->database->_table_prefix , $wpdb->base_prefix . $this->database->_table_prefix, $query); $queries = explode(';', $query); foreach($queries as $query) if(strlen($query)> 20) $response = $wpdb->query($query); } public function _internalDeactivationHook() { global $wpdb; $wpdb->query("DROP TABLE IF EXISTS " . $this->database->_keyword_table); } Concluzia : WP Multi Site nu e mare branza, sunt mai multe lucruri care trebuie luate in considerare, dar daca e vorba despre baza de date, e foarte simplu, prefixul se baga automat, $wpdb->_table_prefix e setat in functie de website daca dai switch_to_blog() cand trebuie. Mai este unca un lucru, la generarea fisierelor, recomand sa ai functii, pentru ca daca ai multi site, ai fisere separate pentru fiecare fisier ( daca sunt editate constant de user ) Asa ca am scris urmatoarea functie private function _getCurrentFrontGeneratedStylePath() { return (function_exists('is_multisite') && is_multisite()) ? $this->frontGeneratedStylePathPrefix . '-' . get_current_blog_id() . $this->frontGeneratedStylePathPostfix : $this->frontGeneratedStylePathPrefix . $this->frontGeneratedStylePathPostfix; } Verific daca e multi_site, daca e multi site, mai adaug un -[blog-id] in capatul fiserelor ( apoi extensia "frontGeneratedStylePathPostfix" ) Ok, sper ca v-a placut, am scris ceva in timp ce imi beam cafeaua inainte de ore . Feedback & Comments are welcome.