/** * Get configuration options stored in multiple bundles * @since 1.3 */ function get_duplicates() { $settings = WPCFM()->options->get('wpcfm_settings'); $settings = json_decode($settings, true); if (empty($settings['bundles'])) { return array(); } $result = array(); foreach ($settings['bundles'] as $bundle) { foreach ((array) $bundle['config'] as $option) { if (empty($result[$option])) { $result[$option] = array($bundle['name']); } else { $result[$option][] = $bundle['name']; } } } foreach ($result as $option => $bundles) { if (1 == count($bundles)) { unset($result[$option]); } else { sort($result[$option]); } } return $result; }
private function exportSettings() { if (function_exists('WPCFM')) { // running inside WordPress, use WPCFM directly echo "Using WPCFM directly\n"; WPCFM()->readwrite->push_bundle('wpbootstrap'); } else { $wpcmd = $this->bootstrap->getWpCommand(); $this->ensureBundleExists(); $cmd = $wpcmd . 'config push wpbootstrap 2>/dev/null'; exec($cmd); } $src = $this->bootstrap->localSettings->wppath . '/wp-content/config/wpbootstrap.json'; $trg = BASEPATH . '/bootstrap/config/wpbootstrap.json'; if (file_exists($src)) { @mkdir(dirname($trg), 0777, true); copy($src, $trg); // sanity check $settings = json_decode(file_get_contents($trg)); $label = '.label'; if (is_null($settings->{$label})) { $settings->{$label} = 'wpbootstrap'; file_put_contents($trg, $this->bootstrap->prettyPrint(json_encode($settings))); } } }
/** * Import settings via WP-CFM */ public function import() { $app = Bootstrap::getApplication(); $helpers = $app['helpers']; $baseUrl = get_option('siteurl'); $src = WPBOOT_BASEPATH . '/bootstrap/config/wpbootstrap.json'; $trg = $app['path'] . '/wp-content/config/wpbootstrap.json'; if (file_exists($src)) { @mkdir(dirname($trg), 0777, true); copy($src, $trg); // deneutralize $settings = json_decode(file_get_contents($trg)); $helpers->fieldSearchReplace($settings, Bootstrap::NEUTRALURL, $baseUrl); file_put_contents($trg, $helpers->prettyPrint(json_encode($settings))); if (function_exists('WPCFM')) { WPCFM()->readwrite->pull_bundle('wpbootstrap'); } else { $cli = $app['cli']; $cli->warning('Plugin WP-CFM does not seem to be installed. No options imported.'); $cli->warning('Add the WP-CFM plugin directly to this install using:'); $cli->warning('$ wp plugin install wp-cfm --activate'); $cli->warning(''); $cli->warning('...or to your appsettings using:'); $cli->warning('$ wp bootstrap add plugin wp-cfm'); $cli->warning('$ wp bootstrap setup'); return; } // Flush options to make sure no other code overwrites based // on old settings stored in cache wp_cache_flush(); } }
/** * Get file bundles */ function get_file_bundles() { $output = array(); $filenames = scandir(WPCFM_CONFIG_DIR); $filenames = array_diff($filenames, array('.', '..')); foreach ($filenames as $filename) { // Default to single site bundle $bundle_name = str_replace('.json', '', $filename); if (is_multisite()) { $filename_parts = explode('-', $filename, 2); // Only accept multi-site bundles if (2 > count($filename_parts)) { continue; } $bundle_name = str_replace('.json', '', $filename_parts[1]); if (WPCFM()->options->is_network) { if ('network' != $filename_parts[0]) { continue; } } elseif ($filename_parts[0] != 'blog' . get_current_blog_id()) { continue; } } $bundle_data = WPCFM()->readwrite->read_file($bundle_name); $bundle_label = $bundle_data['.label']; unset($bundle_data['.label']); $output[$bundle_name] = array('label' => $bundle_label, 'name' => $bundle_name, 'config' => $bundle_data); } return $output; }
/** * Pull settings into DB */ function pull_settings() { if (current_user_can('manage_options')) { $bundle_name = stripslashes($_POST['data']['bundle_name']); WPCFM()->readwrite->pull_bundle($bundle_name); echo __('Pull successful', 'wpcfm'); } exit; }
/** * Get bundle details * * ## OPTIONS * * <bundle_name> * : The bundle name to inspect. * * ## EXAMPLES * * wp config show_bundle <bundle_name> * * @synopsis <bundle_name> * */ function show_bundle($args, $assoc_args) { $file_bundle = WPCFM()->readwrite->read_file($args[0]); $db_bundle = WPCFM()->readwrite->read_db($args[0]); $header = array('Config', 'File value', 'DB value'); $rows = array(); foreach ($file_bundle as $key => $value) { $rows[$key] = array($key, $value); if (isset($db_bundle[$key])) { $rows[$key][] = $db_bundle[$key]; } else { $rows[$key][] = 'n/a'; } } foreach ($file_bundle as $key => $value) { if (!isset($db_bundle[$key])) { $rows[$key] = array($key, 'n/a', $db_bundle[$key]); } } unset($rows['.label']); ksort($rows); $table = new \cli\Table($header, $rows); $table->display(); }
/** * Default callback - write to wp_options table */ function callback_wp_options($params) { $option_name = $params['name']; $option_value = maybe_unserialize($params['new_value']); WPCFM()->options->update($option_name, $option_value); }
} /** * Route to the correct edit screen */ function settings_page() { include WPCFM_DIR . '/templates/page-settings.php'; } /** * i18n support */ function load_textdomain() { $locale = apply_filters('plugin_locale', get_locale(), 'wpcfm'); $mofile = WP_LANG_DIR . '/wpcfm-' . $locale . '.mo'; if (file_exists($mofile)) { load_textdomain('wpcfm', $mofile); } else { load_plugin_textdomain('wpcfm', false, dirname(plugin_basename(__FILE__)) . '/languages/'); } } } WPCFM(); /** * Allow direct access to WPCFM classes * For example, use WPCFM()->options to access WPCFM_Options */ function WPCFM() { return WPCFM_Core::instance(); }
/** * Load all bundle names */ function get_bundle_names() { if (WPCFM()->readwrite->folder != WPCFM_CONFIG_DIR) { return array_keys($this->get_file_bundles()); } else { return array_keys($this->get_bundles()); } }