wpsf/wpsf-dev

Adding wpsf_get_option and wpsf_set_options

Opened this issue · 0 comments

This framework lacks two important functions.

wpsf_get_option () and wpsf_set_option ()

Here they are:

if ( ! function_exists( 'wpsf_get_option' ) ) {
	/**
	 * Get option.
	 *
	 * @param  string  $option_name
	 * @param  string  $default
	 * @return mixed|string|null
	 */
	function wpsf_get_option( $option_name = '', $default = '' ) {
		$options = apply_filters( 'wpsf_get_option', get_option( WPSF_OPTION ) );

		if ( ! empty( $option_name ) && ! empty( $options[ $option_name ] ) ) {
			return $options[ $option_name ];
		} else {
			return ( ! empty( $default ) ) ? $default : null;
		}
	}
}
if ( ! function_exists( 'wpff_set_option' ) ) {
	/**
	 * Set option.
	 *
	 * @param  string  $option_name
	 * @param  string  $new_value
	 * @return void
	 */
	function wpsf_set_option( $option_name = '', $new_value = '' )  {
		$options = get_option( WPSF_OPTION );

		if ( ! empty( $option_name ) && ! empty( $options[ $option_name ] ) ) {
			$options[ $option_name ] = $new_value;
			update_option( WPSF_OPTION, $options );
		}
	}
}

Put this function in functions/helpers.php