* @return array
*/
private function get_calculation_overview( $entries ): array {
// Check if the entries array is empty.
if ( empty( $entries ) ) {
return [];
}
// Get the sum of 'count' index in all entries.
$sum_current = array_sum( array_column( $entries, 'count' ) );
// Choose a specific 'form_id' to check if 'count_previous_week' index exists.
$sample_form_id = key( $entries );
// Check if 'count_previous_week' index doesn't exist and return early.
if ( ! isset( $entries[ $sample_form_id ]['count_previous_week'] ) ) {
return [];
}
// Get the sum of 'count_previous_week' index in all entries.
$sum_previous_week = array_sum( array_column( $entries, 'count_previous_week' ) );
// Check if the sum of counts from the previous week is 0.
// If so, return the sum of counts from the current week and trends as "+100%".
if ( $sum_previous_week === 0 ) {
return [
'total' => $sum_current,
'trends' => $this->format_trends_for_display( $sum_current === 0 ? 0 : 100 ),
];
}
// Calculate trends based on the sum of counts from the current week and the previous week.
$trends = round( ( $sum_current - $sum_previous_week ) / $sum_previous_week * 100 );
// Return an array with the total and trends.
return [
'total' => $sum_current,
'trends' => $this->format_trends_for_display( $trends ),
];
}
/**
* Register Action Scheduler task to fetch and cache Info Blocks.
*
* @since 1.6.4
*
* @param \WPForms\Tasks\Task[] $tasks List of task classes.
*
* @return array
*/
public static function register_fetch_info_blocks_task( $tasks ): array {
$tasks[] = FetchInfoBlocksTask::class;
return $tasks;
}
/**
* Deregister Action Scheduler task to fetch and cache Info Blocks.
*
* @since 1.6.4
*/
public function deregister_fetch_info_blocks_task() {
if ( ! $this->is_disabled() ) {
return;
}
// Deregister the task.
( new FetchInfoBlocksTask() )->cancel();
// Delete last run time record.
delete_option( FetchInfoBlocksTask::LAST_RUN );
// Remove the cache file if it exists.
$file_name = ( new InfoBlocks() )->get_cache_file_path();
if ( file_exists( $file_name ) ) {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.unlink_unlink
@unlink( $file_name );
}
}
/**
* Check if the current request is a preview for the summaries email template.
*
* @since 1.8.8
*
* @return bool
*/
private function is_preview(): bool {
// Leave if the current user can't access.
if ( ! wpforms_current_user_can() ) {
return false;
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
// Leave early if nonce verification failed.
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), Preview::PREVIEW_NONCE_NAME ) ) {
return false;
}
// Leave early if preview is not requested.
if ( ! isset( $_GET['wpforms_email_preview'], $_GET['wpforms_email_template'] ) ) {
return false;
}
// Leave early if preview is not requested for the summaries template.
if ( $_GET['wpforms_email_template'] !== 'summary' ) {
return false;
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
return true;
}
/**
* Format entries trends for display.
*
* This function takes an array of entries and formats the 'trends' value for display.
*
* @since 1.8.8
*
* @param array|int $input Input data to format.
*
* @return array|string
*/
private function format_trends_for_display( $input ) {
// If input is a numeric value, format and return it.
if ( is_numeric( $input ) ) {
return sprintf( '%s%s%%', $input >= 0 ? '+' : '', $input );
}
// Loop through entries and format 'trends' values.
foreach ( $input as &$form ) {
// Leave early if 'trends' index doesn't exist.
if ( ! isset( $form['trends'] ) ) {
continue;
}
// Add percent sign to trends and + sign if value greater than zero.
$form['trends'] = sprintf( '%s%s%%', $form['trends'] >= 0 ? '+' : '', $form['trends'] );
}
return $input;
}
/**
* Check if trends can be displayed for the given entries.
*
* @since 1.8.8
*
* @param array $entries The entries data.
*
* @return bool
*/
private function entries_has_trends( array $entries ): bool {
// Return false if entries array is empty.
if ( empty( $entries ) ) {
return false;
}
// Check if at least one array item has the 'trends' key.
foreach ( $entries as $entry ) {
if ( isset( $entry['trends'] ) ) {
return true;
}
}
return false;
}
/**
* Get icons URL.
* Primarily used in the HTML version of the email template.
*
* @since 1.8.8
*
* @return array
*/
private function get_icons_url(): array {
$base_url = WPFORMS_PLUGIN_URL . 'assets/images/email/';
return [
'overview' => $base_url . 'icon-overview.png',
'upward' => $base_url . 'icon-upward.png',
'downward' => $base_url . 'icon-downward.png',
'notification_block' => $base_url . 'notification-block-icon.png',
'info_block' => $base_url . 'info-block-icon.png',
];
}
}
Fatal error: Uncaught Error: Class 'WPForms\Emails\Summaries' not found in /home/tourismg/public_html/wp-content/plugins/wpforms-lite/src/Lite/Emails/Summaries.php:12
Stack trace:
#0 /home/tourismg/public_html/wp-content/plugins/one-click-demo-import/vendor/composer/ClassLoader.php(444): include()
#1 /home/tourismg/public_html/wp-content/plugins/one-click-demo-import/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile()
#2 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#3 [internal function]: spl_autoload_call()
#4 /home/tourismg/public_html/wp-content/plugins/wpforms-lite/src/WPForms.php(305): class_exists()
#5 /home/tourismg/public_html/wp-content/plugins/wpforms-lite/src/WPForms.php(365): WPForms\WPForms->register()
#6 /home/tourismg/public_html/wp-content/plugins/wpforms-lite/src/Loader.php(30): WPForms\WPForms->register_bulk()
#7 /home/tourismg/public_html/wp-content/plugins/wpforms-lite/src/WPForms.php(325): WPForms\Loader->init()
#8 /home/tourismg/public_html/wp-content/plugins/wpfo in /home/tourismg/public_html/wp-content/plugins/wpforms-lite/src/Lite/Emails/Summaries.php on line 12