Skip to content

Commit

Permalink
Merge pull request #55 from alicolville/DB-functions
Browse files Browse the repository at this point in the history
4.1.1
  • Loading branch information
alicolville committed Dec 4, 2023
2 parents 218223e + 06a276c commit 0236ad2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
18 changes: 9 additions & 9 deletions docs/shortcodes/sc-db-value-by-id.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Fetch a value from the given MySQL table. Specify which column the value should

For example, the following shortcode usage, will run the SQL specified below.

`[sv slug="sc-db-value-by-id" table="users" column="user_login" column-to-search="id" key="3" key-format="%d"]`
`[sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d"]`

*Pseudo MySQL:*

Expand All @@ -22,11 +22,11 @@ The shortcode supports the following arguments:

| Argument | Description | Options | Example |
|-------------------|------------------------------------------------------------------------------------------|-------------------------------------------------|--|
| table | MySQL table to search | text | [sv slug="sc-db-value-by-id" table="users" column="user_login" column-to-search="id" key="3" key-format="%d"]
| cache | If enabled, cache the results of the SQL query for the number of seconds specified by | True (default) or False | [sv slug="sc-db-value-by-id" table="users" column="user_login" column-to-search="id" key="3" key-format="%d" cache=false]
| cache-duration | Number of seconds the data should be cached for (before hitting the database again) | Number, default 3600 seconds (1 hour) | [sv slug="sc-db-value-by-id" table="users" column="user_login" column-to-search="id" key="3" key-format="%d" cache=true cache-duration=60]
| column | MySQL table column to return | text | [sv slug="sc-db-value-by-id" table="users" column="user_login" column-to-search="id" key="3" key-format="%d"]
| column-to-search | MySQL column to use in Where clause | text | [sv slug="sc-db-value-by-id" table="users" column="user_login" column-to-search="id" key="3" key-format="%d"]
| key | Value to compare against colum-to-search | text | [sv slug="sc-db-value-by-id" table="users" column="user_login" column-to-search="id" key="3" key-format="%d"]
| key-format | To stop SQL injection, a format (either numeric or string) must be specified for the key | Either "%d" (for a number) or "%s" for a string | [sv slug="sc-db-value-by-id" table="users" column="user_login" column-to-search="id" key="3" key-format="%d"]
| message-not-found | Message to display if no value can be found for the given key. | Either blank or text | [sv slug="sc-db-value-by-id" table="users" column="user_login" column-to-search="id" key="3" key-format="%d" message-not-found="Could not find user"]
| table | MySQL table to search | text | [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d"]
| cache | If enabled, cache the results of the SQL query for the number of seconds specified by | True (default) or False | [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d" cache=false]
| cache-duration | Number of seconds the data should be cached for (before hitting the database again) | Number, default 3600 seconds (1 hour) | [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d" cache=true cache-duration=60]
| column | MySQL table column to return | text | [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d"]
| column-to-search | MySQL column to use in Where clause | text | [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d"]
| key | Value to compare against colum-to-search | text | [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d"]
| key-format | To stop SQL injection, a format (either numeric or string) must be specified for the key | Either "%d" (for a number) or "%s" for a string | [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d"]
| message-not-found | Message to display if no value can be found for the given key. | Either blank or text | [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d" message-not-found="Could not find user"]
2 changes: 1 addition & 1 deletion includes/shortcode.presets.premium.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ protected function unsanitised() {

$sql = sprintf( 'Select %s from %s where %s = %s',
$args['column'],
$wpdb->prefix . $args['table'],
$args['table'],
$args['column-to-search'],
$args['key-format']
);
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.paypal.me/yeken
Tags: shortcode, variable, php, text, html, parameter, javascript, embed, reuse
Requires at least: 5.7
Tested up to: 6.4.1
Stable tag: 4.1
Stable tag: 4.1.1
Requires PHP: 7.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -147,6 +147,10 @@ Login into Wordpress Admin Panel and goto Settings > Snippet Shortcodes

== Changelog ==

= 4.1.1 =

* Improvement: Dropped the database table prefix from the shortcode [sv slug="sc-db-value-by-id"] e.g. instead of specifying "users" table, it would now be "wp_users" (i.e. if a WP table, specify the prefix)

= 4.1 =

* New Feature: New Premium shortcode for fetching a value from a MySQL table, [sv slug="sc-db-value-by-id"]. Read more: https://snippet-shortcodes.yeken.uk/shortcodes/sc-db-value-by-id.html
Expand Down
4 changes: 2 additions & 2 deletions shortcode-variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Plugin Name: Snippet Shortcodes
* Description: Create your own shortcodes and assign text / variables to it or use our premade ones. You can then embed these shortcodes throughout your entire site and only have to change the value in one place.
* Version: 4.1
* Version: 4.1.1
* Requires at least: 5.7
* Tested up to: 6.4.1
* Requires PHP: 7.4
Expand Down Expand Up @@ -34,7 +34,7 @@

define( 'SH_CD_ABSPATH', plugin_dir_path( __FILE__ ) );

define( 'SH_CD_PLUGIN_VERSION', '4.1' );
define( 'SH_CD_PLUGIN_VERSION', '4.1.1' );
define( 'SH_CD_PLUGIN_NAME', 'Snippet Shortcodes' );
define( 'SH_CD_TABLE', 'SH_CD_SHORTCODES' );
define( 'SH_CD_TABLE_MULTISITE', 'SH_CD_SHORTCODES_MULTISITE' );
Expand Down

0 comments on commit 0236ad2

Please sign in to comment.