Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/password.../includes
File: class-ppw-db.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Class PPW_Repository_Passwords
[2] Fix | Delete
*/
[3] Fix | Delete
[4] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[5] Fix | Delete
exit;
[6] Fix | Delete
}
[7] Fix | Delete
[8] Fix | Delete
if ( ! class_exists( 'PPW_Repository_Passwords' ) ) {
[9] Fix | Delete
/**
[10] Fix | Delete
* DB class to create table and manage version
[11] Fix | Delete
* Class PPW_Pro_DB
[12] Fix | Delete
*/
[13] Fix | Delete
class PPW_Repository_Passwords {
[14] Fix | Delete
/**
[15] Fix | Delete
* Table version
[16] Fix | Delete
* @var string
[17] Fix | Delete
*/
[18] Fix | Delete
private $tbl_version;
[19] Fix | Delete
/**
[20] Fix | Delete
* Table name
[21] Fix | Delete
* @var string
[22] Fix | Delete
*/
[23] Fix | Delete
private $tbl_name;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* @var object
[27] Fix | Delete
*/
[28] Fix | Delete
private $wpdb;
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Instance of PPW_Pro_Shortcode class.
[32] Fix | Delete
*
[33] Fix | Delete
* @var PPW_Repository_Passwords
[34] Fix | Delete
*/
[35] Fix | Delete
protected static $instance = null;
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* PPW_Pro_DB constructor.
[39] Fix | Delete
*
[40] Fix | Delete
* @param $prefix
[41] Fix | Delete
*/
[42] Fix | Delete
public function __construct( $prefix = false ) {
[43] Fix | Delete
global $wpdb;
[44] Fix | Delete
$this->wpdb = $wpdb;
[45] Fix | Delete
$this->tbl_version = $this->get_table_version();
[46] Fix | Delete
$this->tbl_name = ! $prefix ? $this->wpdb->prefix . PPW_Constants::TBL_NAME : $prefix . PPW_Constants::TBL_NAME;
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Get short code instance
[51] Fix | Delete
*
[52] Fix | Delete
* @return PPW_Repository_Passwords
[53] Fix | Delete
*/
[54] Fix | Delete
public static function get_instance() {
[55] Fix | Delete
if ( is_null( self::$instance ) ) {
[56] Fix | Delete
// Use static instead of self due to the inheritance later.
[57] Fix | Delete
// For example: ChildSC extends this class, when we call get_instance
[58] Fix | Delete
// it will return the object of child class. On the other hand, self function
[59] Fix | Delete
// will return the object of base class.
[60] Fix | Delete
self::$instance = new static();
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
return self::$instance;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Install table
[68] Fix | Delete
*/
[69] Fix | Delete
public function install() {
[70] Fix | Delete
// TODO: Check highest version to create table.
[71] Fix | Delete
$this->init_tbl();
[72] Fix | Delete
[73] Fix | Delete
// Add new column.
[74] Fix | Delete
foreach ( PPW_Constants::DB_DATA_COLUMN_TABLE as $data ) {
[75] Fix | Delete
$this->add_new_column( $data['old_version'], $data['new_version'], $data['value'] );
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
// Update column.
[79] Fix | Delete
foreach ( PPW_Constants::DB_UPDATE_COLUMN_TABLE as $dt ) {
[80] Fix | Delete
$this->update_table( $dt['old_version'], $dt['new_version'], $dt['value'] );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
// TODO: Add column for pro version.
[84] Fix | Delete
$this->update_label_and_post_types_column();
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Uninstall table
[89] Fix | Delete
*/
[90] Fix | Delete
public function uninstall() {
[91] Fix | Delete
$this->wpdb->query( "DROP TABLE IF EXISTS $this->tbl_name" ); // phpcs:ignore -- We do not need to prepare because don't have any param to pass.
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Init table
[96] Fix | Delete
*/
[97] Fix | Delete
private function init_tbl() {
[98] Fix | Delete
if ( $this->is_table_does_not_exist() ) {
[99] Fix | Delete
$charset_collate = $this->wpdb->get_charset_collate();
[100] Fix | Delete
$sql = "CREATE TABLE $this->tbl_name (
[101] Fix | Delete
id mediumint(9) NOT NULL AUTO_INCREMENT,
[102] Fix | Delete
post_id mediumint(9) NOT NULL,
[103] Fix | Delete
contact_id mediumint(9) NULL,
[104] Fix | Delete
campaign_app_type varchar(50) DEFAULT '' NULL,
[105] Fix | Delete
password varchar(30) NOT NULL,
[106] Fix | Delete
is_activated tinyint(1) DEFAULT 1,
[107] Fix | Delete
created_time BIGINT DEFAULT NULL,
[108] Fix | Delete
expired_time BIGINT DEFAULT NULL,
[109] Fix | Delete
UNIQUE KEY id(id)
[110] Fix | Delete
) $charset_collate;";
[111] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
[112] Fix | Delete
dbDelta( $sql );
[113] Fix | Delete
[114] Fix | Delete
// Init setting when installing plugin firstly.
[115] Fix | Delete
update_option( PPW_Constants::MISC_OPTIONS, wp_json_encode( array( 'wpp_use_custom_form_action' => 'true' ) ), 'no' );
[116] Fix | Delete
[117] Fix | Delete
$this->tbl_version = "1.0";
[118] Fix | Delete
$this->update_table_version( $this->tbl_version );
[119] Fix | Delete
}
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Add new column for table
[124] Fix | Delete
*
[125] Fix | Delete
* @param $old_version
[126] Fix | Delete
* @param $new_version
[127] Fix | Delete
* @param $value
[128] Fix | Delete
*/
[129] Fix | Delete
private function add_new_column( $old_version, $new_version, $value ) {
[130] Fix | Delete
if ( $this->tbl_version === $old_version ) {
[131] Fix | Delete
if ( is_null( $this->check_column_exist( $value ) ) ) {
[132] Fix | Delete
$charset_collate = $this->wpdb->get_charset_collate();
[133] Fix | Delete
$sql = "CREATE TABLE $this->tbl_name ( $value ) $charset_collate;";
[134] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
[135] Fix | Delete
dbDelta( $sql );
[136] Fix | Delete
}
[137] Fix | Delete
$this->tbl_version = $new_version;
[138] Fix | Delete
$this->update_table_version( $this->tbl_version );
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
/**
[143] Fix | Delete
* Update value for column in table
[144] Fix | Delete
*
[145] Fix | Delete
* @param $old_version
[146] Fix | Delete
* @param $new_version
[147] Fix | Delete
* @param $value
[148] Fix | Delete
*/
[149] Fix | Delete
private function update_table( $old_version, $new_version, $value ) {
[150] Fix | Delete
if ( $this->tbl_version === $old_version ) {
[151] Fix | Delete
$sql = "ALTER TABLE $this->tbl_name CHANGE $value";
[152] Fix | Delete
[153] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
[154] Fix | Delete
$this->wpdb->query( $sql ); // phpcs:ignore -- We don't need to prepare this one.
[155] Fix | Delete
[156] Fix | Delete
$this->tbl_version = $new_version;
[157] Fix | Delete
$this->update_table_version( $this->tbl_version );
[158] Fix | Delete
}
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
/**
[162] Fix | Delete
* Check table is exist
[163] Fix | Delete
*
[164] Fix | Delete
* @return bool
[165] Fix | Delete
*/
[166] Fix | Delete
private function is_table_does_not_exist() {
[167] Fix | Delete
$preparation = $this->wpdb->prepare( 'SHOW TABLES LIKE %s', $this->tbl_name );
[168] Fix | Delete
return $this->wpdb->get_var( $preparation ) != $this->tbl_name; // phpcs:ignore -- we already prepared above, but there are no data to prepare
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* Get the plugin table's version
[173] Fix | Delete
*/
[174] Fix | Delete
private function get_table_version() {
[175] Fix | Delete
$version = get_option( PPW_Constants::TBL_VERSION, false );
[176] Fix | Delete
[177] Fix | Delete
return ! $version ? '1.0' : $version;
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
/**
[181] Fix | Delete
* Update table version
[182] Fix | Delete
*
[183] Fix | Delete
* @param $version
[184] Fix | Delete
*/
[185] Fix | Delete
private function update_table_version( $version ) {
[186] Fix | Delete
update_option( PPW_Constants::TBL_VERSION, $version );
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Get password info by password and post id
[191] Fix | Delete
*
[192] Fix | Delete
* @param string $password The password.
[193] Fix | Delete
*
[194] Fix | Delete
* @return mixed
[195] Fix | Delete
*/
[196] Fix | Delete
public function get_master_password_info_by_password( $password ) {
[197] Fix | Delete
$like_master_param = 'master_';
[198] Fix | Delete
$query_string = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s and campaign_app_type LIKE %s and post_id = 0 and is_activated = 1 and (expired_date is NULL OR expired_date > UNIX_TIMESTAMP()) and (usage_limit is NULL OR hits_count < usage_limit)", $password, $this->wpdb->esc_like( $like_master_param ) . '%' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
[199] Fix | Delete
[200] Fix | Delete
return $this->wpdb->get_row( $query_string ); // phpcs:ignore -- we already prepared above
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
[204] Fix | Delete
/**
[205] Fix | Delete
* Get master password which activating.
[206] Fix | Delete
*
[207] Fix | Delete
* @return array|object|null Database query results.
[208] Fix | Delete
*/
[209] Fix | Delete
public function get_activate_master_passwords_info() {
[210] Fix | Delete
$like_master_param = 'master_';
[211] Fix | Delete
$query_string = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE post_id = 0 AND campaign_app_type LIKE %s and is_activated = 1", $this->wpdb->esc_like( $like_master_param ) . '%' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder.
[212] Fix | Delete
[213] Fix | Delete
return $this->wpdb->get_results( $query_string ); // phpcs:ignore -- we already prepared above
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
/**
[217] Fix | Delete
* Get master password which in database.
[218] Fix | Delete
*
[219] Fix | Delete
* @return array|object|null Database query results.
[220] Fix | Delete
*/
[221] Fix | Delete
public function get_master_passwords_info() {
[222] Fix | Delete
$like_master_param = 'master_';
[223] Fix | Delete
$query_string = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE post_id = 0 AND campaign_app_type LIKE %s", $this->wpdb->esc_like( $like_master_param ) . '%' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
[224] Fix | Delete
[225] Fix | Delete
return $this->wpdb->get_results( $query_string ); // phpcs:ignore -- we already prepared above
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
/**
[229] Fix | Delete
* Add a row in table by id.
[230] Fix | Delete
*
[231] Fix | Delete
* @param array $data Data to add.
[232] Fix | Delete
*
[233] Fix | Delete
* @return int|false The number of rows updated, or false on error.
[234] Fix | Delete
*/
[235] Fix | Delete
public function add_new_password( $data ) {
[236] Fix | Delete
$is_added = $this->wpdb->insert( $this->tbl_name, $data );
[237] Fix | Delete
if ( $is_added ) {
[238] Fix | Delete
return $this->wpdb->insert_id;
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
return false;
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
public function delete_passwords( $ids, $post_id ) {
[245] Fix | Delete
$ids = implode( ',', array_map( 'absint', $ids ) );
[246] Fix | Delete
$post_id = absint( $post_id );
[247] Fix | Delete
$query_string = $this->wpdb->prepare( "DELETE FROM {$this->tbl_name} WHERE id IN(%1s) AND post_id = %d", $ids, $post_id ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder and put the $ids in quotes.
[248] Fix | Delete
$this->wpdb->query( $query_string ); // phpcs:ignore -- we already prepared above
[249] Fix | Delete
}
[250] Fix | Delete
[251] Fix | Delete
/**
[252] Fix | Delete
* Find password by post ID.
[253] Fix | Delete
*
[254] Fix | Delete
* @param string $password Password.
[255] Fix | Delete
*
[256] Fix | Delete
* @return array|object|void|null Database query result in format specified by $output or null on failure
[257] Fix | Delete
*/
[258] Fix | Delete
public function find_by_master_password( $password ) {
[259] Fix | Delete
$like_master_param = 'master_';
[260] Fix | Delete
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s AND post_id = 0 AND campaign_app_type LIKE %s", $password, $this->wpdb->esc_like( $like_master_param ) . '%' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
[261] Fix | Delete
[262] Fix | Delete
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
/**
[266] Fix | Delete
* Find shared category password.
[267] Fix | Delete
*
[268] Fix | Delete
* @param string $password Password.
[269] Fix | Delete
*
[270] Fix | Delete
* @return array|object|void|null Database query result in format specified by $output or null on failure
[271] Fix | Delete
*/
[272] Fix | Delete
public function find_by_shared_category_password( $password ) {
[273] Fix | Delete
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s AND post_id = 0 AND campaign_app_type = %s", $password, PPW_Category_Service::SHARED_CATEGORY_TYPE ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
[274] Fix | Delete
[275] Fix | Delete
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
[276] Fix | Delete
}
[277] Fix | Delete
[278] Fix | Delete
/**
[279] Fix | Delete
* Get all shared categories password.
[280] Fix | Delete
*
[281] Fix | Delete
* @return array|object|void|null Database query result in format specified by $output or null on failure
[282] Fix | Delete
*/
[283] Fix | Delete
public function get_all_shared_categories_password() {
[284] Fix | Delete
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE post_id = 0 AND campaign_app_type = %s", PPW_Category_Service::SHARED_CATEGORY_TYPE ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
[285] Fix | Delete
[286] Fix | Delete
return $this->wpdb->get_results( $sql ); // phpcs:ignore -- we already prepared above
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
public function get_passwords_with_type_and_post_id( $type, $post_id, $column = '*' ) {
[290] Fix | Delete
$sql = $this->wpdb->prepare( "SELECT %1s FROM {$this->tbl_name} WHERE post_id = %d AND campaign_app_type = %s", $column, $post_id, $type ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder, and put $column in quotes.
[291] Fix | Delete
[292] Fix | Delete
return $this->wpdb->get_results( $sql ); // phpcs:ignore -- we already prepared above
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
/***
[296] Fix | Delete
* Get all custom categories's password
[297] Fix | Delete
* @param $taxonomy_type
[298] Fix | Delete
*
[299] Fix | Delete
* @return mixed
[300] Fix | Delete
*/
[301] Fix | Delete
public function get_all_custom_categories_password( $taxonomy_type ) {
[302] Fix | Delete
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE post_id = 0 AND campaign_app_type = %s", $taxonomy_type ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
[303] Fix | Delete
[304] Fix | Delete
return $this->wpdb->get_results( $sql ); // phpcs:ignore -- we already prepared above
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
/***
[308] Fix | Delete
* Check password with custom category type.
[309] Fix | Delete
*
[310] Fix | Delete
* @param $password
[311] Fix | Delete
* @param $taxonomy
[312] Fix | Delete
*
[313] Fix | Delete
* @return mixed
[314] Fix | Delete
*/
[315] Fix | Delete
public function find_by_shared_custom_category_password( $password, $taxonomy_type ) {
[316] Fix | Delete
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s AND post_id = 0 AND campaign_app_type = %s", $password, $taxonomy_type ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
[317] Fix | Delete
[318] Fix | Delete
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
/**
[322] Fix | Delete
* Get shared category password by password ID.
[323] Fix | Delete
*
[324] Fix | Delete
* @param int $password_id Password ID.
[325] Fix | Delete
*
[326] Fix | Delete
* @return array|object|void|null Database query result in format specified by $output or null on failure
[327] Fix | Delete
*/
[328] Fix | Delete
public function get_shared_category_password( $password_id ) {
[329] Fix | Delete
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY id = %d AND campaign_app_type = %s", $password_id, PPW_Category_Service::SHARED_CATEGORY_TYPE ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
[330] Fix | Delete
[331] Fix | Delete
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
[332] Fix | Delete
}
[333] Fix | Delete
[334] Fix | Delete
/**
[335] Fix | Delete
* Get shared category password by password ID.
[336] Fix | Delete
*
[337] Fix | Delete
* @param int $password_id Password ID.
[338] Fix | Delete
*
[339] Fix | Delete
* @return array|object|void|null Database query result in format specified by $output or null on failure
[340] Fix | Delete
*/
[341] Fix | Delete
public function get_shared_custom_category_password( $password_id, $taxonomy ) {
[342] Fix | Delete
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE id = %d AND campaign_app_type = %s", $password_id, $taxonomy ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
[343] Fix | Delete
[344] Fix | Delete
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
/**
[348] Fix | Delete
* Delete a row in table by id.
[349] Fix | Delete
*
[350] Fix | Delete
* @param int $id ID.
[351] Fix | Delete
*
[352] Fix | Delete
* @return int|false The number of rows updated, or false on error.
[353] Fix | Delete
*/
[354] Fix | Delete
public function delete( $id ) {
[355] Fix | Delete
return $this->wpdb->delete(
[356] Fix | Delete
$this->tbl_name,
[357] Fix | Delete
array(
[358] Fix | Delete
'id' => absint( $id ),
[359] Fix | Delete
)
[360] Fix | Delete
);
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
/**
[364] Fix | Delete
* Update a row in table by id.
[365] Fix | Delete
*
[366] Fix | Delete
* @param int $id ID.
[367] Fix | Delete
* @param array $data Data to update.
[368] Fix | Delete
*
[369] Fix | Delete
* @return int|false The number of rows updated, or false on error.
[370] Fix | Delete
*/
[371] Fix | Delete
public function update_password( $id, $data ) {
[372] Fix | Delete
return $this->wpdb->update(
[373] Fix | Delete
$this->tbl_name,
[374] Fix | Delete
$data,
[375] Fix | Delete
array(
[376] Fix | Delete
'id' => absint( $id ),
[377] Fix | Delete
)
[378] Fix | Delete
);
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
/**
[382] Fix | Delete
* Update label and post types column.
[383] Fix | Delete
*/
[384] Fix | Delete
public function update_label_and_post_types_column() {
[385] Fix | Delete
$this->add_new_column( '1.6', '1.7', 'label TINYTEXT' );
[386] Fix | Delete
$this->add_new_column( '1.7', '1.8', 'post_types varchar(255)' );
[387] Fix | Delete
$this->add_new_column( '1.8', '1.9', 'protection_types varchar(50)' );
[388] Fix | Delete
}
[389] Fix | Delete
[390] Fix | Delete
/**
[391] Fix | Delete
* Check column exist in database.
[392] Fix | Delete
*
[393] Fix | Delete
* @param string $value Value to add new column.
[394] Fix | Delete
*
[395] Fix | Delete
* @return string|null|false Database query result (as string), or null on failure
[396] Fix | Delete
* @since 1.4.0 Init function.
[397] Fix | Delete
*/
[398] Fix | Delete
private function check_column_exist( $value ) {
[399] Fix | Delete
if ( empty( $value ) ) {
[400] Fix | Delete
return false;
[401] Fix | Delete
}
[402] Fix | Delete
$value_patterns = explode( ' ', $value );
[403] Fix | Delete
$field_name = $value_patterns[0];
[404] Fix | Delete
$query = $this->wpdb->prepare( "SHOW COLUMNS FROM {$this->tbl_name} LIKE %s", $this->wpdb->esc_like( $field_name ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
[405] Fix | Delete
[406] Fix | Delete
return $this->wpdb->get_var( $query ); // phpcs:ignore -- we already prepared above
[407] Fix | Delete
}
[408] Fix | Delete
[409] Fix | Delete
/**
[410] Fix | Delete
* Get all backup post password.
[411] Fix | Delete
*
[412] Fix | Delete
* @return array|object|void|null Database query result in format specified by $output or null on failure
[413] Fix | Delete
*/
[414] Fix | Delete
public function get_wp_post_passwords() {
[415] Fix | Delete
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->postmeta} WHERE meta_key = %s", 'ppwp_post_password_bk' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
[416] Fix | Delete
[417] Fix | Delete
return $this->wpdb->get_results( $sql ); // phpcs:ignore -- we already prepared above
[418] Fix | Delete
}
[419] Fix | Delete
[420] Fix | Delete
/**
[421] Fix | Delete
* Count all backup post password.
[422] Fix | Delete
*
[423] Fix | Delete
* @return int - number for count
[424] Fix | Delete
*/
[425] Fix | Delete
public function count_wp_post_passwords() {
[426] Fix | Delete
$sql = $this->wpdb->prepare( "SELECT COUNT(*) FROM {$this->wpdb->postmeta} WHERE meta_key = %s", 'ppwp_post_password_bk' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
[427] Fix | Delete
[428] Fix | Delete
return $this->wpdb->get_var( $sql ); // phpcs:ignore -- we already prepared above
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
/**
[432] Fix | Delete
* Delete selected passwords by id
[433] Fix | Delete
* String will convert to int
[434] Fix | Delete
*
[435] Fix | Delete
* @param array $selected_ids ID Passwords selected.
[436] Fix | Delete
*
[437] Fix | Delete
* @return mixed
[438] Fix | Delete
*/
[439] Fix | Delete
public function bulk_delete_passwords( $selected_ids ) {
[440] Fix | Delete
$selected_ids = implode( ',', array_map( 'absint', $selected_ids ) );
[441] Fix | Delete
$query_string = $this->wpdb->prepare( "DELETE FROM {$this->tbl_name} WHERE ID IN(%1s)", $selected_ids ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder and put the $ids in quotes.
[442] Fix | Delete
[443] Fix | Delete
return $this->wpdb->query( $query_string ); // phpcs:ignore -- we already prepared above
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
/**
[447] Fix | Delete
* Delete all expired master password
[448] Fix | Delete
*/
[449] Fix | Delete
public function delete_all_expired_password( $ids, $campaign_app_type) {
[450] Fix | Delete
return $this->wpdb->query($this->wpdb->prepare( "DELETE FROM $this->tbl_name WHERE `campaign_app_type` LIKE '%$campaign_app_type%' and `expired_date` < UNIX_TIMESTAMP(NOW()) or `hits_count` >= `usage_limit`"));
[451] Fix | Delete
//return $this->wpdb->query($this->wpdb->prepare( "DELETE FROM $this->tbl_name WHERE `campaign_app_type` = %s", $campaign_app_type));
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
public function delete_passwords_by_post_id( $post_id ) {
[455] Fix | Delete
return $this->wpdb->delete(
[456] Fix | Delete
$this->tbl_name,
[457] Fix | Delete
array(
[458] Fix | Delete
'post_id' => absint( $post_id ),
[459] Fix | Delete
)
[460] Fix | Delete
);
[461] Fix | Delete
}
[462] Fix | Delete
[463] Fix | Delete
public function find_activated_password( $password, $params ) {
[464] Fix | Delete
$args = wp_parse_args(
[465] Fix | Delete
$params,
[466] Fix | Delete
array(
[467] Fix | Delete
'post_id' => 0,
[468] Fix | Delete
'roles' => array(),
[469] Fix | Delete
'global_type' => '',
[470] Fix | Delete
'role_type' => '',
[471] Fix | Delete
'allow_to_check_expired' => true,
[472] Fix | Delete
)
[473] Fix | Delete
);
[474] Fix | Delete
[475] Fix | Delete
$like_where = '';
[476] Fix | Delete
if ( $args['role_type'] ) {
[477] Fix | Delete
$like_where = $this->generate_where_like_for_roles( $args['roles'], $args['role_type'] );
[478] Fix | Delete
}
[479] Fix | Delete
[480] Fix | Delete
$expired_where = '';
[481] Fix | Delete
if ( $args['allow_to_check_expired'] ) {
[482] Fix | Delete
$expired_where = ' AND (expired_date IS NULL OR expired_date > UNIX_TIMESTAMP()) AND (usage_limit IS NULL OR hits_count < usage_limit) ';
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
$query = $this->wpdb->prepare(
[486] Fix | Delete
"SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s AND is_activated = 1 AND ( campaign_app_type = %s {$like_where}) AND post_id = %d {$expired_where}", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder and put the extended where sql query in quotes.
[487] Fix | Delete
$password,
[488] Fix | Delete
$args['global_type'],
[489] Fix | Delete
$args['post_id']
[490] Fix | Delete
);
[491] Fix | Delete
[492] Fix | Delete
return $this->wpdb->get_row( $query ); // phpcs:ignore -- we already prepared above
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
public function find_activated_passwords_by_ids( $password_ids, $params ) {
[496] Fix | Delete
$args = wp_parse_args(
[497] Fix | Delete
$params,
[498] Fix | Delete
array(
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function