ap_opt( string $key = false, string $value = null )

Description #

To retrieve AnsPress option.

Parameters #

  • $key
    string (Optional) Name of option to retrieve or keep it blank to get all options of AnsPress. Default value: false
  • $value
    string (Optional) Enter value to update existing option. Default value: null

Changelog #

VersionDescription
0.1Introduced.

Source #

File: includes/options.php

function ap_opt( $key = false, $value = null ) {
	$settings = wp_cache_get( 'anspress_opt', 'ap' );

	if ( false === $settings ) {
		$settings = get_option( 'anspress_opt' );

		if ( ! $settings ) {
			$settings = array();
		}

		wp_cache_set( 'anspress_opt', $settings, 'ap' );
	}

	$settings = $settings + ap_default_options();

	if ( ! is_null( $value ) ) {
		$settings[ $key ] = $value;
		update_option( 'anspress_opt', $settings );

		// Clear cache if option updated.
		wp_cache_delete( 'anspress_opt', 'ap' );

		return;
	}

	if ( false === $key ) {
		return $settings;
	}

	if ( isset( $settings[ $key ] ) ) {
		return $settings[ $key ];
	}

	return null;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment