| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); | |
| 3 | 2 | |
| 4 | 3 | /** |
| 5 | 4 | * Imagify DB base class. |
| 6 | 5 | * |
| @@ -7,9 +6,8 @@ | ||
| 7 | 6 | * @since 1.5 |
| 8 | 7 | * @source https://gist.github.com/pippinsplugins/e220a7f0f0f2fbe64608 |
| 9 | 8 | */ |
| 10 | 9 | abstract class Imagify_Abstract_DB extends Imagify_Abstract_DB_Deprecated implements \Imagify\DB\DBInterface { |
| 11 | - | |
| 12 | 10 | /** |
| 13 | 11 | * Class version. |
| 14 | 12 | * |
| 15 | 13 | * @var string |
| @@ -24,17 +22,8 @@ | ||
| 24 | 22 | */ |
| 25 | 23 | const TABLE_VERSION_OPTION_SUFFIX = '_db_version'; |
| 26 | 24 | |
| 27 | 25 | /** |
| 28 | - * The single instance of the class. | |
| 29 | - * | |
| 30 | - * @var object | |
| 31 | - * @since 1.5 | |
| 32 | - * @access protected | |
| 33 | - */ | |
| 34 | - protected static $_instance; | |
| 35 | - | |
| 36 | - /** | |
| 37 | 26 | * The suffix used in the name of the database table (so, without the wpdb prefix). |
| 38 | 27 | * |
| 39 | 28 | * @var string |
| 40 | 29 | * @since 1.7 |
| @@ -123,25 +112,8 @@ | ||
| 123 | 112 | $this->set_table_ready(); |
| 124 | 113 | } |
| 125 | 114 | |
| 126 | 115 | /** |
| 127 | - * Get the main Instance. | |
| 128 | - * | |
| 129 | - * @since 1.6.5 | |
| 130 | - * @access public | |
| 131 | - * @author Grégory Viguier | |
| 132 | - * | |
| 133 | - * @return object Main instance. | |
| 134 | - */ | |
| 135 | - public static function get_instance() { | |
| 136 | - if ( ! isset( self::$_instance ) ) { | |
| 137 | - self::$_instance = new self(); | |
| 138 | - } | |
| 139 | - | |
| 140 | - return self::$_instance; | |
| 141 | - } | |
| 142 | - | |
| 143 | - /** | |
| 144 | 116 | * Init: |
| 145 | 117 | * - Launch hooks. |
| 146 | 118 | * |
| 147 | 119 | * @since 1.7 |
| @@ -148,9 +120,9 @@ | ||
| 148 | 120 | * @access public |
| 149 | 121 | * @author Grégory Viguier |
| 150 | 122 | */ |
| 151 | 123 | public function init() { |
| 152 | - add_action( 'admin_init', array( $this, 'maybe_upgrade_table' ) ); | |
| 124 | + add_action( 'admin_init', [ $this, 'maybe_upgrade_table' ] ); | |
| 153 | 125 | } |
| 154 | 126 | |
| 155 | 127 | /** |
| 156 | 128 | * Tell if we can work with the tables. |
| @@ -233,9 +205,9 @@ | ||
| 233 | 205 | * @return array |
| 234 | 206 | */ |
| 235 | 207 | public function get( $row_id ) { |
| 236 | 208 | if ( $row_id <= 0 ) { |
| 237 | - return array(); | |
| 209 | + return []; | |
| 238 | 210 | } |
| 239 | 211 | |
| 240 | 212 | return $this->get_by( $this->primary_key, $row_id ); |
| 241 | 213 | } |
| @@ -252,10 +224,10 @@ | ||
| 252 | 224 | */ |
| 253 | 225 | public function get_by( $column_where, $column_value ) { |
| 254 | 226 | global $wpdb; |
| 255 | 227 | |
| 256 | - $placeholder = $this->get_placeholder( $column_where ); | |
| 257 | - $column_where = esc_sql( $column_where ); | |
| 228 | + $placeholder = $this->get_placeholder( $column_where ); | |
| 229 | + $column_where = esc_sql( $column_where ); | |
| 258 | 230 | |
| 259 | 231 | $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column_where = $placeholder LIMIT 1;", $column_value ), ARRAY_A ); // WPCS: unprepared SQL ok, PreparedSQLPlaceholders replacement count ok. |
| 260 | 232 | |
| 261 | 233 | return (array) $this->cast_row( $result ); |
| @@ -446,9 +418,9 @@ | ||
| 446 | 418 | * @param array $data New data. |
| 447 | 419 | * @param string $where A column name. |
| 448 | 420 | * @return bool |
| 449 | 421 | */ |
| 450 | - public function update( $row_id, $data = array(), $where = '' ) { | |
| 422 | + public function update( $row_id, $data = [], $where = '' ) { | |
| 451 | 423 | global $wpdb; |
| 452 | 424 | |
| 453 | 425 | if ( $row_id <= 0 ) { |
| 454 | 426 | return false; |
| @@ -477,9 +449,9 @@ | ||
| 477 | 449 | |
| 478 | 450 | // Reorder $column_formats to match the order of columns given in $data. |
| 479 | 451 | $column_formats = array_merge( $data, $column_formats ); |
| 480 | 452 | |
| 481 | - return (bool) $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats, $this->get_placeholder( $where ) ); | |
| 453 | + return (bool) $wpdb->update( $this->table_name, $data, [ $where => $row_id ], $column_formats, $this->get_placeholder( $where ) ); | |
| 482 | 454 | } |
| 483 | 455 | |
| 484 | 456 | /** |
| 485 | 457 | * Delete a row identified by the primary key. |
| @@ -576,15 +548,15 @@ | ||
| 576 | 548 | */ |
| 577 | 549 | protected function set_table_not_ready() { |
| 578 | 550 | global $wpdb; |
| 579 | 551 | |
| 580 | - $this->table_created = false; | |
| 552 | + $this->table_created = false; | |
| 581 | 553 | unset( $wpdb->{$this->table} ); |
| 582 | 554 | |
| 583 | 555 | if ( $this->table_is_global ) { |
| 584 | - $wpdb->global_tables = array_diff( $wpdb->global_tables, array( $this->table ) ); | |
| 556 | + $wpdb->global_tables = array_diff( $wpdb->global_tables, [ $this->table ] ); | |
| 585 | 557 | } else { |
| 586 | - $wpdb->tables = array_diff( $wpdb->tables, array( $this->table ) ); | |
| 558 | + $wpdb->tables = array_diff( $wpdb->tables, [ $this->table ] ); | |
| 587 | 559 | } |
| 588 | 560 | } |
| 589 | 561 | |
| 590 | 562 | |
| @@ -872,12 +844,15 @@ | ||
| 872 | 844 | if ( ! $serialized_data ) { |
| 873 | 845 | return $data; |
| 874 | 846 | } |
| 875 | 847 | |
| 876 | - $serialized_data = array_map( function( $array ) { | |
| 877 | - // Try not to store empty serialized arrays. | |
| 878 | - return [] === $array ? null : maybe_serialize( $array ); | |
| 879 | - }, $serialized_data ); | |
| 848 | + $serialized_data = array_map( | |
| 849 | + function ( $value ) { | |
| 850 | + // Try not to store empty serialized arrays. | |
| 851 | + return [] === $value ? null : maybe_serialize( $value ); | |
| 852 | + }, | |
| 853 | + $serialized_data | |
| 854 | + ); | |
| 880 | 855 | |
| 881 | 856 | return array_merge( $data, $serialized_data ); |
| 882 | 857 | } |
| 883 | 858 | } |