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