public static function update($key, $value) { self::initialize(); if (!empty(self::$_cache[$key]) && self::$_cache[$key] == $value) { return; } self::$_cache[$key] = $value; if (empty(self::$_cache)) { return; } if (self::$_empty) { if (is_multisite()) { add_blog_option(NULL, self::$_name, self::$_cache); } else { add_option(self::$_name, self::$_cache); } self::$_empty = FALSE; } else { if (is_multisite()) { update_blog_option(NULL, self::$_name, self::$_cache); } else { update_option(self::$_name, self::$_cache); } } }
static function addOption($name, $value, $blogID = 1) { if (wpsIsMultisite()) { return add_blog_option($blogID, $name, $value); } return add_option($name, $value); }
/** * Init 'mucd_duplicable' options * @param string $blogs_value the value for blogs options * @param string $network_value the value for site option * @since 0.2.0 */ public static function init_duplicable_option($blogs_value = "no", $network_value = "all") { $network_blogs = wp_get_sites(array('limit' => MUCD_MAX_NUMBER_OF_SITE)); foreach ($network_blogs as $blog) { $blog_id = $blog['blog_id']; add_blog_option($blog_id, 'mucd_duplicable', $blogs_value); } add_site_option('mucd_duplicables', $network_value); }
function _archivesCalendar_activate() { global $wpdb; $default_options = array("css" => 1, "theme" => "calendrier", "js" => 1, "show_settings" => 1, "filter" => 0, "javascript" => "jQuery(document).ready(function(\$){\n\t\$('.calendar-archives').archivesCW();\n});"); $default_custom_css = file_get_contents(plugins_url('/admin/default_custom.css', __FILE__)); $default_themer_options = array("arw-theme1" => $default_custom_css, "arw-theme2" => ''); if (!($options = get_option('archivesCalendar'))) { // if new installation copy default options into the DB $options = $default_options; } else { // if reactivation or after update: merge existing settings with the defaults in case if new options were added in the update array_merge($default_options, $options); } if (!($themer_options = get_option('archivesCalendarThemer'))) { $themer_options = $default_themer_options; } foreach ($themer_options as $ctheme => $css) { if ($css) { if (is_writable('../wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/themes/')) { if (isMU()) { $old_blog = $wpdb->blogid; $blogids = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}"); foreach ($blogids as $blogid) { $blog_id = $blogid->blog_id; switch_to_blog($blog_id); $filename = '../wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/themes/' . $ctheme . '-' . $wpdb->blogid . '.css'; $themefile = fopen($filename, "w") or die("Unable to open file!"); fwrite($themefile, $css); fclose($themefile); } switch_to_blog($old_blog); } else { $filename = '../wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/themes/' . $ctheme . '.css'; $themefile = fopen($filename, "w") or die("Unable to open file!"); fwrite($themefile, $css); fclose($themefile); } } else { echo "<p>Can't write in `/wp-content/plugins/" . dirname(plugin_basename(__FILE__)) . "/themes/" . " </p>"; } } } if (isMU()) { update_blog_option($wpdb->blogid, 'archivesCalendar', $options); add_blog_option($wpdb->blogid, 'archivesCalendar', $options); add_blog_option($wpdb->blogid, 'archivesCalendarThemer', $themer_options); } else { update_option('archivesCalendar', $options); add_option('archivesCalendar', $options); add_option('archivesCalendarThemer', $themer_options); } }
/** Save default plugin settings on activation */ public static function instance() { $general_settings = array(); $general_settings['set_log_out_url'] = 'current_view_page'; $general_settings['set_login_redirect'] = 'dashboard'; $general_settings['set_login_url'] = \pp_default_pages\Login::instance(); $general_settings['set_registration_url'] = \pp_default_pages\Registration::instance(); $general_settings['set_lost_password_url'] = \pp_default_pages\Password_Reset::instance(); if (is_multisite()) { add_blog_option(null, 'pp_settings_data', $general_settings); } else { add_option('pp_settings_data', $general_settings); } }
/** RESTful endpoint for this multisite function. * * Get $_REQUEST options for this endpoint: * * u (optional) -- Username (if not logged in) * p (optional) -- Password (if not logged in) * nonce (required) -- the security nonce for this API function * blog_id (required) if not set then current site id is used * key (required) key of the blog option to add * value (required) value of the blog option * * Returns Success message or error */ public function add_blog_option() { global $json_api; $this->_verify_admin(); $this->_verify_nonce('add_blog_option'); extract($_REQUEST); if (!isset($blog_id)) { $json_api->error(__("You must send the 'blog_id' parameter.")); } if (!isset($key)) { $json_api->error(__("You must send the 'key' parameter.")); } if (!isset($value)) { $json_api->error(__("You must send the 'value' parameter.")); } add_blog_option($blog_id, $key, $value); return array("message" => __("You successfully added a blog option.")); }
public static function set($_options) { if (is_multisite()) { if (!@get_blog_option(BLOG_ID_CURRENT_SITE, self::$_optionName)) { add_blog_option(BLOG_ID_CURRENT_SITE, self::$_optionName, $_options); } else { update_blog_option(BLOG_ID_CURRENT_SITE, self::$_optionName, $_options + @get_blog_option(BLOG_ID_CURRENT_SITE, self::$_optionName)); } self::$_arrSettings = @get_blog_option(BLOG_ID_CURRENT_SITE, self::$_optionName); } else { if (!@get_option(self::$_optionName)) { add_option(self::$_optionName, $_options); } else { update_option(self::$_optionName, $_options + @get_option(self::$_optionName)); } self::$_arrSettings = @get_option(self::$_optionName); } }
function wp_super_cache_blogs_field($name, $blog_id) { if ($name != 'wp_super_cache') { return false; } if (isset($_GET['id']) && $blog_id == $_GET['id']) { $valid_nonce = isset($_GET['_wpnonce']) ? wp_verify_nonce($_GET['_wpnonce'], 'wp-cache' . $_GET['id']) : false; if ($valid_nonce && isset($_GET['action']) && $_GET['action'] == 'disable_cache') { add_blog_option($_GET['id'], 'wp_super_cache_disabled', 1); } elseif ($valid_nonce && isset($_GET['action']) && $_GET['action'] == 'enable_cache') { delete_blog_option($_GET['id'], 'wp_super_cache_disabled'); } } if (get_blog_option($blog_id, 'wp_super_cache_disabled') == 1) { echo "<a href='" . wp_nonce_url(add_query_arg(array('action' => 'enable_cache', 'id' => $blog_id)), 'wp-cache' . $blog_id) . "'>" . __('Enable', 'wp-super-cache') . "</a>"; } else { echo "<a href='" . wp_nonce_url(add_query_arg(array('action' => 'disable_cache', 'id' => $blog_id)), 'wp-cache' . $blog_id) . "'>" . __('Disable', 'wp-super-cache') . "</a>"; } }
function wpsNetworkActivate($networkwide = false) { if (wpsIsMultisite()) { global $wpdb; if ($networkwide) { $old_blog = $wpdb->blogid; // Get all blog ids $blogIds = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}"); foreach ($blogIds as $blog_id) { switch_to_blog($blog_id); update_blog_option($blog_id, 'WPS_PLUGIN_ACTIVATED', 1); delete_blog_option($blog_id, WpsSettings::PLUGIN_ERROR_NOTICE_OPTION); } switch_to_blog($old_blog); if (_wpsSiteActivate(true, $old_blog)) { add_blog_option($old_blog, 'WPS_KEEP_NUM_ENTRIES_LT', 500); add_blog_option($old_blog, 'WPS_REFRESH_RATE_AJAX_LT', 10); add_blog_option($old_blog, 'WPS_NETWORK_INSTALL', 1); add_blog_option($old_blog, 'WPS_PLUGIN_ACTIVATED', 1); add_blog_option($old_blog, WpsSettings::ENABLE_LIVE_TRAFFIC, 1); } else { $notices = get_blog_option($wpdb->blogid, WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, array()); $notices[] = '<p><strong>' . WPS_PLUGIN_NAME . '</strong></p><p><strong>Error:</strong> An error has occurred while installing the plugin.</p>'; update_site_option($wpdb->blogid, WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); } } else { wp_redirect(network_admin_url('plugins.php')); exit; } } else { add_option('WPS_KEEP_NUM_ENTRIES_LT', 500); add_option('WPS_REFRESH_RATE_AJAX_LT', 10); add_option(WpsSettings::ENABLE_LIVE_TRAFFIC, 1); _wpsSiteActivate(); } }
function wpeo_add_blog_option($id, $option, $value) { $value = maybe_serialize($value); $value = WP_Encrypted_Options::encrypt($value); return add_blog_option($id, $option, $value); }
/** * Set an option's value related to a specific blog * * @param string $key * option key * @param int $blogID * blog ID (default: current blog) * @param string $value * new option value */ public function setOption($key, $value, $blogID = null) { $this->settingsChanged = true; self::$wpPiwik->log('Changed option ' . $key . ': ' . $value); if ($this->checkNetworkActivation() && !empty($blogID)) { add_blog_option($blogID, 'wp-piwik-' . $key, $value); } else { $this->settings[$key] = $value; } }
static function networkActivate() { wssLog(__METHOD__ . '() executed'); global $wpdb; $charset_collate = ''; if (!empty($wpdb->charset)) { $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $charset_collate .= " COLLATE {$wpdb->collate}"; } // MUST HAVE "CREATE" RIGHTS if a table is not found and needs to be created $rights = WsdInfoServer::getDatabaseUserAccessRights(); $hasCreateRight = in_array('CREATE', $rights['rightsHaving']); // Must have alter right for updating table $hasAlterRight = in_array('CREATE', $rights['rightsHaving']); $table1 = self::getTableName(WpsSettings::ALERTS_TABLE_NAME); $table2 = self::getTableName(WpsSettings::LIVE_TRAFFIC_TABLE_NAME); $table3 = self::getTableName(WpsSettings::SCAN_TABLE_NAME); $table4 = self::getTableName(WpsSettings::SCANS_TABLE_NAME); $notices = get_blog_option(1, WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, array()); if (!WsdUtil::tableExists($table1)) { wssLog("table not found: {$table1}"); if (!$hasCreateRight) { $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>: The database user needs the '<strong>CREATE</strong>' right in order to install this plugin."; update_site_option(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } $query1 = "CREATE TABLE IF NOT EXISTS {$table1} (\n `alertId` INT UNSIGNED NOT NULL AUTO_INCREMENT ,\n `alertType` TINYINT NOT NULL DEFAULT 0 ,\n `alertSeverity` INT NOT NULL DEFAULT 0 ,\n `alertActionName` VARCHAR (255) NOT NULL,\n `alertTitle` VARCHAR(255) NOT NULL ,\n `alertDescription` TEXT NOT NULL ,\n `alertSolution` TEXT NOT NULL ,\n `alertDate` DATETIME NOT NULL default '0000-00-00 00:00:00',\n `alertFirstSeen` DATETIME NOT NULL default '0000-00-00 00:00:00',\n PRIMARY KEY (`alertId`) ,\n UNIQUE INDEX `alertId_UNIQUE` (`alertId` ASC) ) {$charset_collate};"; $result = @$wpdb->query($query1); if ($result === false) { //#! MySQL error $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$query1}</pre></strong>."; update_site_option(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } wssLog("table created: {$table1}"); } $alterCheck = true; if (!WsdUtil::tableExists($table2)) { wssLog("table not found: {$table2}"); if (!$hasCreateRight) { $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>: The database user needs the '<strong>CREATE</strong>' right in order to install this plugin."; update_site_option(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } $query2 = "CREATE TABLE IF NOT EXISTS {$table2} (\n `entryId` bigint(20) unsigned NOT NULL auto_increment,\n `entryTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n `entryIp` text,\n `entryReferrer` text,\n `entryUA` text,\n `entryRequestedUrl` text,\n `entryCountry` varchar(125) not null,\n `entryCity` varchar(125) not null,\n `blogId` INT(10) NOT NULL DEFAULT 1,\n PRIMARY KEY (entryId)) {$charset_collate};"; $result = @$wpdb->query($query2); if ($result === false) { //#! MySQL error $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$query2}</pre></strong>."; update_site_option(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } $alterCheck = false; wssLog("table created: {$table2}."); } if ($alterCheck) { wssLog("Alter check needed for {$table2}."); if (!$hasAlterRight) { $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>: The database user needs the '<strong>ALTER</strong>' right in order to install this plugin."; update_site_option(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } // Get columns $query = "SHOW COLUMNS FROM {$table2}"; $cols = $wpdb->get_results($query, ARRAY_A); $columns = array(); if (empty($cols)) { wssLog("Could not retrieve columns from table: {$table2}"); $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$query}</pre></strong>. Please inform the plugin author about this error."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } foreach ($cols as $i => $values) { if (isset($values['Field']) && !empty($values['Field'])) { array_push($columns, $values['Field']); } } $entryCountryExists = $entryCityExists = $blogIdExists = false; if (in_array('entryCountry', $columns)) { $entryCountryExists = true; } if (in_array('entryCity', $columns)) { $entryCityExists = true; } if (in_array('blogId', $columns)) { $blogIdExists = true; } //## Check for column: entryCountry wssLog("Checking for column: entryCountry"); if (!$entryCountryExists) { // alter table $q = "ALTER TABLE {$table2} ADD COLUMN `entryCountry` VARCHAR(125) NOT NULL DEFAULT '' AFTER `entryRequestedUrl`;"; $result = @$wpdb->query($q); if ($result === false) { //#! MySQL error $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$q}</pre></strong>."; update_site_option(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } } //## Check for column: entryCity wssLog("Checking for column: entryCity"); if (!$entryCityExists) { $q = "ALTER TABLE {$table2} ADD COLUMN `entryCity` VARCHAR(125) NOT NULL DEFAULT '' AFTER `entryCountry`;"; $result = @$wpdb->query($q); if ($result === false) { //#! MySQL error $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$q}</pre></strong>."; update_site_option(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } } //## Check for column: blogId wssLog("Checking for column: blogid"); if (!$blogIdExists) { $q = "ALTER TABLE {$table2} ADD COLUMN `blogId` INT(10) NOT NULL DEFAULT 1 AFTER `entryCity`;"; $result = @$wpdb->query($q); if ($result === false) { //#! MySQL error $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$q}</pre></strong>."; update_site_option(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } } wssLog("{$table2} updated successfully"); } if (!WsdUtil::tableExists($table3)) { wssLog("table not found: {$table3}"); if (!$hasCreateRight) { $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>: The database user needs the '<strong>CREATE</strong>' right in order to install this plugin."; update_site_option(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } $query3 = "CREATE TABLE IF NOT EXISTS {$table3} (\n `entryId` BIGINT NOT NULL AUTO_INCREMENT ,\n `scanId` INT NOT NULL ,\n `filePath` VARCHAR(1000) NOT NULL ,\n `dateModified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' ,\n `fileNotFound` TINYINT NOT NULL DEFAULT 0,\n PRIMARY KEY (`entryId`) ,\n UNIQUE INDEX `entryId_UNIQUE` (`entryId` ASC) ) {$charset_collate};"; $result = @$wpdb->query($query3); if ($result === false) { //#! MySQL error $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$query3}</pre></strong>."; update_site_option(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } } if (!WsdUtil::tableExists($table4)) { wssLog("table not found: {$table4}"); if (!$hasCreateRight) { $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>: The database user needs the '<strong>CREATE</strong>' right in order to install this plugin."; WpsOption::updateOption(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } $query4 = "CREATE TABLE {$table4} (\n `scanId` INT NOT NULL AUTO_INCREMENT ,\n `scanStartDate` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n `scanEndDate` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n `scanResult` INT NOT NULL DEFAULT 0,\n `failReason` VARCHAR(5000) NOT NULL DEFAULT '',\n `scanType` int(11) NOT NULL DEFAULT '0',\n PRIMARY KEY (`scanId`) ) {$charset_collate};"; $result = @$wpdb->query($query4); if ($result === false) { //#! MySQL error $notices[] = '<strong>' . WPS_PLUGIN_NAME . "</strong>. Error running query: <strong><pre>{$query4}</pre></strong>."; update_site_option(WpsSettings::PLUGIN_ERROR_NOTICE_OPTION, $notices); return false; } } add_blog_option($wpdb->blogid, WpsSettings::CAN_RUN_TASKS_OPTION_NAME, 1); return true; }
/** * Creates default option and inserts it into the Options table on blog creation * * @param int $blog_id Blog ID of the created blog * * @since 1.0.0 * * @action * @event https://codex.wordpress.org/Plugin_API/Action_Reference/wpmu_new_blog * @in class-mcb-admin.php Mobile_Contact_Bar_Admin::plugins_loaded() * * @uses https://codex.wordpress.org/Function_Reference/add_blog_option * @uses class-mcb-admin.php Mobile_Contact_Bar_Admin::get_default_option() * */ public static function wpmu_new_blog($blog_id) { add_blog_option($blog_id, 'mcb_option', self::get_default_option()); }
/** * replicate the options to the new blog created */ function the_champ_replicate_settings($blogId) { global $theChampFacebookOptions, $theChampLoginOptions, $theChampSharingOptions; add_blog_option($blogId, 'the_champ_facebook', $theChampFacebookOptions); add_blog_option($blogId, 'the_champ_login', $theChampLoginOptions); add_blog_option($blogId, 'the_champ_sharing', $theChampSharingOptions); }
function wpmu_get_blog_allowedthemes($blog_id = 0) { $themes = get_themes(); if ($blog_id == 0) { $blog_allowed_themes = get_option("allowedthemes"); } else { $blog_allowed_themes = get_blog_option($blog_id, "allowedthemes"); } if (!is_array($blog_allowed_themes) || empty($blog_allowed_themes)) { // convert old allowed_themes to new allowedthemes if ($blog_id == 0) { $blog_allowed_themes = get_option("allowed_themes"); } else { $blog_allowed_themes = get_blog_option($blog_id, "allowed_themes"); } if (is_array($blog_allowed_themes)) { foreach ((array) $themes as $key => $theme) { $theme_key = wp_specialchars($theme['Stylesheet']); if (isset($blog_allowed_themes[$key]) == true) { $blog_allowedthemes[$theme_key] = 1; } } $blog_allowed_themes = $blog_allowedthemes; if ($blog_id == 0) { add_option("allowedthemes", $blog_allowed_themes); delete_option("allowed_themes"); } else { add_blog_option($blog_id, "allowedthemes", $blog_allowed_themes); delete_blog_option($blog_id, "allowed_themes"); } } } return $blog_allowed_themes; }
/** * Write option * * Write the "config-press" option to the wp_options database table. This * function also takes in cosideration multisite setup (each site has it's * own configurations) * * @param string $content * * @return boolean * * @access protected */ protected function writeOption($content) { if ($this->readOption() === false) { if (is_multisite()) { $result = add_blog_option(get_current_blog_id(), self::OPTION, $content); } else { $result = add_option(self::OPTION, $content); } } else { //update if (is_multisite()) { $result = update_blog_option(get_current_blog_id(), self::OPTION, $content); } else { $result = update_option(self::OPTION, $content); } } return $result; }
function test_with_another_site() { global $current_site, $base; $domain = 'blogoptiontest'; if (is_subdomain_install()) { $newdomain = $domain . '.' . preg_replace('|^www\\.|', '', $current_site->domain); $path = $base; } else { $newdomain = $current_site->domain; $path = $base . $domain . '/'; } $email = '*****@*****.**'; $password = wp_generate_password(12, false); $user_id = wpmu_create_user($domain, $password, $email); $this->assertInternalType('integer', $user_id); $blog_id = wpmu_create_blog($newdomain, $path, $title, $user_id, array('public' => 1), $current_site->id); $this->assertInternalType('integer', $blog_id); $key = rand_str(); $key2 = rand_str(); $value = rand_str(); $value2 = rand_str(); $this->assertFalse(get_blog_option($blog_id, 'doesnotexist')); //$this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option() $this->assertTrue(add_blog_option($blog_id, $key, $value)); // Assert all values of $blog_id that means the current or main blog (the same here). $this->assertEquals($value, get_blog_option($blog_id, $key)); $this->assertEquals($value, get_blog_option("{$blog_id}", $key)); //$this->assertEquals( $value, get_option( $key ) ); // check get_option() $this->assertFalse(add_blog_option($blog_id, $key, $value)); // Already exists $this->assertFalse(update_blog_option($blog_id, $key, $value)); // Value is the same $this->assertTrue(update_blog_option($blog_id, $key, $value2)); $this->assertEquals($value2, get_blog_option($blog_id, $key)); //$this->assertEquals( $value2, get_option( $key ) ); // check get_option() $this->assertFalse(add_blog_option($blog_id, $key, $value)); $this->assertEquals($value2, get_blog_option($blog_id, $key)); //$this->assertEquals( $value2, get_option( $key ) ); // check get_option() $this->assertTrue(delete_blog_option($blog_id, $key)); $this->assertFalse(get_blog_option($blog_id, $key)); //$this->assertFalse( get_option( $key ) ); // check get_option() $this->assertFalse(delete_blog_option($blog_id, $key)); $this->assertTrue(update_blog_option($blog_id, $key2, $value2)); $this->assertEquals($value2, get_blog_option($blog_id, $key2)); //$this->assertEquals( $value2, get_option( $key2 ) ); // check get_option() $this->assertTrue(delete_blog_option($blog_id, $key2)); $this->assertFalse(get_blog_option($blog_id, $key2)); //$this->assertFalse( get_option( $key2 ) ); // check get_option() }
/** * sets the Columbia -> WPMU role mapping for this blog * @param $blog_id * @param $setting_name - CU role, e.g. instructor_role, student_role * @param $setting_value - WPMU role, e.g. editor, author * @return true if no change made, null if change made */ function wind_add_role_option($blog_id, $setting_name, $setting_value) { if (function_exists('add_blog_option')) { if ($custom_setting = get_blog_option($blog_id, $setting_name)) { return true; } else { return add_blog_option($blog_id, $setting_name, $setting_value); } } }
$new_options_table = $wpdb->prefix . $new_blog_id . '_options'; $old_name = $wpdb->prefix . $template_id . '_user_roles'; $new_name = $wpdb->prefix . $new_blog_id . '_user_roles'; $result = $wpdb->update($new_options_table, array('option_name' => $new_name), array('option_name' => $old_name)); // 'check' if it went ok - NOTE: is just a basic check could give an error anyway... if (get_blog_option($new_blog_id, 'blogdescription') != $blogdescription) { //$error = TRUE; _e("<span class=\"error\">Maybe we had an error updating the options table with the new data.</span>", 'acswpmu_trdom'); } else { _e("Updated the options table with cloned data<br>", 'acswpmu_trdom'); } } // add template_id to option table for later reference if (!$error) { $savearray = array('template-id' => $template_id, 'lasttime' => time()); add_blog_option($new_blog_id, 'add-cloned-sites', serialize($savearray)); //get it back with: //get_option('add-cloned-sites') == "" ? "" : $new = unserialize(get_option('add-cloned-sites')); } // Domainmap the newly cloned site if (!$error and $domainmap) { $tbl_domain_map = $wpdb->prefix . "domain_mapping"; // Check if domainmapping exists if ($wpdb->get_var("SHOW TABLES LIKE '{$tbl_domain_map}'") == $tbl_domain_map) { // Map the domain $result = $wpdb->insert($tbl_domain_map, array('blog_id' => $new_blog_id, 'domain' => $siteurl, 'active' => '1')); if ($result) { _e("New site mapped to domain: {$siteurl}<br/>", 'acswpmu_trdom'); } else { _e("<span class=\"error\">Domain mapping for {$siteurl} failed</span>", 'acswpmu_trdom'); $error = TRUE;
public function replicate_settings_to_new_blog($blogId) { global $loginRadiusSettings; add_blog_option($blogId, 'LoginRadius_settings', $loginRadiusSettings); }
/** * AJAX callback function from the snapshot restore form. This is the third * step of the restore. This step will performs the cleanup of the unzipped * archive and writes an entry to the activity log about the restore. * * @since 1.0.2 * @see * * @param none * * @return JSON formatted array status. */ function snapshot_ajax_restore_finish($item) { $this->snapshot_ajax_restore_rename_restored_tables($item); if (is_multisite()) { $this->snapshot_ajax_restore_convert_db_global_tables($item); } if (isset($_POST['snapshot_restore_theme'])) { $snapshot_restore_theme = esc_attr($_REQUEST['snapshot_restore_theme']); if ($snapshot_restore_theme) { $themes = Snapshot_Helper_Utility::get_blog_active_themes($item['blog-id']); if ($themes && isset($themes[$snapshot_restore_theme])) { if (is_multisite()) { delete_blog_option($item['blog-id'], 'current_theme'); add_blog_option($item['blog-id'], 'current_theme', $themes[$snapshot_restore_theme]); } else { delete_option('current_theme'); add_option('current_theme', $themes[$snapshot_restore_theme]); } } } } if (isset($_REQUEST['snapshot_restore_plugin']) && esc_attr($_REQUEST['snapshot_restore_plugin']) == "yes") { $_plugin_file = basename(dirname(__FILE__)) . "/" . basename(__FILE__); $_plugins = array($_plugin_file); if (is_multisite()) { delete_blog_option($item['blog-id'], 'active_plugins'); add_blog_option($item['blog-id'], 'active_plugins', $_plugins); } else { delete_option('active_plugins'); add_option('active_plugins', $_plugins); } } // Cleanup any files from restore in case any files were left if ($dh = opendir($this->_session->data['restoreFolder'])) { while (($file = readdir($dh)) !== false) { if ($file == '.' || $file == '..') { continue; } Snapshot_Helper_Utility::recursive_rmdir($this->_session->data['restoreFolder'] . $file); } closedir($dh); } flush_rewrite_rules(); $error_status = array(); $error_status['errorStatus'] = false; $error_status['errorText'] = ""; $error_status['responseText'] = "<p>" . __("SUCCESS: Snapshot Restore complete! ", SNAPSHOT_I18N_DOMAIN) . "</p>"; return $error_status; }
public function replicate_settings_to_new_blog($blogId) { global $oss_api_settings; add_blog_option($blogId, 'OpenSocialShare_API_settings', $oss_api_settings); }
function test_with_another_site() { $user_id = $this->factory->user->create(); $this->assertInternalType('integer', $user_id); $blog_id = $this->factory->blog->create(array('user_id' => $user_id, 'meta' => array('public' => 1))); $this->assertInternalType('integer', $blog_id); $key = rand_str(); $key2 = rand_str(); $value = rand_str(); $value2 = rand_str(); $this->assertFalse(get_blog_option($blog_id, 'doesnotexist')); //$this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option() $this->assertTrue(add_blog_option($blog_id, $key, $value)); // Assert all values of $blog_id that means the current or main blog (the same here). $this->assertEquals($value, get_blog_option($blog_id, $key)); $this->assertEquals($value, get_blog_option("{$blog_id}", $key)); //$this->assertEquals( $value, get_option( $key ) ); // check get_option() $this->assertFalse(add_blog_option($blog_id, $key, $value)); // Already exists $this->assertFalse(update_blog_option($blog_id, $key, $value)); // Value is the same $this->assertTrue(update_blog_option($blog_id, $key, $value2)); $this->assertEquals($value2, get_blog_option($blog_id, $key)); //$this->assertEquals( $value2, get_option( $key ) ); // check get_option() $this->assertFalse(add_blog_option($blog_id, $key, $value)); $this->assertEquals($value2, get_blog_option($blog_id, $key)); //$this->assertEquals( $value2, get_option( $key ) ); // check get_option() $this->assertTrue(delete_blog_option($blog_id, $key)); $this->assertFalse(get_blog_option($blog_id, $key)); //$this->assertFalse( get_option( $key ) ); // check get_option() $this->assertFalse(delete_blog_option($blog_id, $key)); $this->assertTrue(update_blog_option($blog_id, $key2, $value2)); $this->assertEquals($value2, get_blog_option($blog_id, $key2)); //$this->assertEquals( $value2, get_option( $key2 ) ); // check get_option() $this->assertTrue(delete_blog_option($blog_id, $key2)); $this->assertFalse(get_blog_option($blog_id, $key2)); //$this->assertFalse( get_option( $key2 ) ); // check get_option() }
/** * Replicate the options to the new blog created. * * @since 1.0.0 */ public function replicate_settings($blog_id) { add_blog_option($blog_id, 'heateor_sss', $this->options); }
/** * Add option data in WordPress. * * @param string$option * @param mixed $value * * @return bool */ function pp_add_option($option, $value) { $current_blog_id = get_current_blog_id(); $return = is_multisite() ? add_blog_option($current_blog_id, $option, $value) : add_option($option, $value); return $return; }
/** * Add an option. * * This is a wrapper for {@link add_blog_option()}, which in turn stores * settings data on the appropriate blog, given your current setup. * * @since BuddyPress (2.0.0) * * @param string $option_name The option key to be set. * @param mixed $value The value to be set. * @return bool True on success, false on failure. */ function bp_add_option($option_name, $value) { return add_blog_option(bp_get_root_blog_id(), $option_name, $value); }
/** * Install * * @param none * @return void */ public function install() { global $wpdb; if (is_multisite() && is_network_admin()) { $blogs = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM %d", $wpdb->blogs)); } else { $blogs = array($wpdb->blogid); } $defaults = $this->getSetting('network_defaults'); foreach ($blogs as $blog_id) { if (version_compare($this->getSetting('version', $blog_id), $this->getVersion(), '<')) { if ($this->getSetting('version', $blog_id) == '') { // Add Settings foreach ($this->getSettings() as $option => $value) { if (is_multisite()) { if (add_blog_option($blog_id, $option, $value) && isset($defaults[$option]) && $defaults[$option] != '') { if ($option == 'ssl_host' && strpos($value, 'https://') !== 0) { $value = 'https://' . rtrim($defaults[$option], '/') . '/'; } else { $value = $defaults[$option]; } $this->setSetting($option, $value, $blog_id); } } else { add_option($option, $value); } } } // Fix a bug that saved the ssl_host as an object if (!is_string($this->getSetting('ssl_host', $blog_id))) { $this->setSetting('ssl_host', $this->_settings['ssl_host'], $blog_id); $this->setSetting('ssl_host_diff', $this->_settings['ssl_host_diff'], $blog_id); $this->setSetting('ssl_host_subdomain', $this->_settings['ssl_host_subdomain'], $blog_id); } // Remove old ssl_port setting and append to HTTPS URL if ((int) $this->getSetting('ssl_port', $blog_id) > 0) { if ($this->getSetting('ssl_port', $blog_id) != 443) { $ssl_host = Mvied_Url::fromString($this->getSetting('ssl_host', $blog_id)); $ssl_host->setPort($this->getSetting('ssl_port', $blog_id)); $this->setSetting('ssl_host', $ssl_host->toString(), $blog_id); } $this->setSetting('ssl_port', null, $blog_id); } // If secure front page option exists, create front page filter if ($this->getSetting('frontpage', $blog_id)) { $this->setSetting('secure_filter', array_merge($this->getSetting('secure_filter'), array(rtrim(str_replace('http://', '', $this->getHttpUrl()->toString()), '/') . '/$'))); $this->setSetting('frontpage', 0, $blog_id); } // Reformat ssl_host_mapping $ssl_host_mapping = $this->getSetting('ssl_host_mapping', $blog_id); if ($ssl_host_mapping != array() && !is_array($ssl_host_mapping[0])) { $mappings = array(); foreach ($ssl_host_mapping as $http_host => $https_host) { $mappings[] = array(array('scheme' => 'http', 'host' => $http_host), array('scheme' => 'https', 'host' => $https_host)); } $this->setSetting('ssl_host_mapping', $mappings, $blog_id); } // Reset cache $this->setSetting('secure_external_urls', $this->_settings['secure_external_urls'], $blog_id); $this->setSetting('unsecure_external_urls', $this->_settings['unsecure_external_urls'], $blog_id); $this->setSetting('path_cache', $this->_settings['path_cache'], $blog_id); $this->setSetting('blog_cache', $this->_settings['blog_cache'], $blog_id); // Set default URL Mapping if ($this->getSetting('ssl_host_mapping', $blog_id) == array()) { $this->setSetting('ssl_host_mapping', WordPressHTTPS::$ssl_host_mapping, $blog_id); } } $this->setSetting('version', $this->getVersion(), $blog_id); } $is_subdomain = $this->getHttpsUrl()->isSubdomain($this->getHttpUrl()); foreach ($blogs as $blog_id) { $this->setSetting('ssl_host_subdomain', $is_subdomain, $blog_id); } // Check for deprecated modules if (file_exists($this->getModuleDirectory() . '/DomainMapping.php')) { @unlink($this->getModuleDirectory() . '/DomainMapping.php'); } }
function mycred_install_log($decimals = 0, $table = NULL) { if (is_multisite() && get_blog_option($GLOBALS['blog_id'], 'mycred_version_db', false) !== false) { return true; } elseif (!is_multisite() && get_option('mycred_version_db', false) !== false) { return true; } global $wpdb; if ($table === NULL) { $mycred = mycred(); $table = $mycred->log_table; } if ($decimals > 0) { if ($decimals > 4) { $cred_format = "decimal(32,{$decimals})"; } else { $cred_format = "decimal(22,{$decimals})"; } } else { $cred_format = 'bigint(22)'; } $wpdb->hide_errors(); $collate = ''; if ($wpdb->has_cap('collation')) { if (!empty($wpdb->charset)) { $collate .= "DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $collate .= " COLLATE {$wpdb->collate}"; } } // Log structure $sql = "\n\t\t\tid int(11) NOT NULL AUTO_INCREMENT, \n\t\t\tref VARCHAR(256) NOT NULL, \n\t\t\tref_id int(11) DEFAULT NULL, \n\t\t\tuser_id int(11) DEFAULT NULL, \n\t\t\tcreds {$cred_format} DEFAULT NULL, \n\t\t\tctype VARCHAR(64) DEFAULT 'mycred_default', \n\t\t\ttime bigint(20) DEFAULT NULL, \n\t\t\tentry LONGTEXT DEFAULT NULL, \n\t\t\tdata LONGTEXT DEFAULT NULL, \n\t\t\tPRIMARY KEY (id), \n\t\t\tUNIQUE KEY id (id)"; // Insert table require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta("CREATE TABLE IF NOT EXISTS {$table} ( " . $sql . " ) {$collate};"); if (is_multisite()) { add_blog_option($GLOBALS['blog_id'], 'mycred_version_db', '1.0'); } else { add_option('mycred_version_db', '1.0'); } return true; }
/** * Install * * @param none * @return void */ public function install() { global $wpdb; if (is_multisite() && is_network_admin()) { $blogs = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM " . $wpdb->blogs, NULL)); } else { $blogs = array($wpdb->blogid); } $defaults = $this->getSetting('network_defaults'); foreach ($blogs as $blog_id) { // Add Settings foreach ($this->getSettings() as $option => $value) { if (is_multisite()) { if (add_blog_option($blog_id, $option, $value) && isset($defaults[$option])) { if ($option == 'ssl_host' && strpos($value, 'https://') !== 0) { $value = 'https://' . rtrim($defaults[$option], '/') . '/'; } else { $value = $defaults[$option]; } $this->setSetting($option, $value, $blog_id); } } else { add_option($option, $value); } } // Fix a bug that saved the ssl_host as an object if (!is_string($this->getSetting('ssl_host', $blog_id))) { $this->setSetting('ssl_host', $this->_settings['ssl_host'], $blog_id); $this->setSetting('ssl_port', $this->_settings['ssl_port'], $blog_id); $this->setSetting('ssl_host_diff', $this->_settings['ssl_host_diff'], $blog_id); $this->setSetting('ssl_host_subdomain', $this->_settings['ssl_host_subdomain'], $blog_id); } // If secure front page option exists, create front page filter if ($this->getSetting('frontpage', $blog_id)) { $this->setSetting('secure_filter', array_merge($this->getSetting('secure_filter'), array(rtrim(str_replace('http://', '', $this->getHttpUrl()->toString()), '/') . '/$'))); $this->setSetting('frontpage', 0, $blog_id); } // Reset cache $this->setSetting('secure_external_urls', $this->_settings['secure_external_urls'], $blog_id); $this->setSetting('unsecure_external_urls', $this->_settings['unsecure_external_urls'], $blog_id); // Set default domain mapping if ($this->getSetting('ssl_host_mapping', $blog_id) == array()) { $this->setSetting('ssl_host_mapping', WordPressHTTPS::$ssl_host_mapping, $blog_id); } } $is_subdomain = $this->getHttpsUrl()->isSubdomain($this->getHttpUrl()); foreach ($blogs as $blog_id) { $this->setSetting('ssl_host_subdomain', $is_subdomain, $blog_id); } }