Network mode is used when Falcon is network-activated, and moves some
of the settings to the network admin for super admins instead. It also
adds UI to allow enabling per-site.
public static is_network_mode ( ) : boolean | ||
리턴 | boolean |
public static function register_default_settings() { if (Falcon::is_network_mode()) { self::register_network_settings(); } add_settings_section('bbsub_options_notifications', 'Default Notification Settings', array(get_class(), 'output_default_settings_header'), 'bbsub_options'); $connectors = Falcon::get_connectors(); foreach ($connectors as $type => $connector) { if (!is_callable(array($connector, 'get_available_settings'))) { continue; } $args = array('type' => $type, 'connector' => $connector); add_settings_field('falcon_options_notifications-' . $type, $connector->get_name(), array(get_class(), 'output_default_settings'), 'bbsub_options', 'bbsub_options_notifications', $args); $available = $connector->get_available_settings(); self::$available[$type] = $available; foreach ($available as $key => $title) { $setting_key = self::key_for_setting($type, 'notifications.' . $key); register_setting('bbsub_options', $setting_key); // Add the filter ourselves, so that we can specify two params add_filter("sanitize_option_{$setting_key}", array(get_class(), 'sanitize_notification_option'), 10, 2); // Save the key for later self::$registered_settings[$setting_key] = array($type, $key); } } }
/** * Handle option saving in the network admin * * Alas, the network admin doesn't include an options handler, so we need * to use our own here isntead. * * @wp-action load-settings_page_bbsub_options */ public static function handle_save_on_network() { if (!Falcon::is_network_mode()) { return; } if (empty($_POST) || empty($_REQUEST['action']) || $_REQUEST['action'] !== 'update') { return; } $option_page = 'bbsub_options'; $capability = apply_filters("option_page_capability_{$option_page}", 'manage_network_options'); if (!current_user_can($capability)) { wp_die(__('Cheatin’ uh?'), 403); } check_admin_referer($option_page . '-options'); $whitelist_options = apply_filters('whitelist_options', array()); if (!isset($whitelist_options[$option_page])) { wp_die(__('<strong>ERROR</strong>: options page not found.')); } $options = $whitelist_options[$option_page]; foreach ($options as $option) { if ($unregistered) { _deprecated_argument('options.php', '2.7', sprintf(__('The <code>%1$s</code> setting is unregistered. Unregistered settings are deprecated. See http://codex.wordpress.org/Settings_API'), $option, $option_page)); } $option = trim($option); $value = null; if (isset($_POST[$option])) { $value = $_POST[$option]; if (!is_array($value)) { $value = trim($value); } $value = wp_unslash($value); } update_site_option($option, $value); } /** * Handle settings errors and return to options page */ // If no settings errors were registered add a general 'updated' message. if (!count(get_settings_errors())) { add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated'); } set_transient('settings_errors', get_settings_errors(), 30); /** * Redirect back to the settings page that was submitted */ $goback = add_query_arg('settings-updated', 'true', wp_get_referer()); wp_redirect($goback); exit; }