Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Admin/Notes
File: DataStore.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WC Admin Note Data_Store class file.
[2] Fix | Delete
*/
[3] Fix | Delete
[4] Fix | Delete
namespace Automattic\WooCommerce\Admin\Notes;
[5] Fix | Delete
[6] Fix | Delete
defined( 'ABSPATH' ) || exit;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* WC Admin Note Data Store (Custom Tables)
[10] Fix | Delete
*/
[11] Fix | Delete
class DataStore extends \WC_Data_Store_WP implements \WC_Object_Data_Store_Interface {
[12] Fix | Delete
// Extensions should define their own contexts and use them to avoid applying woocommerce_note_where_clauses when not needed.
[13] Fix | Delete
const WC_ADMIN_NOTE_OPER_GLOBAL = 'global';
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Method to create a new note in the database.
[17] Fix | Delete
*
[18] Fix | Delete
* @param Note $note Admin note.
[19] Fix | Delete
*/
[20] Fix | Delete
public function create( &$note ) {
[21] Fix | Delete
$date_created = time();
[22] Fix | Delete
$note->set_date_created( $date_created );
[23] Fix | Delete
[24] Fix | Delete
global $wpdb;
[25] Fix | Delete
[26] Fix | Delete
$note_to_be_inserted = array(
[27] Fix | Delete
'name' => $note->get_name(),
[28] Fix | Delete
'type' => $note->get_type(),
[29] Fix | Delete
'locale' => $note->get_locale(),
[30] Fix | Delete
'title' => $note->get_title(),
[31] Fix | Delete
'content' => $note->get_content(),
[32] Fix | Delete
'status' => $note->get_status(),
[33] Fix | Delete
'source' => $note->get_source(),
[34] Fix | Delete
'is_snoozable' => (int) $note->get_is_snoozable(),
[35] Fix | Delete
'layout' => $note->get_layout(),
[36] Fix | Delete
'image' => $note->get_image(),
[37] Fix | Delete
'is_deleted' => (int) $note->get_is_deleted(),
[38] Fix | Delete
'is_read' => (int) $note->get_is_read(),
[39] Fix | Delete
);
[40] Fix | Delete
[41] Fix | Delete
$note_to_be_inserted['content_data'] = wp_json_encode( $note->get_content_data() );
[42] Fix | Delete
$note_to_be_inserted['date_created'] = gmdate( 'Y-m-d H:i:s', $date_created );
[43] Fix | Delete
$note_to_be_inserted['date_reminder'] = null;
[44] Fix | Delete
[45] Fix | Delete
$wpdb->insert( $wpdb->prefix . 'wc_admin_notes', $note_to_be_inserted );
[46] Fix | Delete
$note_id = $wpdb->insert_id;
[47] Fix | Delete
$note->set_id( $note_id );
[48] Fix | Delete
$this->save_actions( $note );
[49] Fix | Delete
$note->apply_changes();
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Fires when an admin note is created.
[53] Fix | Delete
*
[54] Fix | Delete
* @param int $note_id Note ID.
[55] Fix | Delete
*/
[56] Fix | Delete
do_action( 'woocommerce_note_created', $note_id );
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Method to read a note.
[61] Fix | Delete
*
[62] Fix | Delete
* @param Note $note Admin note.
[63] Fix | Delete
* @throws \Exception Throws exception when invalid data is found.
[64] Fix | Delete
*/
[65] Fix | Delete
public function read( &$note ) {
[66] Fix | Delete
global $wpdb;
[67] Fix | Delete
[68] Fix | Delete
$note->set_defaults();
[69] Fix | Delete
$note_row = false;
[70] Fix | Delete
[71] Fix | Delete
$note_id = $note->get_id();
[72] Fix | Delete
if ( 0 !== $note_id || '0' !== $note_id ) {
[73] Fix | Delete
$note_row = $wpdb->get_row(
[74] Fix | Delete
$wpdb->prepare(
[75] Fix | Delete
"SELECT * FROM {$wpdb->prefix}wc_admin_notes WHERE note_id = %d LIMIT 1",
[76] Fix | Delete
$note->get_id()
[77] Fix | Delete
)
[78] Fix | Delete
);
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
if ( 0 === $note->get_id() || '0' === $note->get_id() ) {
[82] Fix | Delete
$this->read_actions( $note );
[83] Fix | Delete
$note->set_object_read( true );
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Fires when an admin note is loaded.
[87] Fix | Delete
*
[88] Fix | Delete
* @param int $note_id Note ID.
[89] Fix | Delete
*/
[90] Fix | Delete
do_action( 'woocommerce_note_loaded', $note );
[91] Fix | Delete
} elseif ( $note_row ) {
[92] Fix | Delete
$note->set_name( $note_row->name );
[93] Fix | Delete
$note->set_type( $note_row->type );
[94] Fix | Delete
$note->set_locale( $note_row->locale );
[95] Fix | Delete
$note->set_title( $note_row->title );
[96] Fix | Delete
$note->set_content( $note_row->content );
[97] Fix | Delete
[98] Fix | Delete
// The default for 'content_value' used to be an array, so there might be rows with invalid data!
[99] Fix | Delete
$content_data = json_decode( $note_row->content_data );
[100] Fix | Delete
if ( ! $content_data ) {
[101] Fix | Delete
$content_data = new \stdClass();
[102] Fix | Delete
} elseif ( is_array( $content_data ) ) {
[103] Fix | Delete
$content_data = (object) $content_data;
[104] Fix | Delete
}
[105] Fix | Delete
$note->set_content_data( $content_data );
[106] Fix | Delete
[107] Fix | Delete
$note->set_status( $note_row->status );
[108] Fix | Delete
$note->set_source( $note_row->source );
[109] Fix | Delete
$note->set_date_created( $note_row->date_created );
[110] Fix | Delete
$note->set_date_reminder( $note_row->date_reminder );
[111] Fix | Delete
$note->set_is_snoozable( (bool) $note_row->is_snoozable );
[112] Fix | Delete
$note->set_is_deleted( (bool) $note_row->is_deleted );
[113] Fix | Delete
isset( $note_row->is_read ) && $note->set_is_read( (bool) $note_row->is_read );
[114] Fix | Delete
$note->set_layout( $note_row->layout );
[115] Fix | Delete
$note->set_image( $note_row->image );
[116] Fix | Delete
$this->read_actions( $note );
[117] Fix | Delete
$note->set_object_read( true );
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Fires when an admin note is loaded.
[121] Fix | Delete
*
[122] Fix | Delete
* @param int $note_id Note ID.
[123] Fix | Delete
*/
[124] Fix | Delete
do_action( 'woocommerce_note_loaded', $note );
[125] Fix | Delete
} else {
[126] Fix | Delete
throw new \Exception( __( 'Invalid admin note', 'woocommerce' ) );
[127] Fix | Delete
}
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
/**
[131] Fix | Delete
* Updates a note in the database.
[132] Fix | Delete
*
[133] Fix | Delete
* @param Note $note Admin note.
[134] Fix | Delete
*/
[135] Fix | Delete
public function update( &$note ) {
[136] Fix | Delete
global $wpdb;
[137] Fix | Delete
[138] Fix | Delete
if ( $note->get_id() ) {
[139] Fix | Delete
$date_created = $note->get_date_created();
[140] Fix | Delete
$date_created_timestamp = $date_created->getTimestamp();
[141] Fix | Delete
$date_created_to_db = gmdate( 'Y-m-d H:i:s', $date_created_timestamp );
[142] Fix | Delete
[143] Fix | Delete
$date_reminder = $note->get_date_reminder();
[144] Fix | Delete
if ( is_null( $date_reminder ) ) {
[145] Fix | Delete
$date_reminder_to_db = null;
[146] Fix | Delete
} else {
[147] Fix | Delete
$date_reminder_timestamp = $date_reminder->getTimestamp();
[148] Fix | Delete
$date_reminder_to_db = gmdate( 'Y-m-d H:i:s', $date_reminder_timestamp );
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
$wpdb->update(
[152] Fix | Delete
$wpdb->prefix . 'wc_admin_notes',
[153] Fix | Delete
array(
[154] Fix | Delete
'name' => $note->get_name(),
[155] Fix | Delete
'type' => $note->get_type(),
[156] Fix | Delete
'locale' => $note->get_locale(),
[157] Fix | Delete
'title' => $note->get_title(),
[158] Fix | Delete
'content' => $note->get_content(),
[159] Fix | Delete
'content_data' => wp_json_encode( $note->get_content_data() ),
[160] Fix | Delete
'status' => $note->get_status(),
[161] Fix | Delete
'source' => $note->get_source(),
[162] Fix | Delete
'date_created' => $date_created_to_db,
[163] Fix | Delete
'date_reminder' => $date_reminder_to_db,
[164] Fix | Delete
'is_snoozable' => (int) $note->get_is_snoozable(),
[165] Fix | Delete
'layout' => $note->get_layout(),
[166] Fix | Delete
'image' => $note->get_image(),
[167] Fix | Delete
'is_deleted' => (int) $note->get_is_deleted(),
[168] Fix | Delete
'is_read' => (int) $note->get_is_read(),
[169] Fix | Delete
),
[170] Fix | Delete
array( 'note_id' => $note->get_id() )
[171] Fix | Delete
);
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
$this->save_actions( $note );
[175] Fix | Delete
$note->apply_changes();
[176] Fix | Delete
[177] Fix | Delete
/**
[178] Fix | Delete
* Fires when an admin note is updated.
[179] Fix | Delete
*
[180] Fix | Delete
* @param int $note_id Note ID.
[181] Fix | Delete
*/
[182] Fix | Delete
do_action( 'woocommerce_note_updated', $note->get_id() );
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Deletes a note from the database.
[187] Fix | Delete
*
[188] Fix | Delete
* @param Note $note Admin note.
[189] Fix | Delete
* @param array $args Array of args to pass to the delete method (not used).
[190] Fix | Delete
*/
[191] Fix | Delete
public function delete( &$note, $args = array() ) {
[192] Fix | Delete
$note_id = $note->get_id();
[193] Fix | Delete
if ( $note_id ) {
[194] Fix | Delete
global $wpdb;
[195] Fix | Delete
$wpdb->delete( $wpdb->prefix . 'wc_admin_notes', array( 'note_id' => $note_id ) );
[196] Fix | Delete
$wpdb->delete( $wpdb->prefix . 'wc_admin_note_actions', array( 'note_id' => $note_id ) );
[197] Fix | Delete
$note->set_id( null );
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* Fires when an admin note is deleted.
[202] Fix | Delete
*
[203] Fix | Delete
* @param int $note_id Note ID.
[204] Fix | Delete
*/
[205] Fix | Delete
do_action( 'woocommerce_note_deleted', $note_id );
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
/**
[209] Fix | Delete
* Read actions from the database.
[210] Fix | Delete
*
[211] Fix | Delete
* @param Note $note Admin note.
[212] Fix | Delete
*/
[213] Fix | Delete
private function read_actions( &$note ) {
[214] Fix | Delete
global $wpdb;
[215] Fix | Delete
[216] Fix | Delete
$db_actions = $wpdb->get_results(
[217] Fix | Delete
$wpdb->prepare(
[218] Fix | Delete
"SELECT action_id, name, label, query, status, actioned_text, nonce_action, nonce_name
[219] Fix | Delete
FROM {$wpdb->prefix}wc_admin_note_actions
[220] Fix | Delete
WHERE note_id = %d",
[221] Fix | Delete
$note->get_id()
[222] Fix | Delete
)
[223] Fix | Delete
);
[224] Fix | Delete
[225] Fix | Delete
$note_actions = array();
[226] Fix | Delete
[227] Fix | Delete
if ( $db_actions ) {
[228] Fix | Delete
foreach ( $db_actions as $action ) {
[229] Fix | Delete
$note_actions[] = (object) array(
[230] Fix | Delete
'id' => (int) $action->action_id,
[231] Fix | Delete
'name' => $action->name,
[232] Fix | Delete
'label' => $action->label,
[233] Fix | Delete
'query' => $action->query,
[234] Fix | Delete
'status' => $action->status,
[235] Fix | Delete
'actioned_text' => $action->actioned_text,
[236] Fix | Delete
'nonce_action' => $action->nonce_action,
[237] Fix | Delete
'nonce_name' => $action->nonce_name,
[238] Fix | Delete
);
[239] Fix | Delete
}
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
$note->set_actions( $note_actions );
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
/**
[246] Fix | Delete
* Save actions to the database.
[247] Fix | Delete
* This function clears old actions, then re-inserts new if any changes are found.
[248] Fix | Delete
*
[249] Fix | Delete
* @param Note $note Note object.
[250] Fix | Delete
*
[251] Fix | Delete
* @return bool|void
[252] Fix | Delete
*/
[253] Fix | Delete
private function save_actions( &$note ) {
[254] Fix | Delete
global $wpdb;
[255] Fix | Delete
[256] Fix | Delete
$changed_props = array_keys( $note->get_changes() );
[257] Fix | Delete
[258] Fix | Delete
if ( ! in_array( 'actions', $changed_props, true ) ) {
[259] Fix | Delete
return false;
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
// Process action removal. Actions are removed from
[263] Fix | Delete
// the note if they aren't part of the changeset.
[264] Fix | Delete
// See Note::add_action().
[265] Fix | Delete
$changed_actions = $note->get_actions( 'edit' );
[266] Fix | Delete
$actions_to_keep = array();
[267] Fix | Delete
[268] Fix | Delete
foreach ( $changed_actions as $action ) {
[269] Fix | Delete
if ( ! empty( $action->id ) ) {
[270] Fix | Delete
$actions_to_keep[] = (int) $action->id;
[271] Fix | Delete
}
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
$clear_actions_query = $wpdb->prepare(
[275] Fix | Delete
"DELETE FROM {$wpdb->prefix}wc_admin_note_actions WHERE note_id = %d",
[276] Fix | Delete
$note->get_id()
[277] Fix | Delete
);
[278] Fix | Delete
[279] Fix | Delete
if ( $actions_to_keep ) {
[280] Fix | Delete
$clear_actions_query .= sprintf( ' AND action_id NOT IN (%s)', implode( ',', $actions_to_keep ) );
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
$wpdb->query( $clear_actions_query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
[284] Fix | Delete
[285] Fix | Delete
// Update/insert the actions in this changeset.
[286] Fix | Delete
foreach ( $changed_actions as $action ) {
[287] Fix | Delete
$action_data = array(
[288] Fix | Delete
'note_id' => $note->get_id(),
[289] Fix | Delete
'name' => $action->name,
[290] Fix | Delete
'label' => $action->label,
[291] Fix | Delete
'query' => $action->query,
[292] Fix | Delete
'status' => $action->status,
[293] Fix | Delete
'actioned_text' => $action->actioned_text,
[294] Fix | Delete
'nonce_action' => $action->nonce_action,
[295] Fix | Delete
'nonce_name' => $action->nonce_name,
[296] Fix | Delete
);
[297] Fix | Delete
[298] Fix | Delete
$data_format = array(
[299] Fix | Delete
'%d',
[300] Fix | Delete
'%s',
[301] Fix | Delete
'%s',
[302] Fix | Delete
'%s',
[303] Fix | Delete
'%s',
[304] Fix | Delete
'%s',
[305] Fix | Delete
'%s',
[306] Fix | Delete
'%s',
[307] Fix | Delete
);
[308] Fix | Delete
[309] Fix | Delete
if ( ! empty( $action->id ) ) {
[310] Fix | Delete
$action_data['action_id'] = $action->id;
[311] Fix | Delete
$data_format[] = '%d';
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
$wpdb->replace(
[315] Fix | Delete
$wpdb->prefix . 'wc_admin_note_actions',
[316] Fix | Delete
$action_data,
[317] Fix | Delete
$data_format
[318] Fix | Delete
);
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
// Update actions from DB (to grab new IDs).
[322] Fix | Delete
$this->read_actions( $note );
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
/**
[326] Fix | Delete
* Return an ordered list of notes.
[327] Fix | Delete
*
[328] Fix | Delete
* @param array $args Query arguments.
[329] Fix | Delete
* @param string $context Optional argument that the woocommerce_note_where_clauses filter can use to determine whether to apply extra conditions. Extensions should define their own contexts and use them to avoid adding to notes where clauses when not needed.
[330] Fix | Delete
* @return array An array of objects containing a note id.
[331] Fix | Delete
*/
[332] Fix | Delete
public function get_notes( $args = array(), $context = self::WC_ADMIN_NOTE_OPER_GLOBAL ) {
[333] Fix | Delete
global $wpdb;
[334] Fix | Delete
[335] Fix | Delete
$defaults = array(
[336] Fix | Delete
'per_page' => get_option( 'posts_per_page' ),
[337] Fix | Delete
'page' => 1,
[338] Fix | Delete
'order' => 'DESC',
[339] Fix | Delete
'orderby' => 'date_created',
[340] Fix | Delete
);
[341] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[342] Fix | Delete
[343] Fix | Delete
$offset = $args['per_page'] * ( $args['page'] - 1 );
[344] Fix | Delete
$where_clauses = $this->get_notes_where_clauses( $args, $context );
[345] Fix | Delete
[346] Fix | Delete
// sanitize order and orderby.
[347] Fix | Delete
$order_by = '`' . str_replace( '`', '', $args['orderby'] ) . '`';
[348] Fix | Delete
$order_dir = 'asc' === strtolower( $args['order'] ) ? 'ASC' : 'DESC';
[349] Fix | Delete
[350] Fix | Delete
$query = $wpdb->prepare(
[351] Fix | Delete
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
[352] Fix | Delete
"SELECT * FROM {$wpdb->prefix}wc_admin_notes WHERE 1=1{$where_clauses} ORDER BY {$order_by} {$order_dir} LIMIT %d, %d",
[353] Fix | Delete
$offset,
[354] Fix | Delete
$args['per_page']
[355] Fix | Delete
);
[356] Fix | Delete
[357] Fix | Delete
return $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
/**
[361] Fix | Delete
* Return an ordered list of notes, without paging or applying the 'woocommerce_note_where_clauses' filter.
[362] Fix | Delete
* INTERNAL: This method is not intended to be used by external code, and may change without notice.
[363] Fix | Delete
*
[364] Fix | Delete
* @param array $args Query arguments.
[365] Fix | Delete
* @return array An array of database records.
[366] Fix | Delete
*/
[367] Fix | Delete
public function lookup_notes( $args = array() ) {
[368] Fix | Delete
global $wpdb;
[369] Fix | Delete
[370] Fix | Delete
$defaults = array(
[371] Fix | Delete
'order' => 'DESC',
[372] Fix | Delete
'orderby' => 'date_created',
[373] Fix | Delete
);
[374] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[375] Fix | Delete
[376] Fix | Delete
$where_clauses = $this->args_to_where_clauses( $args );
[377] Fix | Delete
[378] Fix | Delete
// sanitize order and orderby.
[379] Fix | Delete
$order_by = '`' . str_replace( '`', '', $args['orderby'] ) . '`';
[380] Fix | Delete
$order_dir = 'asc' === strtolower( $args['order'] ) ? 'ASC' : 'DESC';
[381] Fix | Delete
[382] Fix | Delete
$query = "SELECT * FROM {$wpdb->prefix}wc_admin_notes WHERE 1=1{$where_clauses} ORDER BY {$order_by} {$order_dir}";
[383] Fix | Delete
[384] Fix | Delete
return $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
[385] Fix | Delete
}
[386] Fix | Delete
[387] Fix | Delete
/**
[388] Fix | Delete
* Return a count of notes.
[389] Fix | Delete
*
[390] Fix | Delete
* @param string $type Comma separated list of note types.
[391] Fix | Delete
* @param string $status Comma separated list of statuses.
[392] Fix | Delete
* @param string $context Optional argument that the woocommerce_note_where_clauses filter can use to determine whether to apply extra conditions. Extensions should define their own contexts and use them to avoid adding to notes where clauses when not needed.
[393] Fix | Delete
* @return string Count of objects with given type, status and context.
[394] Fix | Delete
*/
[395] Fix | Delete
public function get_notes_count( $type = array(), $status = array(), $context = self::WC_ADMIN_NOTE_OPER_GLOBAL ) {
[396] Fix | Delete
global $wpdb;
[397] Fix | Delete
[398] Fix | Delete
$where_clauses = $this->get_notes_where_clauses(
[399] Fix | Delete
array(
[400] Fix | Delete
'type' => $type,
[401] Fix | Delete
'status' => $status,
[402] Fix | Delete
),
[403] Fix | Delete
$context
[404] Fix | Delete
);
[405] Fix | Delete
[406] Fix | Delete
if ( ! empty( $where_clauses ) ) {
[407] Fix | Delete
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
[408] Fix | Delete
return $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}wc_admin_notes WHERE 1=1{$where_clauses}" );
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
return $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}wc_admin_notes" );
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
/**
[415] Fix | Delete
* Parses the query arguments passed in as arrays and escapes the values.
[416] Fix | Delete
*
[417] Fix | Delete
* @param array $args the query arguments.
[418] Fix | Delete
* @param string $key the key of the specific argument.
[419] Fix | Delete
* @param array|null $allowed_types optional allowed_types if only a specific set is allowed.
[420] Fix | Delete
* @return array the escaped array of argument values.
[421] Fix | Delete
*/
[422] Fix | Delete
private function get_escaped_arguments_array_by_key( $args = array(), $key = '', $allowed_types = null ) {
[423] Fix | Delete
$arg_array = array();
[424] Fix | Delete
if ( isset( $args[ $key ] ) ) {
[425] Fix | Delete
foreach ( $args[ $key ] as $args_type ) {
[426] Fix | Delete
$args_type = trim( $args_type );
[427] Fix | Delete
$allowed = is_null( $allowed_types ) || in_array( $args_type, $allowed_types, true );
[428] Fix | Delete
if ( $allowed ) {
[429] Fix | Delete
$arg_array[] = sprintf( "'%s'", esc_sql( $args_type ) );
[430] Fix | Delete
}
[431] Fix | Delete
}
[432] Fix | Delete
}
[433] Fix | Delete
return $arg_array;
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
/**
[437] Fix | Delete
* Return where clauses for getting notes by status and type. For use in both the count and listing queries.
[438] Fix | Delete
* Applies woocommerce_note_where_clauses filter.
[439] Fix | Delete
*
[440] Fix | Delete
* @uses args_to_where_clauses
[441] Fix | Delete
* @param array $args Array of args to pass.
[442] Fix | Delete
* @param string $context Optional argument that the woocommerce_note_where_clauses filter can use to determine whether to apply extra conditions. Extensions should define their own contexts and use them to avoid adding to notes where clauses when not needed.
[443] Fix | Delete
* @return string Where clauses for the query.
[444] Fix | Delete
*/
[445] Fix | Delete
public function get_notes_where_clauses( $args = array(), $context = self::WC_ADMIN_NOTE_OPER_GLOBAL ) {
[446] Fix | Delete
$where_clauses = $this->args_to_where_clauses( $args );
[447] Fix | Delete
[448] Fix | Delete
/**
[449] Fix | Delete
* Filter the notes WHERE clause before retrieving the data.
[450] Fix | Delete
*
[451] Fix | Delete
* Allows modification of the notes select criterial.
[452] Fix | Delete
*
[453] Fix | Delete
* @param string $where_clauses The generated WHERE clause.
[454] Fix | Delete
* @param array $args The original arguments for the request.
[455] Fix | Delete
* @param string $context Optional argument that the woocommerce_note_where_clauses filter can use to determine whether to apply extra conditions. Extensions should define their own contexts and use them to avoid adding to notes where clauses when not needed.
[456] Fix | Delete
*/
[457] Fix | Delete
return apply_filters( 'woocommerce_note_where_clauses', $where_clauses, $args, $context );
[458] Fix | Delete
}
[459] Fix | Delete
[460] Fix | Delete
/**
[461] Fix | Delete
* Return where clauses for notes queries without applying woocommerce_note_where_clauses filter.
[462] Fix | Delete
* INTERNAL: This method is not intended to be used by external code, and may change without notice.
[463] Fix | Delete
*
[464] Fix | Delete
* @param array $args Array of arguments for query conditionals.
[465] Fix | Delete
* @return string Where clauses.
[466] Fix | Delete
*/
[467] Fix | Delete
protected function args_to_where_clauses( $args = array() ) {
[468] Fix | Delete
$allowed_types = Note::get_allowed_types();
[469] Fix | Delete
$where_type_array = $this->get_escaped_arguments_array_by_key( $args, 'type', $allowed_types );
[470] Fix | Delete
[471] Fix | Delete
$allowed_statuses = Note::get_allowed_statuses();
[472] Fix | Delete
$where_status_array = $this->get_escaped_arguments_array_by_key( $args, 'status', $allowed_statuses );
[473] Fix | Delete
[474] Fix | Delete
$escaped_is_deleted = '';
[475] Fix | Delete
if ( isset( $args['is_deleted'] ) ) {
[476] Fix | Delete
$escaped_is_deleted = esc_sql( $args['is_deleted'] );
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
$where_name_array = $this->get_escaped_arguments_array_by_key( $args, 'name' );
[480] Fix | Delete
$where_excluded_name_array = $this->get_escaped_arguments_array_by_key( $args, 'excluded_name' );
[481] Fix | Delete
$where_source_array = $this->get_escaped_arguments_array_by_key( $args, 'source' );
[482] Fix | Delete
[483] Fix | Delete
$escaped_where_types = implode( ',', $where_type_array );
[484] Fix | Delete
$escaped_where_status = implode( ',', $where_status_array );
[485] Fix | Delete
$escaped_where_names = implode( ',', $where_name_array );
[486] Fix | Delete
$escaped_where_excluded_names = implode( ',', $where_excluded_name_array );
[487] Fix | Delete
$escaped_where_source = implode( ',', $where_source_array );
[488] Fix | Delete
$where_clauses = '';
[489] Fix | Delete
[490] Fix | Delete
if ( ! empty( $escaped_where_types ) ) {
[491] Fix | Delete
$where_clauses .= " AND type IN ($escaped_where_types)";
[492] Fix | Delete
}
[493] Fix | Delete
[494] Fix | Delete
if ( ! empty( $escaped_where_status ) ) {
[495] Fix | Delete
$where_clauses .= " AND status IN ($escaped_where_status)";
[496] Fix | Delete
}
[497] Fix | Delete
[498] Fix | Delete
if ( ! empty( $escaped_where_names ) ) {
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function