From 434d8738602d04563c5f818514685bdd3d044a54 Mon Sep 17 00:00:00 2001 From: Aaron Holbrook Date: Thu, 29 Jun 2017 08:17:57 -0500 Subject: [PATCH] Add get option query function --- README.md | 3 ++- composer.json | 2 +- utils.php | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ccc8a2d..6f977e9 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,5 @@ A collection of functions that provide utility functionality for WordPress. * `get_current_url()`: Returns the current URL. * `get_current_url_clean()`: Returns the current URL, but without query args. -* `get_id_from_slug( $slug, $post_type = 'post', $force = false )` : Performs a lookup for a post given a slug. \ No newline at end of file +* `get_id_from_slug( $slug, $post_type = 'post', $force = false )` : Performs a lookup for a post given a slug. +* `get_raw_option_value( $key )`: Performs a very direct, simple query to the WordPress Options table that bypasses normal WP caching. \ No newline at end of file diff --git a/composer.json b/composer.json index 5c4356e..b71f98a 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "zeek/wp-utils", "description": "A collection of functions that provide utility functionality for WordPress.", - "version": "0.3.1", + "version": "0.4.0", "type": "library", "license": "proprietary", "authors": [ diff --git a/utils.php b/utils.php index d6217a8..06bdf0e 100644 --- a/utils.php +++ b/utils.php @@ -69,3 +69,31 @@ function get_id_from_slug( $slug, $post_type = 'post', $force = false ) { return intval( $id ); } + +/** + * Performs a very direct, simple query to the WordPress Options table + * that bypasses normal WP caching + * + * @param $key + * + * @return int + */ +function get_raw_option_value( $key ) { + global $wpdb; + + $sql = sprintf( " + SELECT + option_value + FROM + wp_options + WHERE + option_name = '%s' + LIMIT 1 + ", + sanitize_text_field( $key ) + ); + + $version = $wpdb->get_var( $sql ); + + return intval( $version ); +}