Skip to content

Commit 898bf5c

Browse files
committed
Add v5 notices
1 parent 3dd499f commit 898bf5c

File tree

7 files changed

+218
-94
lines changed

7 files changed

+218
-94
lines changed

css/admin-general-styles.css

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -339,40 +339,50 @@ label[for='wpra-dl-guide-email-field'] {
339339
margin-top: 5px;
340340
}
341341

342-
.wpra-php-notice {
342+
.wpra-v5-notice {
343343
position: relative;
344344
display: flex;
345345
flex-direction: row;
346346
align-items: stretch;
347-
border: 1px solid #FF792B;
348-
border-left-width: 4px;
347+
border: 1px solid #CCCCCC;
348+
border-left: 4px solid #FF792B;
349349
padding: 0 !important;
350350
}
351351

352-
.wpra-php-notice .wpra-php-notice-left {
352+
.wpra-v5-notice .wpra-v5-notice-left {
353353
flex: 0 1;
354354
display: flex;
355355
flex-direction: column;
356356
justify-items: center;
357357
align-items: center;
358-
padding: 14px 13px;
359-
background-color: rgba(255, 121, 43, .1);
358+
padding: 18px 8px;
359+
background-color: #F6F7FB;
360360
}
361361

362-
.wpra-php-notice .wpra-php-notice-right {
362+
.wpra-v5-notice .wpra-v5-notice-right {
363363
flex: 1;
364364
display: flex;
365365
flex-direction: column;
366-
gap: 10px;
367-
padding: 20px;
366+
gap: 4px;
367+
padding: 18px 24px;
368+
}
369+
370+
.wpra-v5-notice .wpra-v5-notice-right h3 {
371+
font-size: 16px;
372+
line-height: 24px;
373+
}
374+
375+
.wpra-v5-notice .wpra-v5-notice-right p {
376+
font-size: 13px;
377+
line-height: 16px;
368378
}
369379

370-
.wpra-php-notice .wpra-php-notice-right h3,
371-
.wpra-php-notice .wpra-php-notice-right p {
380+
.wpra-v5-notice .wpra-v5-notice-right h3,
381+
.wpra-v5-notice .wpra-v5-notice-right p {
372382
margin: 0 !important;
373383
}
374384

375-
button.wpra-php-notice-close {
385+
button.wpra-v5-notice-close {
376386
all: unset;
377387
appearance: none;
378388
position: absolute;
@@ -381,6 +391,6 @@ button.wpra-php-notice-close {
381391
cursor: pointer;
382392
}
383393

384-
button.wpra-php-notice-close:focus-visible {
394+
button.wpra-v5-notice-close:focus-visible {
385395
outline: 2px dotted #000;
386396
}

includes/php-v5-notice.php

Lines changed: 0 additions & 53 deletions
This file was deleted.

includes/v5-notices.php

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<?php
2+
3+
add_action('admin_notices', function () {
4+
if (wprss_v5_is_available()) {
5+
wprss_v5_available_notice();
6+
} else {
7+
wprss_v5_coming_soon_notice();
8+
}
9+
});
10+
11+
add_action('wp_ajax_wprss_dismiss_v5_notice', function () {
12+
$nonce = $_REQUEST['nonce'];
13+
$nonceOk = wp_verify_nonce($nonce, 'wpra-dismiss-v5-notice');
14+
if (!$nonceOk) {
15+
die('Not allowed');
16+
}
17+
18+
$noticeId = trim($_REQUEST['notice'] ?? '');
19+
if (empty($noticeId)) {
20+
die('Empty notice ID');
21+
}
22+
23+
switch ($noticeId) {
24+
case 'wprss_v5_coming_soon':
25+
update_option('wprss_v5_coming_notice_dismissed', '1');
26+
break;
27+
case 'wprss_v5_available':
28+
update_option('wprss_v5_available_dismissed', '1');
29+
break;
30+
default:
31+
die('Invalid notice ID');
32+
}
33+
34+
die("OK");
35+
});
36+
37+
add_filter('in_plugin_update_message-wp-rss-aggregator/wp-rss-aggregator.php', function () {
38+
?>
39+
<br>
40+
<span style="line-height: 24px;">
41+
<span style="display: inline-block; width: 24px;"></span>
42+
<b><?= __('Note:') ?></b>
43+
<span>
44+
<?= __('This is a major update. Prior testing on a staging site is strongly recommended.', 'wprss') ?>
45+
</span>
46+
</span>
47+
<?php
48+
});
49+
50+
add_filter('site_transient_update_plugins', function ($updates) {
51+
if (!wprss_v5_contains_update($updates)) {
52+
return $updates;
53+
}
54+
55+
$msg = __('This is a major update. Prior testing on a staging site is strongly recommended.', 'wprss');
56+
57+
$basename = plugin_basename(WPRSS_FILE_CONSTANT);
58+
$updates->response[$basename]->upgrade_notice = $msg;
59+
60+
return $updates;
61+
});
62+
63+
function wprss_v5_is_available()
64+
{
65+
$updates = get_site_transient('update_plugins');
66+
return wprss_v5_contains_update($updates);
67+
}
68+
69+
function wprss_v5_contains_update($updates)
70+
{
71+
$basename = plugin_basename(WPRSS_FILE_CONSTANT);
72+
if (!is_object($updates) && !isset($updates->response[$basename])) {
73+
return false;
74+
}
75+
76+
$wprssUpdate = $updates->response[$basename] ?? null;
77+
78+
if (!is_object($wprssUpdate) || !isset($wprssUpdate->new_version)) {
79+
return false;
80+
}
81+
82+
if (version_compare($wprssUpdate->new_version, '5.0', '<')) {
83+
return false;
84+
}
85+
86+
return true;
87+
}
88+
89+
function wprss_v5_coming_soon_notice()
90+
{
91+
$dismissed = get_option('wprss_v5_coming_notice_dismissed', '0');
92+
$dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN);
93+
if ($dismissed) {
94+
return;
95+
}
96+
97+
echo wprss_v5_notice_render(
98+
'wprss_v5_coming_soon',
99+
__('Exciting news for Aggregator!', 'wprss'),
100+
sprintf(
101+
_x(
102+
'Our highly-anticipated update is coming soon. This major update will require your website to be running PHP 7.4 or higher. To learn more about v5.0 %s',
103+
'%s = "click here" link',
104+
'wprss'
105+
),
106+
sprintf(
107+
'<a href="%s" target="_blank">%s</a>',
108+
'https://www.wprssaggregator.com/v5-update/',
109+
__('click here', 'wprss'),
110+
)
111+
),
112+
);
113+
}
114+
115+
function wprss_v5_available_notice()
116+
{
117+
$dismissed = get_option('wprss_v5_available_dismissed', '0');
118+
$dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN);
119+
if ($dismissed) {
120+
return;
121+
}
122+
123+
echo wprss_v5_notice_render(
124+
'wprss_v5_available',
125+
__('A major update of Aggregator is available.', 'wprss'),
126+
sprintf(
127+
_x(
128+
'%s to get access to the new and improved aggregator.',
129+
'%s = "Update" link',
130+
'wprss'
131+
),
132+
sprintf(
133+
'<a href="%s">%s</a>',
134+
admin_url('update-core.php'),
135+
__('Update', 'wprss'),
136+
)
137+
),
138+
);
139+
}
140+
141+
function wprss_v5_notice_render($id, $title, $content)
142+
{
143+
$icon = WPRSS_IMG . 'wpra-icon-transparent-new.png';
144+
$nonce = wp_create_nonce('wpra-dismiss-v5-notice');
145+
146+
ob_start();
147+
?>
148+
<div id="<?= esc_attr($id) ?>" class="notice wpra-v5-notice" data-notice-id="<?= esc_attr($id) ?>">
149+
<input type="hidden" class="wpra-v5-notice-nonce" value="<?= esc_attr($nonce) ?>" />
150+
151+
<div class="wpra-v5-notice-left">
152+
<img src="<?= esc_attr($icon) ?>" style="width: 32px !important" alt="WP RSS Aggregator" />
153+
</div>
154+
<div class="wpra-v5-notice-right">
155+
<h3><?= $title ?></h3>
156+
<p>
157+
<?= $content ?>
158+
</p>
159+
</div>
160+
<button class="wpra-v5-notice-close">
161+
<span class="dashicons dashicons-no-alt" />
162+
</button>
163+
</div>
164+
<?php
165+
166+
return ob_get_clean();
167+
}

js/admin-addon-ajax.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,4 @@ jQuery( document ).ready( function($) {
2525
$(this).text( wprss_admin_addon_ajax.please_wait );
2626
}
2727
});
28-
29-
$(".wpra-php-notice-close").click(function() {
30-
const notice = $(this).closest(".wpra-php-notice");
31-
const nonce = notice.find(".wpra-php-notice-nonce").val();
32-
33-
$.ajax({
34-
url: ajaxurl,
35-
type: "POST",
36-
data: {
37-
action: "wprss_dismiss_php_notice",
38-
nonce: nonce
39-
},
40-
success: function(data) {
41-
if (data === "OK") {
42-
notice.slideUp("fast", function() {
43-
notice.remove();
44-
});
45-
}
46-
}
47-
});
48-
});
4928
});

js/admin-notifications.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,32 @@
33
* Depends on Aventura.Wp.Admin.Notices.
44
*/
55

6-
;(function($, window, document, undefined) {
6+
(function($) {
77
var globalVars = adminNoticeGlobalVars || {};
88
var notices = Aventura.Wp.Admin.Notices.getGlobal();
9-
notices.setOptions(globalVars)
10-
.setOptions('ajax_url', ajaxurl);
9+
notices.setOptions(globalVars).setOptions("ajax_url", ajaxurl);
1110
notices.attach();
12-
})(jQuery, top, document);
11+
12+
$(".wpra-v5-notice-close").click(function() {
13+
const noticeEl = $(this).closest(".wpra-v5-notice");
14+
const noticeId = noticeEl.data("notice-id");
15+
const nonce = noticeEl.find(".wpra-v5-notice-nonce").val();
16+
17+
$.ajax({
18+
url: ajaxurl,
19+
type: "POST",
20+
data: {
21+
action: "wprss_dismiss_v5_notice",
22+
nonce: nonce,
23+
notice: noticeId
24+
},
25+
success: function(data) {
26+
if (data === "OK") {
27+
noticeEl.slideUp("fast", function() {
28+
noticeEl.remove();
29+
});
30+
}
31+
}
32+
});
33+
});
34+
})(jQuery);

js/admin-notifications.min.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wp-rss-aggregator.php

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@
330330
require_once ( WPRSS_INC . 'templates-update.php' );
331331

332332
/* Load the notice for the PHP version upgrade that is coming in v5. */
333-
require_once ( WPRSS_INC . 'php-v5-notice.php' );
333+
require_once ( WPRSS_INC . 'v5-notices.php' );
334334

335335
register_activation_hook(__FILE__, 'wprss_activate');
336336
register_deactivation_hook(__FILE__, 'wprss_deactivate');

0 commit comments

Comments
 (0)