Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Registers an option sanitization filter.
*
* If the option is an "array" option type with "suboptions", you have to use the third param to specify the
* suboption or suboptions you want the filter to apply to. DO NOT call this without the third parameter on an option
* that is an array option, because in that case it will apply that filter to the array(), not each member.
*
* Use the 'genesis_settings_sanitizer_init' action to be notified when this function is safe to use
*
* @since 1.7.0
*
* @uses Genesis_Settings_Sanitizer::add_filter()
*
* @param string $filter The filter to call (see Genesis_Settings_Sanitizer::$available_filters for options)
* @param string $option The WordPress option name
* @param string|array $suboption Optional. The suboption or suboptions you want to filter
*
* @return true
*/
function genesis_add_option_filter( $filter, $option, $suboption = null ) {
return Genesis_Settings_Sanitizer::$instance->add_filter( $filter, $option, $suboption );
}
<?php
/**
* Add sanitization filters to options.
*
* Associates a sanitization filter to each option (or sub options if they
* exist) before adding a reference to run the option through that
* sanitizer at the right time.
*
* @since 1.7.0
*
* @param string $filter Sanitization filter type
* @param string $option Option key
* @param array $suboption Optional. Suboption key
* @return boolean Returns true when complete
*/
function add_filter( $filter, $option, array $suboption = null ) {
if ( is_array( $suboption ) ) {
foreach ( $suboption as $so ) {
$this->options[$option][$so] = $filter;
}
} elseif ( is_null( $suboption ) ) {
$this->options[$option] = $filter;
} else {
$this->options[$option][$suboption] = $filter;
}
add_filter( 'sanitize_option_' . $option, array( $this, 'sanitize' ), 10, 2 );
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment