PluginProbe
Polylang / 3.3
Polylang v3.3
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / include / db-tools.php

db-tools.php in Polylang 3.3, at include/db-tools.php

49 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Polylang
4 */
5
6 defined( 'ABSPATH' ) || exit;
7
8 /**
9 * Small set of tools to work with the database.
10 *
11 * @since 3.2
12 */
13 class PLL_Db_Tools {
14
15 /**
16 * Changes an array of values into a comma separated list, ready to be used in a `IN ()` clause.
17 * Only string and integers and supported for now.
18 *
19 * @since 3.2
20 *
21 * @param (int|string)[] $values An array of values.
22 * @return string A comma separated list of values.
23 */
24 public static function prepare_values_list( $values ) {
25 $values = array_map( array( __CLASS__, 'prepare_value' ), (array) $values );
26
27 return implode( ',', $values );
28 }
29
30 /**
31 * Wraps a value in escaped double quotes or casts as an integer.
32 * Only string and integers and supported for now.
33 *
34 * @since 3.2
35 *
36 * @global wpdb $wpdb
37 *
38 * @param int|string $value A value.
39 * @return int|string
40 */
41 public static function prepare_value( $value ) {
42 if ( ! is_numeric( $value ) ) {
43 return $GLOBALS['wpdb']->prepare( '%s', $value );
44 }
45
46 return (int) $value;
47 }
48 }
49