Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/elemento.../modules/notifica...
File: api.php
<?php
[0] Fix | Delete
namespace Elementor\Modules\Notifications;
[1] Fix | Delete
[2] Fix | Delete
use Elementor\User;
[3] Fix | Delete
[4] Fix | Delete
class API {
[5] Fix | Delete
[6] Fix | Delete
const NOTIFICATIONS_URL = 'https://assets.elementor.com/notifications/v1/notifications.json';
[7] Fix | Delete
[8] Fix | Delete
public static function get_notifications_by_conditions( $force_request = false ) {
[9] Fix | Delete
$notifications = static::get_notifications( $force_request );
[10] Fix | Delete
[11] Fix | Delete
$filtered_notifications = [];
[12] Fix | Delete
[13] Fix | Delete
foreach ( $notifications as $notification ) {
[14] Fix | Delete
if ( empty( $notification['conditions'] ) ) {
[15] Fix | Delete
$filtered_notifications = static::add_to_array( $filtered_notifications, $notification );
[16] Fix | Delete
[17] Fix | Delete
continue;
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
if ( ! static::check_conditions( $notification['conditions'] ) ) {
[21] Fix | Delete
continue;
[22] Fix | Delete
}
[23] Fix | Delete
[24] Fix | Delete
$filtered_notifications = static::add_to_array( $filtered_notifications, $notification );
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
return $filtered_notifications;
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
private static function get_notifications( $force_request = false ) {
[31] Fix | Delete
$notifications = self::get_transient( '_elementor_notifications_data' );
[32] Fix | Delete
[33] Fix | Delete
if ( $force_request || false === $notifications ) {
[34] Fix | Delete
$notifications = static::fetch_data();
[35] Fix | Delete
[36] Fix | Delete
static::set_transient( '_elementor_notifications_data', $notifications, '+1 hour' );
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
$notifications = apply_filters( 'elementor/core/admin/notifications', $notifications );
[40] Fix | Delete
[41] Fix | Delete
return $notifications;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
private static function fetch_data(): array {
[45] Fix | Delete
$response = wp_remote_get( self::NOTIFICATIONS_URL );
[46] Fix | Delete
[47] Fix | Delete
if ( is_wp_error( $response ) ) {
[48] Fix | Delete
return [];
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
$data = json_decode( wp_remote_retrieve_body( $response ), true );
[52] Fix | Delete
[53] Fix | Delete
if ( empty( $data['notifications'] ) || ! is_array( $data['notifications'] ) ) {
[54] Fix | Delete
return [];
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
return $data['notifications'];
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
private static function add_to_array( $filtered_notifications, $notification ) {
[61] Fix | Delete
foreach ( $filtered_notifications as $filtered_notification ) {
[62] Fix | Delete
if ( $filtered_notification['id'] === $notification['id'] ) {
[63] Fix | Delete
return $filtered_notifications;
[64] Fix | Delete
}
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
$filtered_notifications[] = $notification;
[68] Fix | Delete
[69] Fix | Delete
return $filtered_notifications;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
private static function check_conditions( $groups ) {
[73] Fix | Delete
foreach ( $groups as $group ) {
[74] Fix | Delete
if ( static::check_group( $group ) ) {
[75] Fix | Delete
return true;
[76] Fix | Delete
}
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
return false;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
private static function check_group( $group ) {
[83] Fix | Delete
$is_or_relation = ! empty( $group['relation'] ) && 'OR' === $group['relation'];
[84] Fix | Delete
unset( $group['relation'] );
[85] Fix | Delete
$result = false;
[86] Fix | Delete
[87] Fix | Delete
foreach ( $group as $condition ) {
[88] Fix | Delete
// Reset results for each condition.
[89] Fix | Delete
$result = false;
[90] Fix | Delete
switch ( $condition['type'] ) {
[91] Fix | Delete
case 'wordpress': // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
[92] Fix | Delete
// include an unmodified $wp_version
[93] Fix | Delete
include ABSPATH . WPINC . '/version.php';
[94] Fix | Delete
$result = version_compare( $wp_version, $condition['version'], $condition['operator'] );
[95] Fix | Delete
break;
[96] Fix | Delete
case 'multisite':
[97] Fix | Delete
$result = is_multisite() === $condition['multisite'];
[98] Fix | Delete
break;
[99] Fix | Delete
case 'language':
[100] Fix | Delete
$in_array = in_array( get_locale(), $condition['languages'], true );
[101] Fix | Delete
$result = 'in' === $condition['operator'] ? $in_array : ! $in_array;
[102] Fix | Delete
break;
[103] Fix | Delete
case 'plugin':
[104] Fix | Delete
if ( ! function_exists( 'is_plugin_active' ) ) {
[105] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/plugin.php';
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
$is_plugin_active = is_plugin_active( $condition['plugin'] );
[109] Fix | Delete
[110] Fix | Delete
if ( empty( $condition['operator'] ) ) {
[111] Fix | Delete
$condition['operator'] = '==';
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
$result = '==' === $condition['operator'] ? $is_plugin_active : ! $is_plugin_active;
[115] Fix | Delete
break;
[116] Fix | Delete
case 'theme':
[117] Fix | Delete
$theme = wp_get_theme();
[118] Fix | Delete
if ( wp_get_theme()->parent() ) {
[119] Fix | Delete
$theme = wp_get_theme()->parent();
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
if ( $theme->get_template() === $condition['theme'] ) {
[123] Fix | Delete
$version = $theme->version;
[124] Fix | Delete
} else {
[125] Fix | Delete
$version = '';
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
$result = version_compare( $version, $condition['version'], $condition['operator'] );
[129] Fix | Delete
break;
[130] Fix | Delete
case 'introduction_meta':
[131] Fix | Delete
$result = User::get_introduction_meta( $condition['meta'] );
[132] Fix | Delete
break;
[133] Fix | Delete
[134] Fix | Delete
default:
[135] Fix | Delete
/**
[136] Fix | Delete
* Filters the notification condition, whether to check the group or not.
[137] Fix | Delete
*
[138] Fix | Delete
* The dynamic portion of the hook name, `$condition['type']`, refers to the condition type.
[139] Fix | Delete
*
[140] Fix | Delete
* @since 3.19.0
[141] Fix | Delete
*
[142] Fix | Delete
* @param bool $result Whether to check the group.
[143] Fix | Delete
* @param array $condition Notification condition.
[144] Fix | Delete
*/
[145] Fix | Delete
$result = apply_filters( "elementor/notifications/condition/{$condition['type']}", $result, $condition );
[146] Fix | Delete
break;
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
if ( ( $is_or_relation && $result ) || ( ! $is_or_relation && ! $result ) ) {
[150] Fix | Delete
return $result;
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
return $result;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
private static function get_transient( $cache_key ) {
[158] Fix | Delete
$cache = get_option( $cache_key );
[159] Fix | Delete
[160] Fix | Delete
if ( empty( $cache['timeout'] ) ) {
[161] Fix | Delete
return false;
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
if ( current_time( 'timestamp' ) > $cache['timeout'] ) {
[165] Fix | Delete
return false;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
return json_decode( $cache['value'], true );
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
private static function set_transient( $cache_key, $value, $expiration = '+12 hours' ) {
[172] Fix | Delete
$data = [
[173] Fix | Delete
'timeout' => strtotime( $expiration, current_time( 'timestamp' ) ),
[174] Fix | Delete
'value' => json_encode( $value ),
[175] Fix | Delete
];
[176] Fix | Delete
[177] Fix | Delete
return update_option( $cache_key, $data, false );
[178] Fix | Delete
}
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function