PluginProbe ʕ •ᴥ•ʔ
External Links – nofollow, noopener & new window / 2.3
External Links – nofollow, noopener & new window v2.3
0.31 0.32 0.33 0.34 0.35 1.01 1.02 1.03 1.10 1.20 1.21 1.30 1.31 1.40 1.41 1.50 1.51 1.52 1.53 1.54 1.55 1.56 1.60 1.61 1.62 1.70 1.80 1.81 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 2.3 2.32 2.35 2.40 2.42 2.43 2.45 2.46 2.47 2.48 2.50 2.51 2.55 2.56 2.57 2.58 2.59 2.60 2.61 2.62 2.63 2.64 2.65 trunk 0.10 0.11 0.12 0.20 0.21 0.30
wp-external-links / includes / admin / settings-fields / class-wpel-exceptions-fields.php
wp-external-links / includes / admin / settings-fields Last commit date
class-wpel-admin-fields.php 7 years ago class-wpel-exceptions-fields.php 7 years ago class-wpel-excluded-link-fields.php 7 years ago class-wpel-external-link-fields.php 7 years ago class-wpel-internal-link-fields.php 7 years ago class-wpel-link-fields-base.php 7 years ago
class-wpel-exceptions-fields.php
258 lines
1 <?php
2 /**
3 * Class WPEL_Exceptions_Fields
4 *
5 * @package WPEL
6 * @category WordPress Plugin
7 * @version 2.3
8 * @link https://www.webfactoryltd.com/
9 * @license Dual licensed under the MIT and GPLv2+ licenses
10 */
11 final class WPEL_Exceptions_Fields extends FWP_Settings_Section_Base_1x0x0
12 {
13
14 /**
15 * Initialize
16 */
17 protected function init()
18 {
19 $this->set_settings( array(
20 'section_id' => 'wpel-exceptions-fields',
21 'page_id' => 'wpel-exceptions-fields',
22 'option_name' => 'wpel-exceptions-settings',
23 'option_group' => 'wpel-exceptions-settings',
24 'title' => __( 'Exceptions', 'wp-external-links' ),
25 'fields' => array(
26 'apply_all' => array(
27 'label' => __( 'Apply settings on:', 'wp-external-links' ),
28 'class' => 'js-wpel-apply',
29 'default_value' => '1',
30 ),
31 'apply_post_content' => array(
32 'class' => 'js-wpel-apply-child wpel-hidden wpel-no-label ',
33 'default_value' => '1',
34 ),
35 'apply_comments' => array(
36 'class' => 'js-wpel-apply-child wpel-hidden wpel-no-label',
37 'default_value' => '1',
38 ),
39 'apply_widgets' => array(
40 'class' => 'js-wpel-apply-child wpel-hidden wpel-no-label',
41 'default_value' => '1',
42 ),
43 'skip_post_ids' => array(
44 'label' => __( 'Skip pages or posts (id\'s):', 'wp-external-links' ),
45 ),
46 'ignore_classes' => array(
47 'label' => __( 'Ignore links by class:', 'wp-external-links' ),
48 ),
49 'subdomains_as_internal_links' => array(
50 'label' => __( 'Make subdomains internal:', 'wp-external-links' ),
51 ),
52 'include_urls' => array(
53 'label' => __( 'Include external links by URL:', 'wp-external-links' ),
54 ),
55 'exclude_urls' => array(
56 'label' => __( 'Exclude external links by URL:', 'wp-external-links' ),
57 ),
58 'excludes_as_internal_links' => array(
59 'label' => __( 'Own settings for excluded links:', 'wp-external-links' ),
60 ),
61 'ignore_script_tags' => array(
62 'label' => __( 'Skip <code>&lt;script&gt;</code>:', 'wp-external-links' ),
63 'default_value' => '1',
64 ),
65 'ignore_mailto_links' => array(
66 'label' => __( 'Skip <code>mailto</code> links:', 'wp-external-links' ),
67 'default_value' => '1',
68 ),
69 ),
70 ) );
71
72 parent::init();
73 }
74
75 /**
76 * Show field methods
77 */
78
79 protected function show_apply_all( array $args )
80 {
81 $this->get_html_fields()->check_with_label(
82 $args[ 'key' ]
83 , __( 'All contents (the whole page)', 'wp-external-links' )
84 , '1'
85 , ''
86 );
87 }
88
89 protected function show_apply_post_content( array $args )
90 {
91 $this->get_html_fields()->check_with_label(
92 $args[ 'key' ]
93 , __( 'Post content', 'wp-external-links' )
94 , '1'
95 , ''
96 );
97 }
98
99 protected function show_apply_comments( array $args )
100 {
101 $this->get_html_fields()->check_with_label(
102 $args[ 'key' ]
103 , __( 'Comments', 'wp-external-links' )
104 , '1'
105 , ''
106 );
107 }
108
109 protected function show_apply_widgets( array $args )
110 {
111 $this->get_html_fields()->check_with_label(
112 $args[ 'key' ]
113 , __( 'All widgets', 'wp-external-links' )
114 , '1'
115 , ''
116 );
117 }
118
119 protected function show_skip_post_ids( array $args )
120 {
121 $this->get_html_fields()->text( $args[ 'key' ], array(
122 'class' => 'regular-text',
123 ) );
124
125 echo '<p class="description">'
126 . __( 'Separate page- / post-id\'s by comma.', 'wp-external-links' )
127 .'</p>';
128 }
129
130 protected function show_ignore_classes( array $args )
131 {
132 $this->get_html_fields()->text( $args[ 'key' ], array(
133 'class' => 'regular-text',
134 ) );
135
136 echo '<p class="description">'
137 . __( 'Separate classes by comma.', 'wp-external-links' )
138 .'</p>';
139 }
140
141 protected function show_subdomains_as_internal_links( array $args )
142 {
143 $this->get_html_fields()->check_with_label(
144 $args[ 'key' ]
145 , __( 'Treat all links to the site\'s domain and subdomains as internal links', 'wp-external-links' )
146 , '1'
147 , ''
148 );
149 }
150
151 protected function show_include_urls( array $args )
152 {
153 $this->show_urls_field( $args[ 'key' ] );
154 }
155
156 protected function show_exclude_urls( array $args )
157 {
158 $this->show_urls_field( $args[ 'key' ] );
159 }
160
161 protected function show_urls_field( $key )
162 {
163 $this->get_html_fields()->text_area( $key, array(
164 'class' => 'large-text',
165 'rows' => 4,
166 'placeholder' => __( 'For example:'. "\n"
167 .'somedomain.org, sub.domain.net/some-slug'. "\n"
168 .'http://sub.moredomain.net, http://www.domain.com/other-slug', 'wp-external-links' ),
169 ) );
170
171 echo '<p class="description">'
172 . __( 'Separate url\'s by comma and/or a line break. '
173 .'Write the url\'s as specific as you want them to match.', 'wp-external-links' )
174 .'</p>';
175 }
176
177 protected function show_excludes_as_internal_links( array $args )
178 {
179 echo '<fieldset>';
180
181 $this->get_html_fields()->radio_with_label(
182 $args[ 'key' ]
183 , __( 'Treat excluded links as internal links', 'wp-external-links' )
184 , '1'
185 );
186
187 echo '<br>';
188
189 $this->get_html_fields()->radio_with_label(
190 $args[ 'key' ]
191 , __( 'Own settings for excluded links <span class="description">(extra tab)</span>', 'wp-external-links' )
192 , ''
193 );
194
195 echo '</fieldset>';
196 }
197
198 protected function show_ignore_script_tags( array $args )
199 {
200 $this->get_html_fields()->check_with_label(
201 $args[ 'key' ]
202 , __( 'Ignore all links in <code>&lt;script&gt;</code> blocks', 'wp-external-links' )
203 , '1'
204 , ''
205 );
206 }
207
208 protected function show_ignore_mailto_links( array $args )
209 {
210 $this->get_html_fields()->check_with_label(
211 $args[ 'key' ]
212 , __( 'Ignore all <code>mailto</code> links', 'wp-external-links' )
213 , '1'
214 , ''
215 );
216 }
217
218 /**
219 * Validate and sanitize user input before saving to databse
220 * @param array $new_values
221 * @param array $old_values
222 * @return array
223 */
224 protected function before_update( array $new_values, array $old_values )
225 {
226 $update_values = $new_values;
227 $is_valid = true;
228
229 $is_valid = $is_valid && in_array( $new_values[ 'apply_post_content' ], array( '', '1' ) );
230 $is_valid = $is_valid && in_array( $new_values[ 'apply_comments' ], array( '', '1' ) );
231 $is_valid = $is_valid && in_array( $new_values[ 'apply_widgets' ], array( '', '1' ) );
232 $is_valid = $is_valid && in_array( $new_values[ 'apply_all' ], array( '', '1' ) );
233 $is_valid = $is_valid && in_array( $new_values[ 'subdomains_as_internal_links' ], array( '', '1' ) );
234 $is_valid = $is_valid && in_array( $new_values[ 'excludes_as_internal_links' ], array( '', '1' ) );
235 $is_valid = $is_valid && in_array( $new_values[ 'ignore_script_tags' ], array( '', '1' ) );
236 $is_valid = $is_valid && in_array( $new_values[ 'ignore_mailto_links' ], array( '', '1' ) );
237
238 if ( false === $is_valid ) {
239 // error when user input is not valid conform the UI, probably tried to "hack"
240 $this->add_error( __( 'Something went wrong. One or more values were invalid.', 'wp-external-links' ) );
241 return $old_values;
242 }
243
244 if ( '' !== trim( $new_values[ 'include_urls' ] ) ) {
245 $update_values[ 'include_urls' ] = implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $new_values[ 'include_urls' ] ) ) );
246 }
247
248 if ( '' !== trim( $new_values[ 'exclude_urls' ] ) ) {
249 $update_values[ 'exclude_urls' ] = implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $new_values[ 'exclude_urls' ] ) ) );
250 }
251
252 return $update_values;
253 }
254
255 }
256
257 /*?>*/
258