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