Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/paid-memberships-pro/includes/updates.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/* This file contains functions used to process required database updates sometimes logged after PMPro is upgraded. */
3
+
4
+
/*
5
+
Is there an update?
6
+
*/
7
+
function pmpro_isUpdateRequired() {
8
+
$updates = get_option('pmpro_updates', array());
9
+
return(!empty($updates));
10
+
}
11
+
12
+
/**
13
+
* Update option to require an update.
14
+
* @param string $update
15
+
*
16
+
* @since 1.8.7
17
+
*/
18
+
function pmpro_addUpdate($update) {
19
+
$updates = get_option('pmpro_updates', array());
20
+
$updates[] = $update;
21
+
$updates = array_values(array_unique($updates));
22
+
23
+
update_option('pmpro_updates', $updates, 'no');
24
+
}
25
+
26
+
/**
27
+
* Update option to remove an update.
28
+
* @param string $update
29
+
*
30
+
* @since 1.8.7
31
+
*/
32
+
function pmpro_removeUpdate($update) {
33
+
$updates = get_option('pmpro_updates', array());
34
+
$key = array_search($update,$updates);
35
+
if($key!==false){
36
+
unset($updates[$key]);
37
+
}
38
+
39
+
$updates = array_values($updates);
40
+
41
+
update_option('pmpro_updates', $updates, 'no');
42
+
}
43
+
44
+
/*
45
+
Enqueue updates.js if needed
46
+
*/
47
+
function pmpro_enqueue_update_js() {
48
+
if(!empty($_REQUEST['page']) && $_REQUEST['page'] == 'pmpro-updates') {
49
+
wp_enqueue_script( 'pmpro-updates', plugin_dir_url( dirname(__FILE__) ) . 'js/updates.js', array('jquery'), PMPRO_VERSION );
50
+
}
51
+
}
52
+
add_action('admin_enqueue_scripts', 'pmpro_enqueue_update_js');
53
+
54
+
/*
55
+
Load an update via AJAX
56
+
*/
57
+
function pmpro_wp_ajax_pmpro_updates() {
58
+
//get updates
59
+
$updates = array_values(get_option('pmpro_updates', array()));
60
+
61
+
//run update or let them know we're done
62
+
if(!empty($updates)) {
63
+
//get the latest one and run it
64
+
if(function_exists($updates[0]))
65
+
call_user_func($updates[0]);
66
+
else
67
+
echo "[error] Function not found: " . esc_html( $updates[0] );
68
+
echo ". ";
69
+
} else {
70
+
echo "[done]";
71
+
}
72
+
73
+
//reset this transient so we know AJAX is running
74
+
set_transient('pmpro_updates_first_load', false, 60*60*24);
75
+
76
+
//show progress
77
+
global $pmpro_updates_progress;
78
+
if(!empty($pmpro_updates_progress))
79
+
echo esc_html( $pmpro_updates_progress );
80
+
81
+
exit;
82
+
}
83
+
add_action('wp_ajax_pmpro_updates', 'pmpro_wp_ajax_pmpro_updates');
84
+
85
+
/*
86
+
Redirect away from updates page if there are no updates
87
+
*/
88
+
function pmpro_admin_init_updates_redirect() {
89
+
if(is_admin() && !empty($_REQUEST['page']) && $_REQUEST['page'] == 'pmpro-updates' && !pmpro_isUpdateRequired()) {
90
+
wp_redirect(admin_url('admin.php?page=pmpro-membershiplevels&updatescomplete=1'));
91
+
exit;
92
+
}
93
+
}
94
+
add_action('init', 'pmpro_admin_init_updates_redirect');
95
+
96
+
/*
97
+
Show admin notice if an update is required and not already on the updates page.
98
+
*/
99
+
if(pmpro_isUpdateRequired() && (empty($_REQUEST['page']) || $_REQUEST['page'] != 'pmpro-updates'))
100
+
add_action('admin_notices', 'pmpro_updates_notice');
101
+
102
+
/*
103
+
Function to show an admin notice linking to the updates page.
104
+
*/
105
+
function pmpro_updates_notice() {
106
+
?>
107
+
<div class="update-nag notice notice-warning inline">
108
+
<?php
109
+
echo esc_html__( 'Paid Memberships Pro Data Update Required', 'paid-memberships-pro' ) . '. ';
110
+
/* translators: %s: URL to the updates page. */
111
+
echo wp_kses_post( sprintf(__( '(1) <a target="_blank" href="%s">Backup your WordPress database</a></strong> and then (2) <a href="%s">click here to start the update</a>.', 'paid-memberships-pro' ), esc_url( 'https://www.paidmembershipspro.com/backup-wordpress-site/?utm_source=plugin&utm_medium=pmpro-admin-header&utm_campaign=blog&utm_content=backup-notification' ), admin_url('admin.php?page=pmpro-updates')));
112
+
?>
113
+
</div>
114
+
<?php
115
+
}
116
+
117
+
/*
118
+
Show admin notice when updates are complete.
119
+
*/
120
+
if(is_admin() && !empty($_REQUEST['updatescomplete']))
121
+
add_action('admin_notices', 'pmpro_updates_notice_complete');
122
+
123
+
/*
124
+
Function to show an admin notice linking to the updates page.
125
+
*/
126
+
function pmpro_updates_notice_complete() {
127
+
?>
128
+
<div class="updated notice notice-success is-dismissible">
129
+
<p>
130
+
<?php
131
+
esc_html_e('All Paid Memberships Pro updates have finished.', 'paid-memberships-pro' );
132
+
?>
133
+
</p>
134
+
</div>
135
+
<?php
136
+
}
137
+
138
+
/**
139
+
* If there is an upgrade notice for updating PMPro to the latest version, show it.
140
+
*
141
+
* @since 2.9
142
+
*
143
+
* @param array $current_plugin_data {
144
+
* An array of plugin metadata.
145
+
*
146
+
* @type string $name The human-readable name of the plugin.
147
+
* @type string $plugin_uri Plugin URI.
148
+
* @type string $version Plugin version.
149
+
* @type string $description Plugin description.
150
+
* @type string $author Plugin author.
151
+
* @type string $author_uri Plugin author URI.
152
+
* @type string $text_domain Plugin text domain.
153
+
* @type string $domain_path Relative path to the plugin's .mo file(s).
154
+
* @type bool $network Whether the plugin can only be activated network wide.
155
+
* @type string $title The human-readable title of the plugin.
156
+
* @type string $author_name Plugin author's name.
157
+
* @type bool $update Whether there's an available update. Default null.
158
+
* }
159
+
* @param array $update_data {
160
+
* An array of metadata about the available plugin update.
161
+
*
162
+
* @type int $id Plugin ID.
163
+
* @type string $slug Plugin slug.
164
+
* @type string $new_version New plugin version.
165
+
* @type string $url Plugin URL.
166
+
* @type string $package Plugin update package URL.
167
+
* }
168
+
*/
169
+
function pmpro_maybe_show_upgrade_notices( $current_plugin_data, $update_data ) {
170
+
if ( isset( $update_data->upgrade_notice ) && strlen( trim( $update_data->upgrade_notice ) ) > 0 ) {
171
+
echo '<p class="pmpro_plugin_update_notice"><strong>' . esc_html__( 'Important Upgrade Notice', 'paid-memberships-pro' ) . ':</strong> ' . esc_html( strip_tags( $update_data->upgrade_notice ) ) . '</p>';
172
+
173
+
}
174
+
}
175
+
$pmpro_path_from_plugins_dir_arr = explode( '/wp-content/plugins/', PMPRO_BASE_FILE );
176
+
if ( ! empty( $pmpro_path_from_plugins_dir_arr ) ) {
177
+
add_action( 'in_plugin_update_message-' . end( $pmpro_path_from_plugins_dir_arr ), 'pmpro_maybe_show_upgrade_notices', 10, 2 );
178
+
}
179
+