Plugin Directory

source: contact-form-7/tags/5.9.6/admin/includes/welcome-panel.php

Last change on this file was 3043884, checked in by takayukister, 4 months ago

Merge changes on GitHub https://github.com/takayukister/contact-form-7

File size: 8.5 KB
Line 
1<?php
2
3abstract class WPCF7_WelcomePanelColumn {
4
5        abstract protected function icon();
6        abstract protected function title();
7        abstract protected function content();
8
9        public function print_content() {
10                $icon = sprintf(
11                        '<span class="dashicons dashicons-%s" aria-hidden="true"></span>',
12                        esc_attr( $this->icon() )
13                );
14
15                $title = sprintf(
16                        '<h3>%1$s %2$s</h3>',
17                        $icon,
18                        $this->title()
19                );
20
21                $content = $this->content();
22
23                if ( is_array( $content ) ) {
24                        $content = implode( "\n\n", $content );
25                }
26
27                $content = wp_kses_post( $content );
28                $content = wptexturize( $content );
29                $content = convert_chars( $content );
30                $content = wpautop( $content );
31
32                echo "\n";
33                echo '<div class="welcome-panel-column">';
34                echo $title;
35                echo $content;
36                echo '</div>';
37        }
38}
39
40
41class WPCF7_WelcomePanelColumn_AntiSpam extends WPCF7_WelcomePanelColumn {
42
43        protected function icon() {
44                return 'shield';
45        }
46
47        protected function title() {
48                return esc_html(
49                        __( "Getting spammed? You have protection.", 'contact-form-7' )
50                );
51        }
52
53        protected function content() {
54                return array(
55                        esc_html( __( "Spammers target everything; your contact forms are not an exception. Before you get spammed, protect your contact forms with the powerful anti-spam features Contact Form 7 provides.", 'contact-form-7' ) ),
56                        sprintf(
57                                /* translators: links labeled 1: 'Akismet', 2: 'reCAPTCHA', 3: 'disallowed list' */
58                                esc_html( __( 'Contact Form 7 supports spam-filtering with %1$s. Intelligent %2$s blocks annoying spambots. Plus, using %3$s, you can block messages containing specified keywords or those sent from specified IP addresses.', 'contact-form-7' ) ),
59                                wpcf7_link(
60                                        __( 'https://contactform7.com/spam-filtering-with-akismet/', 'contact-form-7' ),
61                                        __( 'Akismet', 'contact-form-7' )
62                                ),
63                                wpcf7_link(
64                                        __( 'https://contactform7.com/recaptcha/', 'contact-form-7' ),
65                                        __( 'reCAPTCHA', 'contact-form-7' )
66                                ),
67                                wpcf7_link(
68                                        __( 'https://contactform7.com/comment-blacklist/', 'contact-form-7' ),
69                                        __( 'disallowed list', 'contact-form-7' )
70                                )
71                        ),
72                );
73        }
74}
75
76
77class WPCF7_WelcomePanelColumn_Donation extends WPCF7_WelcomePanelColumn {
78
79        protected function icon() {
80                return 'megaphone';
81        }
82
83        protected function title() {
84                return esc_html(
85                        __( "Contact Form 7 needs your support.", 'contact-form-7' )
86                );
87        }
88
89        protected function content() {
90                return array(
91                        esc_html( __( "It is hard to continue development and support for this plugin without contributions from users like you.", 'contact-form-7' ) ),
92                        sprintf(
93                                /* translators: %s: link labeled 'making a donation' */
94                                esc_html( __( 'If you enjoy using Contact Form 7 and find it useful, please consider %s.', 'contact-form-7' ) ),
95                                wpcf7_link(
96                                        __( 'https://contactform7.com/donate/', 'contact-form-7' ),
97                                        __( 'making a donation', 'contact-form-7' )
98                                )
99                        ),
100                        esc_html( __( "Your donation will help encourage and support the plugin&#8217;s continued development and better user support.", 'contact-form-7' ) ),
101                );
102        }
103}
104
105
106class WPCF7_WelcomePanelColumn_Flamingo extends WPCF7_WelcomePanelColumn {
107
108        protected function icon() {
109                return 'editor-help';
110        }
111
112        protected function title() {
113                return esc_html(
114                        __( "Before you cry over spilt mail&#8230;", 'contact-form-7' )
115                );
116        }
117
118        protected function content() {
119                return array(
120                        esc_html( __( "Contact Form 7 does not store submitted messages anywhere. Therefore, you may lose important messages forever if your mail server has issues or you make a mistake in mail configuration.", 'contact-form-7' ) ),
121                        sprintf(
122                                /* translators: %s: link labeled 'Flamingo' */
123                                esc_html( __( 'Install a message storage plugin before this happens to you. %s saves all messages through contact forms into the database. Flamingo is a free WordPress plugin created by the same author as Contact Form 7.', 'contact-form-7' ) ),
124                                wpcf7_link(
125                                        __( 'https://contactform7.com/save-submitted-messages-with-flamingo/', 'contact-form-7' ),
126                                        __( 'Flamingo', 'contact-form-7' )
127                                )
128                        ),
129                );
130        }
131}
132
133
134class WPCF7_WelcomePanelColumn_Integration extends WPCF7_WelcomePanelColumn {
135
136        protected function icon() {
137                return 'superhero-alt';
138        }
139
140        protected function title() {
141                return esc_html(
142                        __( "You have strong allies to back you up.", 'contact-form-7' )
143                );
144        }
145
146        protected function content() {
147                return array(
148                        sprintf(
149                                /* translators: 1: link labeled 'Brevo' */
150                                esc_html( __( 'Your contact forms will become more powerful and versatile by integrating them with external APIs. With CRM and email marketing services, you can build your own contact lists (%1$s).', 'contact-form-7' ) ),
151                                wpcf7_link(
152                                        __( 'https://contactform7.com/sendinblue-integration/', 'contact-form-7' ),
153                                        __( 'Brevo', 'contact-form-7' )
154                                )
155                        ),
156                        sprintf(
157                                /* translators: 1: link labeled 'reCAPTCHA', 2: link labeled 'Stripe' */
158                                esc_html( __( 'With help from cloud-based machine learning, anti-spam services will protect your forms (%1$s). Even payment services are natively supported (%2$s).', 'contact-form-7' ) ),
159                                wpcf7_link(
160                                        __( 'https://contactform7.com/recaptcha/', 'contact-form-7' ),
161                                        __( 'reCAPTCHA', 'contact-form-7' )
162                                ),
163                                wpcf7_link(
164                                        __( 'https://contactform7.com/stripe-integration/', 'contact-form-7' ),
165                                        __( 'Stripe', 'contact-form-7' )
166                                )
167                        ),
168                );
169        }
170}
171
172
173function wpcf7_welcome_panel() {
174        $columns = array();
175
176        $flamingo_is_active = defined( 'FLAMINGO_VERSION' );
177
178        $sendinblue_is_active = false;
179
180        if ( class_exists( 'WPCF7_Sendinblue' )
181        and $sendinblue = WPCF7_Sendinblue::get_instance() ) {
182                $sendinblue_is_active = $sendinblue->is_active();
183        }
184
185        if ( $flamingo_is_active and $sendinblue_is_active ) {
186                $columns[] = new WPCF7_WelcomePanelColumn_AntiSpam();
187                $columns[] = new WPCF7_WelcomePanelColumn_Donation();
188        } elseif ( $flamingo_is_active ) {
189                $columns[] = new WPCF7_WelcomePanelColumn_Integration();
190                $columns[] = new WPCF7_WelcomePanelColumn_AntiSpam();
191        } elseif ( $sendinblue_is_active ) {
192                $columns[] = new WPCF7_WelcomePanelColumn_Flamingo();
193                $columns[] = new WPCF7_WelcomePanelColumn_AntiSpam();
194        } else {
195                $columns[] = new WPCF7_WelcomePanelColumn_Flamingo();
196                $columns[] = new WPCF7_WelcomePanelColumn_Integration();
197        }
198
199        $classes = 'wpcf7-welcome-panel';
200
201        $vers = (array) get_user_meta( get_current_user_id(),
202                'wpcf7_hide_welcome_panel_on', true
203        );
204
205        if ( wpcf7_version_grep( wpcf7_version( 'only_major=1' ), $vers ) ) {
206                $classes .= ' hidden';
207        }
208
209?>
210<div id="wpcf7-welcome-panel" class="<?php echo esc_attr( $classes ); ?>">
211        <?php wp_nonce_field( 'wpcf7-welcome-panel-nonce', 'welcomepanelnonce', false ); ?>
212        <a class="welcome-panel-close" href="<?php echo esc_url( menu_page_url( 'wpcf7', false ) ); ?>"><?php echo esc_html( __( 'Dismiss', 'contact-form-7' ) ); ?></a>
213
214        <div class="welcome-panel-content">
215                <div class="welcome-panel-column-container">
216<?php
217
218        foreach ( $columns as $column ) {
219                $column->print_content();
220        }
221
222?>
223                </div>
224        </div>
225</div>
226<?php
227}
228
229
230add_action(
231        'wp_ajax_wpcf7-update-welcome-panel',
232        'wpcf7_admin_ajax_welcome_panel',
233        10, 0
234);
235
236function wpcf7_admin_ajax_welcome_panel() {
237        check_ajax_referer( 'wpcf7-welcome-panel-nonce', 'welcomepanelnonce' );
238
239        $vers = get_user_meta( get_current_user_id(),
240                'wpcf7_hide_welcome_panel_on', true
241        );
242
243        if ( empty( $vers ) or ! is_array( $vers ) ) {
244                $vers = array();
245        }
246
247        if ( empty( $_POST['visible'] ) ) {
248                $vers[] = wpcf7_version( 'only_major=1' );
249        } else {
250                $vers = array_diff( $vers, array( wpcf7_version( 'only_major=1' ) ) );
251        }
252
253        $vers = array_unique( $vers );
254
255        update_user_meta( get_current_user_id(),
256                'wpcf7_hide_welcome_panel_on', $vers
257        );
258
259        wp_die( 1 );
260}
261
262
263add_filter(
264        'screen_settings',
265        'wpcf7_welcome_panel_screen_settings',
266        10, 2
267);
268
269function wpcf7_welcome_panel_screen_settings( $screen_settings, $screen ) {
270
271        if ( 'toplevel_page_wpcf7' !== $screen->id ) {
272                return $screen_settings;
273        }
274
275        $vers = (array) get_user_meta( get_current_user_id(),
276                'wpcf7_hide_welcome_panel_on', true
277        );
278
279        $checkbox_id = 'wpcf7-welcome-panel-show';
280        $checked = ! in_array( wpcf7_version( 'only_major=1' ), $vers );
281
282        $checkbox = sprintf(
283                '<input %s />',
284                wpcf7_format_atts( array(
285                        'id' => $checkbox_id,
286                        'type' => 'checkbox',
287                        'checked' => $checked,
288                ) )
289        );
290
291        $screen_settings .= sprintf( '
292<fieldset class="wpcf7-welcome-panel-options">
293<legend>%1$s</legend>
294<label for="%2$s">%3$s %4$s</label>
295</fieldset>',
296                esc_html( __( 'Welcome panel', 'contact-form-7' ) ),
297                esc_attr( $checkbox_id ),
298                $checkbox,
299                esc_html( __( 'Show welcome panel', 'contact-form-7' ) )
300        );
301
302        return $screen_settings;
303}
Note: See TracBrowser for help on using the repository browser.