Skip to content

Commit

Permalink
Add get option query function
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronHolbrook committed Jun 29, 2017
1 parent aea8aaf commit 434d873
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* `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.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
28 changes: 28 additions & 0 deletions utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

0 comments on commit 434d873

Please sign in to comment.