Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/seo-by-rank-math/includes/class-update-email.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* Code related to the update notification emails.
4
+
*
5
+
* @since 1.0.57
6
+
* @package RankMath
7
+
* @subpackage RankMath\Core
8
+
* @author Rank Math <support@rankmath.com>
9
+
*/
10
+
11
+
namespace RankMath;
12
+
13
+
use RankMath\KB;
14
+
use RankMath\Traits\Hooker;
15
+
use RankMath\Helper;
16
+
17
+
defined( 'ABSPATH' ) || exit;
18
+
19
+
/**
20
+
* Common class.
21
+
*/
22
+
class Update_Email {
23
+
24
+
use Hooker;
25
+
26
+
/**
27
+
* Constructor method.
28
+
*/
29
+
public function __construct() {
30
+
$this->filter( 'pre_set_site_transient_update_plugins', 'maybe_send_update_notification_email', 130 );
31
+
}
32
+
33
+
/**
34
+
* Maybe send the update notification email to the administrator if the setting is turned on.
35
+
*
36
+
* @param mixed $transient update_plugins site transient value.
37
+
* @return mixed
38
+
*/
39
+
public function maybe_send_update_notification_email( $transient ) {
40
+
if ( ! Helper::get_settings( 'general.update_notification_email' ) ) {
41
+
return $transient;
42
+
}
43
+
44
+
$should_send = $this->do_filter( 'admin/should_send_update_notification', $this->should_send_email( $transient ), $transient );
45
+
if ( ! $should_send ) {
46
+
return $transient;
47
+
}
48
+
49
+
$to = get_site_option( 'admin_email' );
50
+
51
+
// Translators: placeholder is the site title.
52
+
$subject = __( '[%s] An update is available for Rank Math', 'rank-math' );
53
+
$subject = sprintf( $subject, wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) );
54
+
55
+
$body = [];
56
+
$body[] = __( 'Hello,', 'rank-math' ) . "\n";
57
+
58
+
// Translators: placeholder is the site URL.
59
+
$body[] = sprintf( __( 'This is an automated email to let you know that there is an update available for the Rank Math SEO plugin installed on: %s', 'rank-math' ), get_home_url() ) . "\n";
60
+
61
+
$products = $this->do_filter( 'admin/update_notification_products', $this->get_updatable_products( $transient ), $transient );
62
+
$list = $this->get_products_list( $products );
63
+
$body[] = $list;
64
+
65
+
// Translators: placeholder is the new admin page URL.
66
+
$body[] = sprintf( __( 'To ensure your site is always on the latest, most up-to-date version of Rank Math - we recommend logging into the admin area to update the plugin as soon as possible: %s', 'rank-math' ), admin_url( 'update-core.php' ) ) . "\n";
67
+
68
+
// Add a note about the support forums.
69
+
$body[] = __( 'If you have any questions or experience any issues – our support team is at your disposal:', 'rank-math' );
70
+
$body[] = __( 'https://support.rankmath.com/', 'rank-math' );
71
+
$body[] = "\n" . '-';
72
+
$body[] = __( 'Rank Math Team', 'rank-math' );
73
+
74
+
$body = implode( "\n", $body );
75
+
76
+
$headers = '';
77
+
78
+
$email = compact( 'to', 'subject', 'body', 'headers' );
79
+
$email = $this->do_filter( 'admin/update_notification_email', $email );
80
+
81
+
$result = wp_mail( $email['to'], $email['subject'], $email['body'], $email['headers'] );
82
+
83
+
$stored = get_option( 'rank_math_update_notifications_sent', [] );
84
+
$new_opt = $stored;
85
+
foreach ( $products as $key => $value ) {
86
+
$new_opt[ $key ] = $value;
87
+
}
88
+
update_option( 'rank_math_update_notifications_sent', $new_opt, false );
89
+
90
+
return $transient;
91
+
}
92
+
93
+
/**
94
+
* Check if we should send an update email or not, based on the update_plugins transient value.
95
+
*
96
+
* @param mixed $transient Transient value.
97
+
* @return boolean
98
+
*/
99
+
public function should_send_email( $transient ) {
100
+
// No need to send email if auto-update is enabled.
101
+
if ( Helper::get_auto_update_setting() ) {
102
+
return false;
103
+
}
104
+
105
+
if ( ! is_object( $transient )
106
+
|| empty( $transient->response )
107
+
|| empty( $transient->response['seo-by-rank-math/rank-math.php'] )
108
+
|| empty( $transient->response['seo-by-rank-math/rank-math.php']->new_version )
109
+
) {
110
+
return false;
111
+
}
112
+
113
+
$new_version = $transient->response['seo-by-rank-math/rank-math.php']->new_version;
114
+
115
+
// Now let's check if we've already sent this email.
116
+
$sent = get_option( 'rank_math_update_notifications_sent', [ 'free' => [ 'new_version' => '1.0' ] ] );
117
+
if ( ! isset( $sent['free'] ) ) {
118
+
$sent['free'] = [ 'new_version' => '1.0' ];
119
+
}
120
+
if ( version_compare( $sent['free']['new_version'], $new_version, '>=' ) ) {
121
+
return false;
122
+
}
123
+
124
+
return true;
125
+
}
126
+
127
+
/**
128
+
* Get list of updatable products and their data.
129
+
*
130
+
* @param mixed $transient The update_plugins transient value.
131
+
* @return array
132
+
*/
133
+
public function get_updatable_products( $transient ) {
134
+
if ( ! $this->should_send_email( $transient ) ) {
135
+
return [];
136
+
}
137
+
138
+
$old_version = rank_math()->version;
139
+
$new_version = $transient->response['seo-by-rank-math/rank-math.php']->new_version;
140
+
141
+
$products = [
142
+
'free' => [
143
+
'name' => __( 'Rank Math Free', 'rank-math' ),
144
+
'old_version' => $old_version,
145
+
'new_version' => $new_version,
146
+
'changelog' => KB::get( 'changelog-free', 'Changelog Update notification mail' ),
147
+
],
148
+
];
149
+
150
+
return $products;
151
+
}
152
+
153
+
/**
154
+
* Turn products array into a human-readable list.
155
+
*
156
+
* @param array $products_array Products array.
157
+
* @return string
158
+
*/
159
+
public function get_products_list( $products_array ) {
160
+
$list = '';
161
+
162
+
foreach ( $products_array as $product_data ) {
163
+
// Translators: placeholders are the old and new version numbers.
164
+
$list .= sprintf( __( '%1$s: Old %2$s -> New %3$s | Changelog: %4$s', 'rank-math' ), $product_data['name'], $product_data['old_version'], $product_data['new_version'], $product_data['changelog'] ) . "\n";
165
+
}
166
+
167
+
return $list;
168
+
}
169
+
}
170
+