+/* Whitelist functions */
+
+/**
+ * Register a setting and its sanitization callback
+ *
+ * @since 2.7.0
+ *
+ * @global array $new_whitelist_options
+ *
+ * @param string $option_group A settings group name. Should correspond to a whitelisted option key name.
+ * Default whitelisted option key names include "general," "discussion," and "reading," among others.
+ * @param string $option_name The name of an option to sanitize and save.
+ * @param callable $sanitize_callback A callback function that sanitizes the option's value.
+ */
+function register_setting( $option_group, $option_name, $sanitize_callback = '' ) {
+ global $new_whitelist_options;
+
+ if ( 'misc' == $option_group ) {
+ _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) );
+ $option_group = 'general';
+ }
+
+ if ( 'privacy' == $option_group ) {
+ _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) );
+ $option_group = 'reading';
+ }
+
+ $new_whitelist_options[ $option_group ][] = $option_name;
+ if ( $sanitize_callback != '' )
+ add_filter( "sanitize_option_{$option_name}", $sanitize_callback );
+}
+
+/**
+ * Unregister a setting
+ *
+ * @since 2.7.0
+ *
+ * @global array $new_whitelist_options
+ *
+ * @param string $option_group
+ * @param string $option_name
+ * @param callable $sanitize_callback
+ */
+function unregister_setting( $option_group, $option_name, $sanitize_callback = '' ) {
+ global $new_whitelist_options;
+
+ if ( 'misc' == $option_group ) {
+ _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) );
+ $option_group = 'general';
+ }
+
+ if ( 'privacy' == $option_group ) {
+ _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) );
+ $option_group = 'reading';
+ }
+
+ $pos = array_search( $option_name, (array) $new_whitelist_options[ $option_group ] );
+ if ( $pos !== false )
+ unset( $new_whitelist_options[ $option_group ][ $pos ] );
+ if ( $sanitize_callback != '' )
+ remove_filter( "sanitize_option_{$option_name}", $sanitize_callback );
+}
+
+/**
+ * Refreshes the value of the options whitelist available via the 'whitelist_options' filter.
+ *
+ * @since 2.7.0
+ *
+ * @global array $new_whitelist_options
+ *
+ * @param array $options
+ * @return array
+ */
+function option_update_filter( $options ) {
+ global $new_whitelist_options;
+
+ if ( is_array( $new_whitelist_options ) )
+ $options = add_option_whitelist( $new_whitelist_options, $options );
+
+ return $options;
+}
+
+/**
+ * Adds an array of options to the options whitelist.
+ *
+ * @since 2.7.0
+ *
+ * @global array $whitelist_options
+ *
+ * @param array $new_options
+ * @param string|array $options
+ * @return array
+ */
+function add_option_whitelist( $new_options, $options = '' ) {
+ if ( $options == '' )
+ global $whitelist_options;
+ else
+ $whitelist_options = $options;
+
+ foreach ( $new_options as $page => $keys ) {
+ foreach ( $keys as $key ) {
+ if ( !isset($whitelist_options[ $page ]) || !is_array($whitelist_options[ $page ]) ) {
+ $whitelist_options[ $page ] = array();
+ $whitelist_options[ $page ][] = $key;
+ } else {
+ $pos = array_search( $key, $whitelist_options[ $page ] );
+ if ( $pos === false )
+ $whitelist_options[ $page ][] = $key;
+ }
+ }
+ }
+
+ return $whitelist_options;
+}
+
+/**
+ * Removes a list of options from the options whitelist.
+ *
+ * @since 2.7.0
+ *
+ * @global array $whitelist_options
+ *
+ * @param array $del_options
+ * @param string|array $options
+ * @return array
+ */
+function remove_option_whitelist( $del_options, $options = '' ) {
+ if ( $options == '' )
+ global $whitelist_options;
+ else
+ $whitelist_options = $options;
+
+ foreach ( $del_options as $page => $keys ) {
+ foreach ( $keys as $key ) {
+ if ( isset($whitelist_options[ $page ]) && is_array($whitelist_options[ $page ]) ) {
+ $pos = array_search( $key, $whitelist_options[ $page ] );
+ if ( $pos !== false )
+ unset( $whitelist_options[ $page ][ $pos ] );
+ }
+ }
+ }
+
+ return $whitelist_options;
+}
+
+/**
+ * Output nonce, action, and option_page fields for a settings page.
+ *
+ * @since 2.7.0
+ *
+ * @param string $option_group A settings group name. This should match the group name used in register_setting().
+ */
+function settings_fields($option_group) {
+ echo "<input type='hidden' name='option_page' value='" . esc_attr($option_group) . "' />";
+ echo '<input type="hidden" name="action" value="update" />';
+ wp_nonce_field("$option_group-options");
+}
+
+/**
+ * Clears the Plugins cache used by get_plugins() and by default, the Plugin Update cache.
+ *
+ * @since 3.7.0
+ *
+ * @param bool $clear_update_cache Whether to clear the Plugin updates cache
+ */
+function wp_clean_plugins_cache( $clear_update_cache = true ) {
+ if ( $clear_update_cache )
+ delete_site_transient( 'update_plugins' );
+ wp_cache_delete( 'plugins', 'plugins' );
+}
+
+/**
+ * @param string $plugin
+ */
+function plugin_sandbox_scrape( $plugin ) {
+ wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
+ include( WP_PLUGIN_DIR . '/' . $plugin );
+}