Suspend
2 years ago
ActionScheduler.php
2 years ago
AdminPages.php
8 months ago
AdminUrl.php
8 months ago
DB.php
4 years ago
Post.php
5 years ago
Resources.php
5 years ago
SyncHash.php
8 months ago
WCTaxonomies.php
1 year ago
WcAdminPages.php
8 months ago
WpAdminPages.php
1 year ago
DB.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Utilities; |
| 4 | |
| 5 | use wpdb; |
| 6 | |
| 7 | class DB { |
| 8 | |
| 9 | /** |
| 10 | * Changes array of items into string of items, separated by comma and sql-escaped |
| 11 | * |
| 12 | * @see https://coderwall.com/p/zepnaw |
| 13 | * @see wpml_prepare_in |
| 14 | * |
| 15 | * @global wpdb $wpdb |
| 16 | * |
| 17 | * @param mixed|array $items item(s) to be joined into string |
| 18 | * @param string $format %s or %d |
| 19 | * |
| 20 | * @return string Items separated by comma and sql-escaped |
| 21 | */ |
| 22 | public static function prepareIn( $items, $format = '%s') { |
| 23 | /** @var wpdb $wpdb */ |
| 24 | global $wpdb; |
| 25 | |
| 26 | $items = (array) $items; |
| 27 | $how_many = count( $items ); |
| 28 | if ( $how_many > 0 ) { |
| 29 | $placeholders = array_fill( 0, $how_many, $format ); |
| 30 | $prepared_format = implode( ',', $placeholders ); |
| 31 | $prepared_in = $wpdb->prepare( $prepared_format, $items ); |
| 32 | } else { |
| 33 | $prepared_in = ''; |
| 34 | } |
| 35 | |
| 36 | return $prepared_in; |
| 37 | } |
| 38 | } |
| 39 |