| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
/** |
| 6 |
* BeyondWords Bulk Edit. |
| 7 |
* |
| 8 |
* Text Domain: beyondwords |
| 9 |
* |
| 10 |
* @package Beyondwords\Wordpress |
| 11 |
* @author Stuart McAlpine <[email protected]> |
| 12 |
* @since 3.0.0 |
| 13 |
*/ |
| 14 |
|
| 15 |
namespace Beyondwords\Wordpress\Component\Posts\BulkEdit; |
| 16 |
|
| 17 |
use Beyondwords\Wordpress\Core\Core; |
| 18 |
use Beyondwords\Wordpress\Core\CoreUtils; |
| 19 |
use Beyondwords\Wordpress\Component\Settings\SettingsUtils; |
| 20 |
use Beyondwords\Wordpress\Plugin; |
| 21 |
|
| 22 |
/** |
| 23 |
* BulkEdit setup |
| 24 |
* |
| 25 |
* @since 4.5.0 |
| 26 |
*/ |
| 27 |
class Notices |
| 28 |
{ |
| 29 |
/** |
| 30 |
* Constructor |
| 31 |
*/ |
| 32 |
public function init() |
| 33 |
{ |
| 34 |
add_action('admin_notices', array($this, 'generatedNotice')); |
| 35 |
add_action('admin_notices', array($this, 'deletedNotice')); |
| 36 |
add_action('admin_notices', array($this, 'failedNotice')); |
| 37 |
add_action('admin_notices', array($this, 'errorNotice')); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* @since 4.1.0 |
| 42 |
*/ |
| 43 |
public function generatedNotice() |
| 44 |
{ |
| 45 |
if (! isset($_GET['beyondwords_bulk_edit_result_nonce'])) { |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
if (! wp_verify_nonce(sanitize_text_field($_GET['beyondwords_bulk_edit_result_nonce']), 'beyondwords_bulk_edit_result')) { // phpcs:ignore Generic.Files.LineLength.TooLong |
| 50 |
wp_nonce_ays(''); |
| 51 |
} |
| 52 |
|
| 53 |
$count = intval(sanitize_text_field($_GET['beyondwords_bulk_generated'] ?? '')); |
| 54 |
|
| 55 |
if ($count) { |
| 56 |
$message = sprintf( |
| 57 |
/* translators: %d is replaced with the number of posts processed */ |
| 58 |
_n( |
| 59 |
'Audio was requested for %d post.', |
| 60 |
'Audio was requested for %d posts.', |
| 61 |
$count, |
| 62 |
'speechkit' |
| 63 |
), |
| 64 |
$count |
| 65 |
); |
| 66 |
?> |
| 67 |
<div id="beyondwords-bulk-edit-notice-generated" class="notice notice-info is-dismissible"> |
| 68 |
<p> |
| 69 |
<?php echo esc_html($message); ?> |
| 70 |
</p> |
| 71 |
</div> |
| 72 |
<?php |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* |
| 78 |
*/ |
| 79 |
public function deletedNotice() |
| 80 |
{ |
| 81 |
if (! isset($_GET['beyondwords_bulk_edit_result_nonce'])) { |
| 82 |
return; |
| 83 |
} |
| 84 |
|
| 85 |
if (! wp_verify_nonce(sanitize_text_field($_GET['beyondwords_bulk_edit_result_nonce']), 'beyondwords_bulk_edit_result')) { // phpcs:ignore Generic.Files.LineLength.TooLong |
| 86 |
wp_nonce_ays(''); |
| 87 |
} |
| 88 |
|
| 89 |
$count = intval(sanitize_text_field($_GET['beyondwords_bulk_deleted'] ?? '')); |
| 90 |
|
| 91 |
if ($count) { |
| 92 |
$message = sprintf( |
| 93 |
/* translators: %d is replaced with the number of posts processed */ |
| 94 |
_n( |
| 95 |
'Audio was deleted for %d post.', |
| 96 |
'Audio was deleted for %d posts.', |
| 97 |
$count, |
| 98 |
'speechkit' |
| 99 |
), |
| 100 |
$count |
| 101 |
); |
| 102 |
?> |
| 103 |
<div id="beyondwords-bulk-edit-notice-deleted" class="notice notice-info is-dismissible"> |
| 104 |
<p> |
| 105 |
<?php echo esc_html($message); ?> |
| 106 |
</p> |
| 107 |
</div> |
| 108 |
<?php |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* |
| 114 |
*/ |
| 115 |
public function failedNotice() |
| 116 |
{ |
| 117 |
if (! isset($_GET['beyondwords_bulk_edit_result_nonce'])) { |
| 118 |
return; |
| 119 |
} |
| 120 |
|
| 121 |
if (! wp_verify_nonce(sanitize_text_field($_GET['beyondwords_bulk_edit_result_nonce']), 'beyondwords_bulk_edit_result')) { // phpcs:ignore Generic.Files.LineLength.TooLong |
| 122 |
wp_nonce_ays(''); |
| 123 |
} |
| 124 |
|
| 125 |
$count = intval(sanitize_text_field($_GET['beyondwords_bulk_failed'] ?? '')); |
| 126 |
|
| 127 |
if ($count) { |
| 128 |
$message = sprintf( |
| 129 |
/* translators: %d is replaced with the number of posts that were skipped */ |
| 130 |
_n( |
| 131 |
'%d post failed, check for errors in the BeyondWords column below.', |
| 132 |
'%d posts failed, check for errors in the BeyondWords column below.', |
| 133 |
$count, |
| 134 |
'speechkit' |
| 135 |
), |
| 136 |
$count |
| 137 |
); |
| 138 |
?> |
| 139 |
<div id="beyondwords-bulk-edit-notice-failed" class="notice notice-error is-dismissible"> |
| 140 |
<p> |
| 141 |
<?php echo esc_html($message); ?> |
| 142 |
</p> |
| 143 |
</div> |
| 144 |
<?php |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* |
| 150 |
*/ |
| 151 |
public function errorNotice() |
| 152 |
{ |
| 153 |
if (! isset($_GET['beyondwords_bulk_edit_result_nonce'])) { |
| 154 |
return; |
| 155 |
} |
| 156 |
|
| 157 |
if (! wp_verify_nonce(sanitize_text_field($_GET['beyondwords_bulk_edit_result_nonce']), 'beyondwords_bulk_edit_result')) { // phpcs:ignore Generic.Files.LineLength.TooLong |
| 158 |
wp_nonce_ays(''); |
| 159 |
} |
| 160 |
|
| 161 |
$message = sanitize_text_field($_GET['beyondwords_bulk_error'] ?? ''); |
| 162 |
|
| 163 |
if ($message) { |
| 164 |
?> |
| 165 |
<div id="beyondwords-bulk-edit-notice-error" class="notice notice-error is-dismissible"> |
| 166 |
<p> |
| 167 |
<?php echo esc_html($message); ?> |
| 168 |
</p> |
| 169 |
</div> |
| 170 |
<?php |
| 171 |
} |
| 172 |
} |
| 173 |
} |
| 174 |
|