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/wpforms-.../src/Admin/Payments/Views/Overview
File: Ajax.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Admin\Payments\Views\Overview;
[2] Fix | Delete
[3] Fix | Delete
use DateTimeImmutable;
[4] Fix | Delete
// phpcs:ignore WPForms.PHP.UseStatement.UnusedUseStatement
[5] Fix | Delete
use wpdb;
[6] Fix | Delete
use WPForms\Db\Payments\ValueValidator;
[7] Fix | Delete
use WPForms\Admin\Helpers\Chart as ChartHelper;
[8] Fix | Delete
use WPForms\Admin\Helpers\Datepicker;
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* "Payments" overview page inside the admin, which lists all payments.
[12] Fix | Delete
* This page will be accessible via "WPForms" → "Payments".
[13] Fix | Delete
*
[14] Fix | Delete
* When requested data is sent via Ajax, this class is responsible for exchanging datasets.
[15] Fix | Delete
*
[16] Fix | Delete
* @since 1.8.2
[17] Fix | Delete
*/
[18] Fix | Delete
class Ajax {
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Database table name.
[22] Fix | Delete
*
[23] Fix | Delete
* @since 1.8.2
[24] Fix | Delete
*
[25] Fix | Delete
* @var string
[26] Fix | Delete
*/
[27] Fix | Delete
private $table_name;
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Temporary storage for the stat cards.
[31] Fix | Delete
*
[32] Fix | Delete
* @since 1.8.4
[33] Fix | Delete
*
[34] Fix | Delete
* @var array
[35] Fix | Delete
*/
[36] Fix | Delete
private $stat_cards;
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Hooks.
[40] Fix | Delete
*
[41] Fix | Delete
* @since 1.8.2
[42] Fix | Delete
*/
[43] Fix | Delete
public function hooks() {
[44] Fix | Delete
[45] Fix | Delete
add_action( 'wp_ajax_wpforms_payments_overview_refresh_chart_dataset_data', [ $this, 'get_chart_dataset_data' ] );
[46] Fix | Delete
add_action( 'wp_ajax_wpforms_payments_overview_save_chart_preference_settings', [ $this, 'save_chart_preference_settings' ] );
[47] Fix | Delete
add_filter( 'wpforms_db_payments_payment_add_secondary_where_conditions_args', [ $this, 'modify_secondary_where_conditions_args' ] );
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Generate and return the data for our dataset data.
[52] Fix | Delete
*
[53] Fix | Delete
* @since 1.8.2
[54] Fix | Delete
*/
[55] Fix | Delete
public function get_chart_dataset_data() {
[56] Fix | Delete
[57] Fix | Delete
// Verify the nonce.
[58] Fix | Delete
check_ajax_referer( 'wpforms_payments_overview_nonce' );
[59] Fix | Delete
[60] Fix | Delete
$report = ! empty( $_POST['report'] ) ? sanitize_text_field( wp_unslash( $_POST['report'] ) ) : null;
[61] Fix | Delete
$dates = ! empty( $_POST['dates'] ) ? sanitize_text_field( wp_unslash( $_POST['dates'] ) ) : null;
[62] Fix | Delete
$fallback = [
[63] Fix | Delete
'data' => [],
[64] Fix | Delete
'reports' => [],
[65] Fix | Delete
];
[66] Fix | Delete
[67] Fix | Delete
// If the report type or dates for the timespan are missing, leave early.
[68] Fix | Delete
if ( ! $report || ! $dates ) {
[69] Fix | Delete
wp_send_json_error( $fallback );
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
// Validates and creates date objects of given timespan string.
[73] Fix | Delete
$timespans = Datepicker::process_string_timespan( $dates );
[74] Fix | Delete
[75] Fix | Delete
// If the timespan is not validated, leave early.
[76] Fix | Delete
if ( ! $timespans ) {
[77] Fix | Delete
wp_send_json_error( $fallback );
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
// Extract start and end timespans in local (site) and UTC timezones.
[81] Fix | Delete
list( $start_date, $end_date, $utc_start_date, $utc_end_date ) = $timespans;
[82] Fix | Delete
[83] Fix | Delete
// Payment table name.
[84] Fix | Delete
$this->table_name = wpforms()->get( 'payment' )->table_name;
[85] Fix | Delete
[86] Fix | Delete
// Get the stat cards.
[87] Fix | Delete
$this->stat_cards = Chart::stat_cards();
[88] Fix | Delete
[89] Fix | Delete
// Get the payments in the given timespan.
[90] Fix | Delete
$results = $this->get_payments_in_timespan( $utc_start_date, $utc_end_date, $report );
[91] Fix | Delete
[92] Fix | Delete
// In case the database's results were empty, leave early.
[93] Fix | Delete
if ( $report === Chart::ACTIVE_REPORT && empty( $results ) ) {
[94] Fix | Delete
wp_send_json_error( $fallback );
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
// Process the results and return the data.
[98] Fix | Delete
// The first element of the array is the total number of entries, the second is the data.
[99] Fix | Delete
list( , $data ) = ChartHelper::process_chart_dataset_data( $results, $start_date, $end_date );
[100] Fix | Delete
[101] Fix | Delete
// Sends the JSON response back to the Ajax request, indicating success.
[102] Fix | Delete
wp_send_json_success(
[103] Fix | Delete
[
[104] Fix | Delete
'data' => $data,
[105] Fix | Delete
'reports' => $this->get_payments_summary_in_timespan( $start_date, $end_date ),
[106] Fix | Delete
]
[107] Fix | Delete
);
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* Save the user's preferred graph style and color scheme.
[112] Fix | Delete
*
[113] Fix | Delete
* @since 1.8.2
[114] Fix | Delete
*/
[115] Fix | Delete
public function save_chart_preference_settings() {
[116] Fix | Delete
[117] Fix | Delete
// Verify the nonce.
[118] Fix | Delete
check_ajax_referer( 'wpforms_payments_overview_nonce' );
[119] Fix | Delete
[120] Fix | Delete
$graph_style = isset( $_POST['graphStyle'] ) ? absint( $_POST['graphStyle'] ) : 2; // Line.
[121] Fix | Delete
[122] Fix | Delete
update_user_meta( get_current_user_id(), 'wpforms_dash_widget_graph_style', $graph_style );
[123] Fix | Delete
[124] Fix | Delete
exit();
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Retrieve and create payment entries from the database within the specified time frame (timespan).
[129] Fix | Delete
*
[130] Fix | Delete
* @global wpdb $wpdb Instantiation of the wpdb class.
[131] Fix | Delete
*
[132] Fix | Delete
* @since 1.8.2
[133] Fix | Delete
*
[134] Fix | Delete
* @param DateTimeImmutable $start_date Start date for the timespan preferably in UTC.
[135] Fix | Delete
* @param DateTimeImmutable $end_date End date for the timespan preferably in UTC.
[136] Fix | Delete
* @param string $report Payment summary stat card name. i.e. "total_payments".
[137] Fix | Delete
*
[138] Fix | Delete
* @return array
[139] Fix | Delete
*/
[140] Fix | Delete
private function get_payments_in_timespan( $start_date, $end_date, $report ) {
[141] Fix | Delete
[142] Fix | Delete
// Ensure given timespan dates are in UTC timezone.
[143] Fix | Delete
list( $utc_start_date, $utc_end_date ) = Datepicker::process_timespan_mysql( [ $start_date, $end_date ] );
[144] Fix | Delete
[145] Fix | Delete
// If the time period is not a date object, leave early.
[146] Fix | Delete
if ( ! ( $start_date instanceof DateTimeImmutable ) || ! ( $end_date instanceof DateTimeImmutable ) ) {
[147] Fix | Delete
return [];
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
// Get the database instance.
[151] Fix | Delete
global $wpdb;
[152] Fix | Delete
[153] Fix | Delete
// SELECT clause to construct the SQL statement.
[154] Fix | Delete
$column_clause = $this->get_stats_column_clause( $report );
[155] Fix | Delete
[156] Fix | Delete
// JOIN clause to construct the SQL statement for metadata.
[157] Fix | Delete
$join_by_meta = $this->add_join_by_meta( $report );
[158] Fix | Delete
[159] Fix | Delete
// WHERE clauses for items query statement.
[160] Fix | Delete
$where_clause = $this->get_stats_where_clause( $report );
[161] Fix | Delete
[162] Fix | Delete
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
[163] Fix | Delete
return $wpdb->get_results(
[164] Fix | Delete
$wpdb->prepare(
[165] Fix | Delete
"SELECT date_created_gmt AS day, $column_clause AS count FROM $this->table_name AS p {$join_by_meta}
[166] Fix | Delete
WHERE 1=1 $where_clause AND date_created_gmt BETWEEN %s AND %s GROUP BY day ORDER BY day ASC",
[167] Fix | Delete
[
[168] Fix | Delete
$utc_start_date->format( Datepicker::DATETIME_FORMAT ),
[169] Fix | Delete
$utc_end_date->format( Datepicker::DATETIME_FORMAT ),
[170] Fix | Delete
]
[171] Fix | Delete
),
[172] Fix | Delete
ARRAY_A
[173] Fix | Delete
);
[174] Fix | Delete
// phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
/**
[178] Fix | Delete
* Fetch and generate payment summary reports from the database.
[179] Fix | Delete
*
[180] Fix | Delete
* @global wpdb $wpdb Instantiation of the wpdb class.
[181] Fix | Delete
*
[182] Fix | Delete
* @since 1.8.2
[183] Fix | Delete
*
[184] Fix | Delete
* @param DateTimeImmutable $start_date Start date for the timespan preferably in UTC.
[185] Fix | Delete
* @param DateTimeImmutable $end_date End date for the timespan preferably in UTC.
[186] Fix | Delete
*
[187] Fix | Delete
* @return array
[188] Fix | Delete
*/
[189] Fix | Delete
private function get_payments_summary_in_timespan( $start_date, $end_date ) {
[190] Fix | Delete
[191] Fix | Delete
// Ensure given timespan dates are in UTC timezone.
[192] Fix | Delete
list( $utc_start_date, $utc_end_date ) = Datepicker::process_timespan_mysql( [ $start_date, $end_date ] );
[193] Fix | Delete
[194] Fix | Delete
// If the time period is not a date object, leave early.
[195] Fix | Delete
if ( ! ( $start_date instanceof DateTimeImmutable ) || ! ( $end_date instanceof DateTimeImmutable ) ) {
[196] Fix | Delete
return [];
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
// Get the database instance.
[200] Fix | Delete
global $wpdb;
[201] Fix | Delete
[202] Fix | Delete
list( $clause, $query ) = $this->prepare_sql_summary_reports( $utc_start_date, $utc_end_date );
[203] Fix | Delete
[204] Fix | Delete
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
[205] Fix | Delete
$group_by = Chart::ACTIVE_REPORT;
[206] Fix | Delete
$results = $wpdb->get_row(
[207] Fix | Delete
"SELECT $clause FROM (SELECT $query) AS results GROUP BY $group_by",
[208] Fix | Delete
ARRAY_A
[209] Fix | Delete
);
[210] Fix | Delete
// phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
[211] Fix | Delete
[212] Fix | Delete
return $this->maybe_format_amounts( $results );
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
/**
[216] Fix | Delete
* Generate SQL statements to create a derived (virtual) table for the report stat cards.
[217] Fix | Delete
*
[218] Fix | Delete
* @global wpdb $wpdb Instantiation of the wpdb class.
[219] Fix | Delete
*
[220] Fix | Delete
* @since 1.8.2
[221] Fix | Delete
*
[222] Fix | Delete
* @param DateTimeImmutable $start_date Start date for the timespan.
[223] Fix | Delete
* @param DateTimeImmutable $end_date End date for the timespan.
[224] Fix | Delete
*
[225] Fix | Delete
* @return array
[226] Fix | Delete
*/
[227] Fix | Delete
private function prepare_sql_summary_reports( $start_date, $end_date ) {
[228] Fix | Delete
[229] Fix | Delete
// In case there are no report stat cards defined, leave early.
[230] Fix | Delete
if ( empty( $this->stat_cards ) ) {
[231] Fix | Delete
return [ '', '' ];
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
global $wpdb;
[235] Fix | Delete
[236] Fix | Delete
$clause = []; // SELECT clause.
[237] Fix | Delete
$query = []; // Query statement for the derived table.
[238] Fix | Delete
[239] Fix | Delete
// Validates and creates date objects for the previous time spans.
[240] Fix | Delete
$prev_timespans = Datepicker::get_prev_timespan_dates( $start_date, $end_date );
[241] Fix | Delete
[242] Fix | Delete
// If the timespan is not validated, leave early.
[243] Fix | Delete
if ( ! $prev_timespans ) {
[244] Fix | Delete
return [ '', '' ];
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
list( $prev_start_date, $prev_end_date ) = $prev_timespans;
[248] Fix | Delete
[249] Fix | Delete
// Get the default number of decimals for the payment currency.
[250] Fix | Delete
$current_currency = wpforms_get_currency();
[251] Fix | Delete
$currency_decimals = wpforms_get_currency_decimals( $current_currency );
[252] Fix | Delete
[253] Fix | Delete
// Loop through the reports and create the SQL statements.
[254] Fix | Delete
foreach ( $this->stat_cards as $report => $attributes ) {
[255] Fix | Delete
[256] Fix | Delete
// Skip stat card, if it's not supposed to be displayed or disabled (upsell).
[257] Fix | Delete
if (
[258] Fix | Delete
( isset( $attributes['condition'] ) && ! $attributes['condition'] )
[259] Fix | Delete
|| in_array( 'disabled', $attributes['button_classes'], true )
[260] Fix | Delete
) {
[261] Fix | Delete
continue;
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
// Determine whether the number of rows has to be counted.
[265] Fix | Delete
$has_count = isset( $attributes['has_count'] ) && $attributes['has_count'];
[266] Fix | Delete
[267] Fix | Delete
// SELECT clause to construct the SQL statement.
[268] Fix | Delete
$column_clause = $this->get_stats_column_clause( $report, $has_count );
[269] Fix | Delete
[270] Fix | Delete
// JOIN clause to construct the SQL statement for metadata.
[271] Fix | Delete
$join_by_meta = $this->add_join_by_meta( $report );
[272] Fix | Delete
[273] Fix | Delete
// WHERE clauses for items query statement.
[274] Fix | Delete
$where_clause = $this->get_stats_where_clause( $report );
[275] Fix | Delete
[276] Fix | Delete
// Get the current and previous values for the report.
[277] Fix | Delete
$current_value = "TRUNCATE($report,$currency_decimals)";
[278] Fix | Delete
$prev_value = "TRUNCATE({$report}_prev,$currency_decimals)";
[279] Fix | Delete
[280] Fix | Delete
// Add the current and previous reports to the SELECT clause.
[281] Fix | Delete
$clause[] = $report;
[282] Fix | Delete
$clause[] = "ROUND( ( ( $current_value - $prev_value ) / $current_value ) * 100 ) AS {$report}_delta";
[283] Fix | Delete
[284] Fix | Delete
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.MissingReplacements
[285] Fix | Delete
$query[] = $wpdb->prepare(
[286] Fix | Delete
"(
[287] Fix | Delete
SELECT $column_clause
[288] Fix | Delete
FROM $this->table_name AS p
[289] Fix | Delete
{$join_by_meta}
[290] Fix | Delete
WHERE 1=1 $where_clause AND date_created_gmt BETWEEN %s AND %s
[291] Fix | Delete
) AS $report,
[292] Fix | Delete
(
[293] Fix | Delete
SELECT $column_clause
[294] Fix | Delete
FROM $this->table_name AS p
[295] Fix | Delete
{$join_by_meta}
[296] Fix | Delete
WHERE 1=1 $where_clause AND date_created_gmt BETWEEN %s AND %s
[297] Fix | Delete
) AS {$report}_prev",
[298] Fix | Delete
[
[299] Fix | Delete
$start_date->format( Datepicker::DATETIME_FORMAT ),
[300] Fix | Delete
$end_date->format( Datepicker::DATETIME_FORMAT ),
[301] Fix | Delete
$prev_start_date->format( Datepicker::DATETIME_FORMAT ),
[302] Fix | Delete
$prev_end_date->format( Datepicker::DATETIME_FORMAT ),
[303] Fix | Delete
]
[304] Fix | Delete
);
[305] Fix | Delete
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.MissingReplacements
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
return [
[309] Fix | Delete
implode( ',', $clause ),
[310] Fix | Delete
implode( ',', $query ),
[311] Fix | Delete
];
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
/**
[315] Fix | Delete
* Helper method to build where clause used to construct the SQL statement.
[316] Fix | Delete
*
[317] Fix | Delete
* @since 1.8.2
[318] Fix | Delete
*
[319] Fix | Delete
* @param string $report Payment summary stat card name. i.e. "total_payments".
[320] Fix | Delete
*
[321] Fix | Delete
* @return string
[322] Fix | Delete
*/
[323] Fix | Delete
private function get_stats_where_clause( $report ) {
[324] Fix | Delete
[325] Fix | Delete
// Get the default WHERE clause from the Payments database class.
[326] Fix | Delete
$clause = wpforms()->get( 'payment' )->add_secondary_where_conditions();
[327] Fix | Delete
[328] Fix | Delete
// If the report doesn't have any additional funnel arguments, leave early.
[329] Fix | Delete
if ( ! isset( $this->stat_cards[ $report ]['funnel'] ) ) {
[330] Fix | Delete
return $clause;
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
// Get the where arguments for the report.
[334] Fix | Delete
$where_args = (array) $this->stat_cards[ $report ]['funnel'];
[335] Fix | Delete
[336] Fix | Delete
// If the where arguments are empty, leave early.
[337] Fix | Delete
if ( empty( $where_args ) ) {
[338] Fix | Delete
return $clause;
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
return $this->prepare_sql_where_clause( $where_args, $clause );
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
/**
[345] Fix | Delete
* Prepare SQL where clause for the given funnel arguments.
[346] Fix | Delete
*
[347] Fix | Delete
* @since 1.8.4
[348] Fix | Delete
*
[349] Fix | Delete
* @param array $where_args Array of where arguments.
[350] Fix | Delete
* @param string $clause SQL where clause.
[351] Fix | Delete
*
[352] Fix | Delete
* @return string
[353] Fix | Delete
*/
[354] Fix | Delete
private function prepare_sql_where_clause( $where_args, $clause ) {
[355] Fix | Delete
[356] Fix | Delete
$allowed_funnels = [ 'in', 'not_in' ];
[357] Fix | Delete
[358] Fix | Delete
$filtered_where_args = array_filter(
[359] Fix | Delete
$where_args,
[360] Fix | Delete
static function ( $key ) use ( $allowed_funnels ) {
[361] Fix | Delete
[362] Fix | Delete
return in_array( $key, $allowed_funnels, true );
[363] Fix | Delete
},
[364] Fix | Delete
ARRAY_FILTER_USE_KEY
[365] Fix | Delete
);
[366] Fix | Delete
[367] Fix | Delete
// Leave early if the filtered where arguments are empty.
[368] Fix | Delete
if ( empty( $filtered_where_args ) ) {
[369] Fix | Delete
return $clause;
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
// Loop through the where arguments and add them to the clause.
[373] Fix | Delete
foreach ( $filtered_where_args as $operator => $columns ) {
[374] Fix | Delete
foreach ( $columns as $column => $values ) {
[375] Fix | Delete
if ( ! is_array( $values ) ) {
[376] Fix | Delete
continue;
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
// Skip if the value is not valid.
[380] Fix | Delete
$valid_values = array_filter(
[381] Fix | Delete
$values,
[382] Fix | Delete
static function ( $item ) use ( $column ) {
[383] Fix | Delete
[384] Fix | Delete
return ValueValidator::is_valid( $item, $column );
[385] Fix | Delete
}
[386] Fix | Delete
);
[387] Fix | Delete
[388] Fix | Delete
$placeholders = wpforms_wpdb_prepare_in( $valid_values );
[389] Fix | Delete
$clause .= $operator === 'in' ? " AND {$column} IN ({$placeholders})" : " AND {$column} NOT IN ({$placeholders})";
[390] Fix | Delete
}
[391] Fix | Delete
}
[392] Fix | Delete
[393] Fix | Delete
return $clause;
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
/**
[397] Fix | Delete
* Helper method to build column clause used to construct the SQL statement.
[398] Fix | Delete
*
[399] Fix | Delete
* @since 1.8.2
[400] Fix | Delete
*
[401] Fix | Delete
* @param string $report Stats card chart type (name). i.e. "total_payments".
[402] Fix | Delete
* @param bool $with_count Whether to concatenate the count to the clause.
[403] Fix | Delete
*
[404] Fix | Delete
* @return string
[405] Fix | Delete
*/
[406] Fix | Delete
private function get_stats_column_clause( $report, $with_count = false ) {
[407] Fix | Delete
[408] Fix | Delete
// Default column clause.
[409] Fix | Delete
// Count the number of rows as fast as possible.
[410] Fix | Delete
$default = 'COUNT(*)';
[411] Fix | Delete
[412] Fix | Delete
// If the report has a meta key, then count the number of unique rows for the meta table.
[413] Fix | Delete
if ( isset( $this->stat_cards[ $report ]['meta_key'] ) ) {
[414] Fix | Delete
$default = 'COUNT(pm.id)';
[415] Fix | Delete
}
[416] Fix | Delete
[417] Fix | Delete
/**
[418] Fix | Delete
* Filters the column clauses for the stat cards.
[419] Fix | Delete
*
[420] Fix | Delete
* @since 1.8.2
[421] Fix | Delete
*
[422] Fix | Delete
* @param array $clauses Array of column clauses.
[423] Fix | Delete
*/
[424] Fix | Delete
$clauses = (array) apply_filters(
[425] Fix | Delete
'wpforms_admin_payments_views_overview_ajax_stats_column_clauses',
[426] Fix | Delete
[
[427] Fix | Delete
'total_payments' => "FORMAT({$default},0)",
[428] Fix | Delete
'total_sales' => 'IFNULL(SUM(total_amount),0)',
[429] Fix | Delete
'total_refunded' => 'IFNULL(SUM(pm.meta_value),0)',
[430] Fix | Delete
'total_subscription' => 'IFNULL(SUM(total_amount),0)',
[431] Fix | Delete
'total_renewal_subscription' => 'IFNULL(SUM(total_amount),0)',
[432] Fix | Delete
'total_coupons' => "FORMAT({$default},0)",
[433] Fix | Delete
]
[434] Fix | Delete
);
[435] Fix | Delete
[436] Fix | Delete
$clause = isset( $clauses[ $report ] ) ? $clauses[ $report ] : $default;
[437] Fix | Delete
[438] Fix | Delete
// Several stat cards might include the count of payment records.
[439] Fix | Delete
if ( $with_count ) {
[440] Fix | Delete
$clause = "CONCAT({$clause}, ' (', {$default}, ')')";
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
return $clause;
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
/**
[447] Fix | Delete
* Add join by meta table.
[448] Fix | Delete
*
[449] Fix | Delete
* @since 1.8.4
[450] Fix | Delete
*
[451] Fix | Delete
* @param string $report Stats card chart type (name). i.e. "total_payments".
[452] Fix | Delete
*
[453] Fix | Delete
* @return string
[454] Fix | Delete
*/
[455] Fix | Delete
private function add_join_by_meta( $report ) {
[456] Fix | Delete
[457] Fix | Delete
// Leave early if the meta key is empty.
[458] Fix | Delete
if ( ! isset( $this->stat_cards[ $report ]['meta_key'] ) ) {
[459] Fix | Delete
return '';
[460] Fix | Delete
}
[461] Fix | Delete
[462] Fix | Delete
// Retrieve the global database instance.
[463] Fix | Delete
global $wpdb;
[464] Fix | Delete
[465] Fix | Delete
// Retrieve the meta table name.
[466] Fix | Delete
$meta_table_name = wpforms()->get( 'payment_meta' )->table_name;
[467] Fix | Delete
[468] Fix | Delete
return $wpdb->prepare(
[469] Fix | Delete
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
[470] Fix | Delete
"LEFT JOIN {$meta_table_name} AS pm ON p.id = pm.payment_id AND pm.meta_key = %s",
[471] Fix | Delete
$this->stat_cards[ $report ]['meta_key']
[472] Fix | Delete
);
[473] Fix | Delete
}
[474] Fix | Delete
[475] Fix | Delete
/**
[476] Fix | Delete
* Modify arguments of secondary where clauses.
[477] Fix | Delete
*
[478] Fix | Delete
* @since 1.8.2
[479] Fix | Delete
*
[480] Fix | Delete
* @param array $args Query arguments.
[481] Fix | Delete
*
[482] Fix | Delete
* @return array
[483] Fix | Delete
*/
[484] Fix | Delete
public function modify_secondary_where_conditions_args( $args ) {
[485] Fix | Delete
[486] Fix | Delete
// Set a current mode.
[487] Fix | Delete
if ( ! isset( $args['mode'] ) ) {
[488] Fix | Delete
$args['mode'] = Page::get_mode();
[489] Fix | Delete
}
[490] Fix | Delete
[491] Fix | Delete
return $args;
[492] Fix | Delete
}
[493] Fix | Delete
[494] Fix | Delete
/**
[495] Fix | Delete
* Maybe format the amounts for the given stat cards.
[496] Fix | Delete
*
[497] Fix | Delete
* @since 1.8.4
[498] Fix | Delete
*
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function