changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 18 | be944660c56a |
15:3d4e9c994f10 | 16:a86126ab1dd4 |
---|---|
9 /** |
9 /** |
10 * Returns whether the server is running Apache with the mod_rewrite module loaded. |
10 * Returns whether the server is running Apache with the mod_rewrite module loaded. |
11 * |
11 * |
12 * @since 2.0.0 |
12 * @since 2.0.0 |
13 * |
13 * |
14 * @return bool |
14 * @return bool Whether the server is running Apache with the mod_rewrite module loaded. |
15 */ |
15 */ |
16 function got_mod_rewrite() { |
16 function got_mod_rewrite() { |
17 $got_rewrite = apache_mod_loaded( 'mod_rewrite', true ); |
17 $got_rewrite = apache_mod_loaded( 'mod_rewrite', true ); |
18 |
18 |
19 /** |
19 /** |
58 /** |
58 /** |
59 * Extracts strings from between the BEGIN and END markers in the .htaccess file. |
59 * Extracts strings from between the BEGIN and END markers in the .htaccess file. |
60 * |
60 * |
61 * @since 1.5.0 |
61 * @since 1.5.0 |
62 * |
62 * |
63 * @param string $filename |
63 * @param string $filename Filename to extract the strings from. |
64 * @param string $marker |
64 * @param string $marker The marker to extract the strings from. |
65 * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers. |
65 * @return string[] An array of strings from a file (.htaccess) from between BEGIN and END markers. |
66 */ |
66 */ |
67 function extract_from_markers( $filename, $marker ) { |
67 function extract_from_markers( $filename, $marker ) { |
68 $result = array(); |
68 $result = array(); |
69 |
69 |
70 if ( ! file_exists( $filename ) ) { |
70 if ( ! file_exists( $filename ) ) { |
77 foreach ( $markerdata as $markerline ) { |
77 foreach ( $markerdata as $markerline ) { |
78 if ( false !== strpos( $markerline, '# END ' . $marker ) ) { |
78 if ( false !== strpos( $markerline, '# END ' . $marker ) ) { |
79 $state = false; |
79 $state = false; |
80 } |
80 } |
81 if ( $state ) { |
81 if ( $state ) { |
82 if ( '#' === substr( $markerline, 0, 1 ) ) { |
|
83 continue; |
|
84 } |
|
82 $result[] = $markerline; |
85 $result[] = $markerline; |
83 } |
86 } |
84 if ( false !== strpos( $markerline, '# BEGIN ' . $marker ) ) { |
87 if ( false !== strpos( $markerline, '# BEGIN ' . $marker ) ) { |
85 $state = true; |
88 $state = true; |
86 } |
89 } |
88 |
91 |
89 return $result; |
92 return $result; |
90 } |
93 } |
91 |
94 |
92 /** |
95 /** |
93 * Inserts an array of strings into a file (.htaccess ), placing it between |
96 * Inserts an array of strings into a file (.htaccess), placing it between |
94 * BEGIN and END markers. |
97 * BEGIN and END markers. |
95 * |
98 * |
96 * Replaces existing marked info. Retains surrounding |
99 * Replaces existing marked info. Retains surrounding |
97 * data. Creates file if none exists. |
100 * data. Creates file if none exists. |
98 * |
101 * |
106 function insert_with_markers( $filename, $marker, $insertion ) { |
109 function insert_with_markers( $filename, $marker, $insertion ) { |
107 if ( ! file_exists( $filename ) ) { |
110 if ( ! file_exists( $filename ) ) { |
108 if ( ! is_writable( dirname( $filename ) ) ) { |
111 if ( ! is_writable( dirname( $filename ) ) ) { |
109 return false; |
112 return false; |
110 } |
113 } |
114 |
|
111 if ( ! touch( $filename ) ) { |
115 if ( ! touch( $filename ) ) { |
112 return false; |
116 return false; |
113 } |
117 } |
118 |
|
119 // Make sure the file is created with a minimum set of permissions. |
|
120 $perms = fileperms( $filename ); |
|
121 if ( $perms ) { |
|
122 chmod( $filename, $perms | 0644 ); |
|
123 } |
|
114 } elseif ( ! is_writeable( $filename ) ) { |
124 } elseif ( ! is_writeable( $filename ) ) { |
115 return false; |
125 return false; |
116 } |
126 } |
117 |
127 |
118 if ( ! is_array( $insertion ) ) { |
128 if ( ! is_array( $insertion ) ) { |
119 $insertion = explode( "\n", $insertion ); |
129 $insertion = explode( "\n", $insertion ); |
120 } |
130 } |
131 |
|
132 $switched_locale = switch_to_locale( get_locale() ); |
|
133 |
|
134 $instructions = sprintf( |
|
135 /* translators: 1: Marker. */ |
|
136 __( |
|
137 'The directives (lines) between "BEGIN %1$s" and "END %1$s" are |
|
138 dynamically generated, and should only be modified via WordPress filters. |
|
139 Any changes to the directives between these markers will be overwritten.' |
|
140 ), |
|
141 $marker |
|
142 ); |
|
143 |
|
144 $instructions = explode( "\n", $instructions ); |
|
145 foreach ( $instructions as $line => $text ) { |
|
146 $instructions[ $line ] = '# ' . $text; |
|
147 } |
|
148 |
|
149 /** |
|
150 * Filters the inline instructions inserted before the dynamically generated content. |
|
151 * |
|
152 * @since 5.3.0 |
|
153 * |
|
154 * @param string[] $instructions Array of lines with inline instructions. |
|
155 * @param string $marker The marker being inserted. |
|
156 */ |
|
157 $instructions = apply_filters( 'insert_with_markers_inline_instructions', $instructions, $marker ); |
|
158 |
|
159 if ( $switched_locale ) { |
|
160 restore_previous_locale(); |
|
161 } |
|
162 |
|
163 $insertion = array_merge( $instructions, $insertion ); |
|
121 |
164 |
122 $start_marker = "# BEGIN {$marker}"; |
165 $start_marker = "# BEGIN {$marker}"; |
123 $end_marker = "# END {$marker}"; |
166 $end_marker = "# END {$marker}"; |
124 |
167 |
125 $fp = fopen( $filename, 'r+' ); |
168 $fp = fopen( $filename, 'r+' ); |
133 $lines = array(); |
176 $lines = array(); |
134 while ( ! feof( $fp ) ) { |
177 while ( ! feof( $fp ) ) { |
135 $lines[] = rtrim( fgets( $fp ), "\r\n" ); |
178 $lines[] = rtrim( fgets( $fp ), "\r\n" ); |
136 } |
179 } |
137 |
180 |
138 // Split out the existing file into the preceding lines, and those that appear after the marker |
181 // Split out the existing file into the preceding lines, and those that appear after the marker. |
139 $pre_lines = $post_lines = $existing_lines = array(); |
182 $pre_lines = array(); |
140 $found_marker = $found_end_marker = false; |
183 $post_lines = array(); |
184 $existing_lines = array(); |
|
185 $found_marker = false; |
|
186 $found_end_marker = false; |
|
141 foreach ( $lines as $line ) { |
187 foreach ( $lines as $line ) { |
142 if ( ! $found_marker && false !== strpos( $line, $start_marker ) ) { |
188 if ( ! $found_marker && false !== strpos( $line, $start_marker ) ) { |
143 $found_marker = true; |
189 $found_marker = true; |
144 continue; |
190 continue; |
145 } elseif ( ! $found_end_marker && false !== strpos( $line, $end_marker ) ) { |
191 } elseif ( ! $found_end_marker && false !== strpos( $line, $end_marker ) ) { |
153 } else { |
199 } else { |
154 $existing_lines[] = $line; |
200 $existing_lines[] = $line; |
155 } |
201 } |
156 } |
202 } |
157 |
203 |
158 // Check to see if there was a change |
204 // Check to see if there was a change. |
159 if ( $existing_lines === $insertion ) { |
205 if ( $existing_lines === $insertion ) { |
160 flock( $fp, LOCK_UN ); |
206 flock( $fp, LOCK_UN ); |
161 fclose( $fp ); |
207 fclose( $fp ); |
162 |
208 |
163 return true; |
209 return true; |
164 } |
210 } |
165 |
211 |
166 // Generate the new file data |
212 // Generate the new file data. |
167 $new_file_data = implode( |
213 $new_file_data = implode( |
168 "\n", |
214 "\n", |
169 array_merge( |
215 array_merge( |
170 $pre_lines, |
216 $pre_lines, |
171 array( $start_marker ), |
217 array( $start_marker ), |
173 array( $end_marker ), |
219 array( $end_marker ), |
174 $post_lines |
220 $post_lines |
175 ) |
221 ) |
176 ); |
222 ); |
177 |
223 |
178 // Write to the start of the file, and truncate it to that length |
224 // Write to the start of the file, and truncate it to that length. |
179 fseek( $fp, 0 ); |
225 fseek( $fp, 0 ); |
180 $bytes = fwrite( $fp, $new_file_data ); |
226 $bytes = fwrite( $fp, $new_file_data ); |
181 if ( $bytes ) { |
227 if ( $bytes ) { |
182 ftruncate( $fp, ftell( $fp ) ); |
228 ftruncate( $fp, ftell( $fp ) ); |
183 } |
229 } |
194 * Always writes to the file if it exists and is writable to ensure that we |
240 * Always writes to the file if it exists and is writable to ensure that we |
195 * blank out old rules. |
241 * blank out old rules. |
196 * |
242 * |
197 * @since 1.5.0 |
243 * @since 1.5.0 |
198 * |
244 * |
199 * @global WP_Rewrite $wp_rewrite |
245 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
200 * |
246 * |
201 * @return bool|null True on write success, false on failure. Null in multisite. |
247 * @return bool|null True on write success, false on failure. Null in multisite. |
202 */ |
248 */ |
203 function save_mod_rewrite_rules() { |
249 function save_mod_rewrite_rules() { |
204 if ( is_multisite() ) { |
250 if ( is_multisite() ) { |
206 } |
252 } |
207 |
253 |
208 global $wp_rewrite; |
254 global $wp_rewrite; |
209 |
255 |
210 // Ensure get_home_path() is declared. |
256 // Ensure get_home_path() is declared. |
211 require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
257 require_once ABSPATH . 'wp-admin/includes/file.php'; |
212 |
258 |
213 $home_path = get_home_path(); |
259 $home_path = get_home_path(); |
214 $htaccess_file = $home_path . '.htaccess'; |
260 $htaccess_file = $home_path . '.htaccess'; |
215 |
261 |
216 /* |
262 /* |
231 * Updates the IIS web.config file with the current rules if it is writable. |
277 * Updates the IIS web.config file with the current rules if it is writable. |
232 * If the permalinks do not require rewrite rules then the rules are deleted from the web.config file. |
278 * If the permalinks do not require rewrite rules then the rules are deleted from the web.config file. |
233 * |
279 * |
234 * @since 2.8.0 |
280 * @since 2.8.0 |
235 * |
281 * |
236 * @global WP_Rewrite $wp_rewrite |
282 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
237 * |
283 * |
238 * @return bool|null True on write success, false on failure. Null in multisite. |
284 * @return bool|null True on write success, false on failure. Null in multisite. |
239 */ |
285 */ |
240 function iis7_save_url_rewrite_rules() { |
286 function iis7_save_url_rewrite_rules() { |
241 if ( is_multisite() ) { |
287 if ( is_multisite() ) { |
243 } |
289 } |
244 |
290 |
245 global $wp_rewrite; |
291 global $wp_rewrite; |
246 |
292 |
247 // Ensure get_home_path() is declared. |
293 // Ensure get_home_path() is declared. |
248 require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
294 require_once ABSPATH . 'wp-admin/includes/file.php'; |
249 |
295 |
250 $home_path = get_home_path(); |
296 $home_path = get_home_path(); |
251 $web_config_file = $home_path . 'web.config'; |
297 $web_config_file = $home_path . 'web.config'; |
252 |
298 |
253 // Using win_is_writable() instead of is_writable() because of a bug in Windows PHP |
299 // Using win_is_writable() instead of is_writable() because of a bug in Windows PHP. |
254 if ( iis7_supports_permalinks() && ( ( ! file_exists( $web_config_file ) && win_is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks() ) || win_is_writable( $web_config_file ) ) ) { |
300 if ( iis7_supports_permalinks() && ( ( ! file_exists( $web_config_file ) && win_is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks() ) || win_is_writable( $web_config_file ) ) ) { |
255 $rule = $wp_rewrite->iis7_url_rewrite_rules( false ); |
301 $rule = $wp_rewrite->iis7_url_rewrite_rules( false ); |
256 if ( ! empty( $rule ) ) { |
302 if ( ! empty( $rule ) ) { |
257 return iis7_add_rewrite_rule( $web_config_file, $rule ); |
303 return iis7_add_rewrite_rule( $web_config_file, $rule ); |
258 } else { |
304 } else { |
549 for ( $t = 0; $t < $count - 2; $t++ ) { |
595 for ( $t = 0; $t < $count - 2; $t++ ) { |
550 if ( ! is_array( $tokens[ $t ] ) ) { |
596 if ( ! is_array( $tokens[ $t ] ) ) { |
551 continue; |
597 continue; |
552 } |
598 } |
553 |
599 |
554 if ( T_STRING == $tokens[ $t ][0] && ( '(' == $tokens[ $t + 1 ] || '(' == $tokens[ $t + 2 ] ) ) { |
600 if ( T_STRING == $tokens[ $t ][0] && ( '(' === $tokens[ $t + 1 ] || '(' === $tokens[ $t + 2 ] ) ) { |
555 // If it's a function or class defined locally, there's not going to be any docs available |
601 // If it's a function or class defined locally, there's not going to be any docs available. |
556 if ( ( isset( $tokens[ $t - 2 ][1] ) && in_array( $tokens[ $t - 2 ][1], array( 'function', 'class' ) ) ) || ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR == $tokens[ $t - 1 ][0] ) ) { |
602 if ( ( isset( $tokens[ $t - 2 ][1] ) && in_array( $tokens[ $t - 2 ][1], array( 'function', 'class' ), true ) ) |
603 || ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR == $tokens[ $t - 1 ][0] ) |
|
604 ) { |
|
557 $ignore_functions[] = $tokens[ $t ][1]; |
605 $ignore_functions[] = $tokens[ $t ][1]; |
558 } |
606 } |
559 // Add this to our stack of unique references |
607 // Add this to our stack of unique references. |
560 $functions[] = $tokens[ $t ][1]; |
608 $functions[] = $tokens[ $t ][1]; |
561 } |
609 } |
562 } |
610 } |
563 |
611 |
564 $functions = array_unique( $functions ); |
612 $functions = array_unique( $functions ); |
575 |
623 |
576 $ignore_functions = array_unique( $ignore_functions ); |
624 $ignore_functions = array_unique( $ignore_functions ); |
577 |
625 |
578 $out = array(); |
626 $out = array(); |
579 foreach ( $functions as $function ) { |
627 foreach ( $functions as $function ) { |
580 if ( in_array( $function, $ignore_functions ) ) { |
628 if ( in_array( $function, $ignore_functions, true ) ) { |
581 continue; |
629 continue; |
582 } |
630 } |
583 $out[] = $function; |
631 $out[] = $function; |
584 } |
632 } |
585 |
633 |
594 function set_screen_options() { |
642 function set_screen_options() { |
595 |
643 |
596 if ( isset( $_POST['wp_screen_options'] ) && is_array( $_POST['wp_screen_options'] ) ) { |
644 if ( isset( $_POST['wp_screen_options'] ) && is_array( $_POST['wp_screen_options'] ) ) { |
597 check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); |
645 check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); |
598 |
646 |
599 if ( ! $user = wp_get_current_user() ) { |
647 $user = wp_get_current_user(); |
648 if ( ! $user ) { |
|
600 return; |
649 return; |
601 } |
650 } |
602 $option = $_POST['wp_screen_options']['option']; |
651 $option = $_POST['wp_screen_options']['option']; |
603 $value = $_POST['wp_screen_options']['value']; |
652 $value = $_POST['wp_screen_options']['value']; |
604 |
653 |
605 if ( $option != sanitize_key( $option ) ) { |
654 if ( sanitize_key( $option ) != $option ) { |
606 return; |
655 return; |
607 } |
656 } |
608 |
657 |
609 $map_option = $option; |
658 $map_option = $option; |
610 $type = str_replace( 'edit_', '', $map_option ); |
659 $type = str_replace( 'edit_', '', $map_option ); |
611 $type = str_replace( '_per_page', '', $type ); |
660 $type = str_replace( '_per_page', '', $type ); |
612 if ( in_array( $type, get_taxonomies() ) ) { |
661 if ( in_array( $type, get_taxonomies(), true ) ) { |
613 $map_option = 'edit_tags_per_page'; |
662 $map_option = 'edit_tags_per_page'; |
614 } elseif ( in_array( $type, get_post_types() ) ) { |
663 } elseif ( in_array( $type, get_post_types(), true ) ) { |
615 $map_option = 'edit_per_page'; |
664 $map_option = 'edit_per_page'; |
616 } else { |
665 } else { |
617 $option = str_replace( '-', '_', $option ); |
666 $option = str_replace( '-', '_', $option ); |
618 } |
667 } |
619 |
668 |
624 case 'upload_per_page': |
673 case 'upload_per_page': |
625 case 'edit_tags_per_page': |
674 case 'edit_tags_per_page': |
626 case 'plugins_per_page': |
675 case 'plugins_per_page': |
627 case 'export_personal_data_requests_per_page': |
676 case 'export_personal_data_requests_per_page': |
628 case 'remove_personal_data_requests_per_page': |
677 case 'remove_personal_data_requests_per_page': |
629 // Network admin |
678 // Network admin. |
630 case 'sites_network_per_page': |
679 case 'sites_network_per_page': |
631 case 'users_network_per_page': |
680 case 'users_network_per_page': |
632 case 'site_users_network_per_page': |
681 case 'site_users_network_per_page': |
633 case 'plugins_network_per_page': |
682 case 'plugins_network_per_page': |
634 case 'themes_network_per_page': |
683 case 'themes_network_per_page': |
637 if ( $value < 1 || $value > 999 ) { |
686 if ( $value < 1 || $value > 999 ) { |
638 return; |
687 return; |
639 } |
688 } |
640 break; |
689 break; |
641 default: |
690 default: |
691 $screen_option = false; |
|
692 |
|
693 if ( '_page' === substr( $option, -5 ) || 'layout_columns' === $option ) { |
|
694 /** |
|
695 * Filters a screen option value before it is set. |
|
696 * |
|
697 * The filter can also be used to modify non-standard [items]_per_page |
|
698 * settings. See the parent function for a full list of standard options. |
|
699 * |
|
700 * Returning false from the filter will skip saving the current option. |
|
701 * |
|
702 * @since 2.8.0 |
|
703 * @since 5.4.2 Only applied to options ending with '_page', |
|
704 * or the 'layout_columns' option. |
|
705 * |
|
706 * @see set_screen_options() |
|
707 * |
|
708 * @param mixed $screen_option The value to save instead of the option value. |
|
709 * Default false (to skip saving the current option). |
|
710 * @param string $option The option name. |
|
711 * @param int $value The option value. |
|
712 */ |
|
713 $screen_option = apply_filters( 'set-screen-option', $screen_option, $option, $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
714 } |
|
715 |
|
642 /** |
716 /** |
643 * Filters a screen option value before it is set. |
717 * Filters a screen option value before it is set. |
644 * |
718 * |
645 * The filter can also be used to modify non-standard [items]_per_page |
719 * The dynamic portion of the hook, `$option`, refers to the option name. |
646 * settings. See the parent function for a full list of standard options. |
|
647 * |
720 * |
648 * Returning false to the filter will skip saving the current option. |
721 * Returning false from the filter will skip saving the current option. |
649 * |
722 * |
650 * @since 2.8.0 |
723 * @since 5.4.2 |
651 * |
724 * |
652 * @see set_screen_options() |
725 * @see set_screen_options() |
653 * |
726 * |
654 * @param bool $keep Whether to save or skip saving the screen option value. Default false. |
727 * @param mixed $screen_option The value to save instead of the option value. |
655 * @param string $option The option name. |
728 * Default false (to skip saving the current option). |
656 * @param int $value The number of rows to use. |
729 * @param string $option The option name. |
730 * @param int $value The option value. |
|
657 */ |
731 */ |
658 $value = apply_filters( 'set-screen-option', false, $option, $value ); |
732 $value = apply_filters( "set_screen_option_{$option}", $screen_option, $option, $value ); |
659 |
733 |
660 if ( false === $value ) { |
734 if ( false === $value ) { |
661 return; |
735 return; |
662 } |
736 } |
663 break; |
737 break; |
695 if ( $doc->load( $filename ) === false ) { |
769 if ( $doc->load( $filename ) === false ) { |
696 return false; |
770 return false; |
697 } |
771 } |
698 $xpath = new DOMXPath( $doc ); |
772 $xpath = new DOMXPath( $doc ); |
699 $rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); |
773 $rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); |
700 if ( $rules->length == 0 ) { |
774 if ( 0 == $rules->length ) { |
701 return false; |
775 return false; |
702 } else { |
776 } else { |
703 return true; |
777 return true; |
704 } |
778 } |
705 } |
779 } |
711 * |
785 * |
712 * @param string $filename Name of the configuration file |
786 * @param string $filename Name of the configuration file |
713 * @return bool |
787 * @return bool |
714 */ |
788 */ |
715 function iis7_delete_rewrite_rule( $filename ) { |
789 function iis7_delete_rewrite_rule( $filename ) { |
716 // If configuration file does not exist then rules also do not exist so there is nothing to delete |
790 // If configuration file does not exist then rules also do not exist, so there is nothing to delete. |
717 if ( ! file_exists( $filename ) ) { |
791 if ( ! file_exists( $filename ) ) { |
718 return true; |
792 return true; |
719 } |
793 } |
720 |
794 |
721 if ( ! class_exists( 'DOMDocument', false ) ) { |
795 if ( ! class_exists( 'DOMDocument', false ) ) { |
768 return false; |
842 return false; |
769 } |
843 } |
770 |
844 |
771 $xpath = new DOMXPath( $doc ); |
845 $xpath = new DOMXPath( $doc ); |
772 |
846 |
773 // First check if the rule already exists as in that case there is no need to re-add it |
847 // First check if the rule already exists as in that case there is no need to re-add it. |
774 $wordpress_rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); |
848 $wordpress_rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); |
775 if ( $wordpress_rules->length > 0 ) { |
849 if ( $wordpress_rules->length > 0 ) { |
776 return true; |
850 return true; |
777 } |
851 } |
778 |
852 |
779 // Check the XPath to the rewrite rule and create XML nodes if they do not exist |
853 // Check the XPath to the rewrite rule and create XML nodes if they do not exist. |
780 $xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite/rules' ); |
854 $xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite/rules' ); |
781 if ( $xmlnodes->length > 0 ) { |
855 if ( $xmlnodes->length > 0 ) { |
782 $rules_node = $xmlnodes->item( 0 ); |
856 $rules_node = $xmlnodes->item( 0 ); |
783 } else { |
857 } else { |
784 $rules_node = $doc->createElement( 'rules' ); |
858 $rules_node = $doc->createElement( 'rules' ); |
827 * Saves the XML document into a file |
901 * Saves the XML document into a file |
828 * |
902 * |
829 * @since 2.8.0 |
903 * @since 2.8.0 |
830 * |
904 * |
831 * @param DOMDocument $doc |
905 * @param DOMDocument $doc |
832 * @param string $filename |
906 * @param string $filename |
833 */ |
907 */ |
834 function saveDomDocument( $doc, $filename ) { |
908 function saveDomDocument( $doc, $filename ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
835 $config = $doc->saveXML(); |
909 $config = $doc->saveXML(); |
836 $config = preg_replace( "/([^\r])\n/", "$1\r\n", $config ); |
910 $config = preg_replace( "/([^\r])\n/", "$1\r\n", $config ); |
837 $fp = fopen( $filename, 'w' ); |
911 $fp = fopen( $filename, 'w' ); |
838 fwrite( $fp, $config ); |
912 fwrite( $fp, $config ); |
839 fclose( $fp ); |
913 fclose( $fp ); |
856 if ( isset( $_wp_admin_css_colors['fresh'] ) ) { |
930 if ( isset( $_wp_admin_css_colors['fresh'] ) ) { |
857 // Set Default ('fresh') and Light should go first. |
931 // Set Default ('fresh') and Light should go first. |
858 $_wp_admin_css_colors = array_filter( |
932 $_wp_admin_css_colors = array_filter( |
859 array_merge( |
933 array_merge( |
860 array( |
934 array( |
861 'fresh' => '', |
935 'fresh' => '', |
862 'light' => '', |
936 'light' => '', |
937 'modern' => '', |
|
863 ), |
938 ), |
864 $_wp_admin_css_colors |
939 $_wp_admin_css_colors |
865 ) |
940 ) |
866 ); |
941 ); |
867 } |
942 } |
937 |
1012 |
938 echo '<script type="text/javascript">var _wpColorScheme = ' . wp_json_encode( array( 'icons' => $icon_colors ) ) . ";</script>\n"; |
1013 echo '<script type="text/javascript">var _wpColorScheme = ' . wp_json_encode( array( 'icons' => $icon_colors ) ) . ";</script>\n"; |
939 } |
1014 } |
940 |
1015 |
941 /** |
1016 /** |
942 * @since 3.3.0 |
1017 * Displays the viewport meta in the admin. |
943 */ |
1018 * |
944 function _ipad_meta() { |
1019 * @since 5.5.0 |
945 if ( wp_is_mobile() ) { |
1020 */ |
946 ?> |
1021 function wp_admin_viewport_meta() { |
947 <meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=1"> |
1022 /** |
948 <?php |
1023 * Filters the viewport meta in the admin. |
949 } |
1024 * |
1025 * @since 5.5.0 |
|
1026 * |
|
1027 * @param string $viewport_meta The viewport meta. |
|
1028 */ |
|
1029 $viewport_meta = apply_filters( 'admin_viewport_meta', 'width=device-width,initial-scale=1.0' ); |
|
1030 |
|
1031 if ( empty( $viewport_meta ) ) { |
|
1032 return; |
|
1033 } |
|
1034 |
|
1035 echo '<meta name="viewport" content="' . esc_attr( $viewport_meta ) . '">'; |
|
1036 } |
|
1037 |
|
1038 /** |
|
1039 * Adds viewport meta for mobile in Customizer. |
|
1040 * |
|
1041 * Hooked to the {@see 'admin_viewport_meta'} filter. |
|
1042 * |
|
1043 * @since 5.5.0 |
|
1044 * |
|
1045 * @param string $viewport_meta The viewport meta. |
|
1046 * @return string Filtered viewport meta. |
|
1047 */ |
|
1048 function _customizer_mobile_viewport_meta( $viewport_meta ) { |
|
1049 return trim( $viewport_meta, ',' ) . ',minimum-scale=0.5,maximum-scale=1.2'; |
|
950 } |
1050 } |
951 |
1051 |
952 /** |
1052 /** |
953 * Check lock status for posts displayed on the Posts screen |
1053 * Check lock status for posts displayed on the Posts screen |
954 * |
1054 * |
955 * @since 3.6.0 |
1055 * @since 3.6.0 |
956 * |
1056 * |
957 * @param array $response The Heartbeat response. |
1057 * @param array $response The Heartbeat response. |
958 * @param array $data The $_POST data sent. |
1058 * @param array $data The $_POST data sent. |
959 * @param string $screen_id The screen id. |
1059 * @param string $screen_id The screen ID. |
960 * @return array The Heartbeat response. |
1060 * @return array The Heartbeat response. |
961 */ |
1061 */ |
962 function wp_check_locked_posts( $response, $data, $screen_id ) { |
1062 function wp_check_locked_posts( $response, $data, $screen_id ) { |
963 $checked = array(); |
1063 $checked = array(); |
964 |
1064 |
965 if ( array_key_exists( 'wp-check-locked-posts', $data ) && is_array( $data['wp-check-locked-posts'] ) ) { |
1065 if ( array_key_exists( 'wp-check-locked-posts', $data ) && is_array( $data['wp-check-locked-posts'] ) ) { |
966 foreach ( $data['wp-check-locked-posts'] as $key ) { |
1066 foreach ( $data['wp-check-locked-posts'] as $key ) { |
967 if ( ! $post_id = absint( substr( $key, 5 ) ) ) { |
1067 $post_id = absint( substr( $key, 5 ) ); |
1068 if ( ! $post_id ) { |
|
968 continue; |
1069 continue; |
969 } |
1070 } |
970 |
1071 |
971 if ( ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) && current_user_can( 'edit_post', $post_id ) ) { |
1072 $user_id = wp_check_post_lock( $post_id ); |
972 $send = array( 'text' => sprintf( __( '%s is currently editing' ), $user->display_name ) ); |
1073 if ( $user_id ) { |
973 |
1074 $user = get_userdata( $user_id ); |
974 if ( ( $avatar = get_avatar( $user->ID, 18 ) ) && preg_match( "|src='([^']+)'|", $avatar, $matches ) ) { |
1075 if ( $user && current_user_can( 'edit_post', $post_id ) ) { |
975 $send['avatar_src'] = $matches[1]; |
1076 $send = array( |
1077 /* translators: %s: User's display name. */ |
|
1078 'text' => sprintf( __( '%s is currently editing' ), $user->display_name ), |
|
1079 ); |
|
1080 |
|
1081 if ( get_option( 'show_avatars' ) ) { |
|
1082 $send['avatar_src'] = get_avatar_url( $user->ID, array( 'size' => 18 ) ); |
|
1083 $send['avatar_src_2x'] = get_avatar_url( $user->ID, array( 'size' => 36 ) ); |
|
1084 } |
|
1085 |
|
1086 $checked[ $key ] = $send; |
|
976 } |
1087 } |
977 |
|
978 $checked[ $key ] = $send; |
|
979 } |
1088 } |
980 } |
1089 } |
981 } |
1090 } |
982 |
1091 |
983 if ( ! empty( $checked ) ) { |
1092 if ( ! empty( $checked ) ) { |
992 * |
1101 * |
993 * @since 3.6.0 |
1102 * @since 3.6.0 |
994 * |
1103 * |
995 * @param array $response The Heartbeat response. |
1104 * @param array $response The Heartbeat response. |
996 * @param array $data The $_POST data sent. |
1105 * @param array $data The $_POST data sent. |
997 * @param string $screen_id The screen id. |
1106 * @param string $screen_id The screen ID. |
998 * @return array The Heartbeat response. |
1107 * @return array The Heartbeat response. |
999 */ |
1108 */ |
1000 function wp_refresh_post_lock( $response, $data, $screen_id ) { |
1109 function wp_refresh_post_lock( $response, $data, $screen_id ) { |
1001 if ( array_key_exists( 'wp-refresh-post-lock', $data ) ) { |
1110 if ( array_key_exists( 'wp-refresh-post-lock', $data ) ) { |
1002 $received = $data['wp-refresh-post-lock']; |
1111 $received = $data['wp-refresh-post-lock']; |
1003 $send = array(); |
1112 $send = array(); |
1004 |
1113 |
1005 if ( ! $post_id = absint( $received['post_id'] ) ) { |
1114 $post_id = absint( $received['post_id'] ); |
1115 if ( ! $post_id ) { |
|
1006 return $response; |
1116 return $response; |
1007 } |
1117 } |
1008 |
1118 |
1009 if ( ! current_user_can( 'edit_post', $post_id ) ) { |
1119 if ( ! current_user_can( 'edit_post', $post_id ) ) { |
1010 return $response; |
1120 return $response; |
1011 } |
1121 } |
1012 |
1122 |
1013 if ( ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) ) { |
1123 $user_id = wp_check_post_lock( $post_id ); |
1124 $user = get_userdata( $user_id ); |
|
1125 if ( $user ) { |
|
1014 $error = array( |
1126 $error = array( |
1127 /* translators: %s: User's display name. */ |
|
1015 'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name ), |
1128 'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name ), |
1016 ); |
1129 ); |
1017 |
1130 |
1018 if ( $avatar = get_avatar( $user->ID, 64 ) ) { |
1131 if ( get_option( 'show_avatars' ) ) { |
1019 if ( preg_match( "|src='([^']+)'|", $avatar, $matches ) ) { |
1132 $error['avatar_src'] = get_avatar_url( $user->ID, array( 'size' => 64 ) ); |
1020 $error['avatar_src'] = $matches[1]; |
1133 $error['avatar_src_2x'] = get_avatar_url( $user->ID, array( 'size' => 128 ) ); |
1021 } |
|
1022 } |
1134 } |
1023 |
1135 |
1024 $send['lock_error'] = $error; |
1136 $send['lock_error'] = $error; |
1025 } else { |
1137 } else { |
1026 if ( $new_lock = wp_set_post_lock( $post_id ) ) { |
1138 $new_lock = wp_set_post_lock( $post_id ); |
1139 if ( $new_lock ) { |
|
1027 $send['new_lock'] = implode( ':', $new_lock ); |
1140 $send['new_lock'] = implode( ':', $new_lock ); |
1028 } |
1141 } |
1029 } |
1142 } |
1030 |
1143 |
1031 $response['wp-refresh-post-lock'] = $send; |
1144 $response['wp-refresh-post-lock'] = $send; |
1039 * |
1152 * |
1040 * @since 3.6.0 |
1153 * @since 3.6.0 |
1041 * |
1154 * |
1042 * @param array $response The Heartbeat response. |
1155 * @param array $response The Heartbeat response. |
1043 * @param array $data The $_POST data sent. |
1156 * @param array $data The $_POST data sent. |
1044 * @param string $screen_id The screen id. |
1157 * @param string $screen_id The screen ID. |
1045 * @return array The Heartbeat response. |
1158 * @return array The Heartbeat response. |
1046 */ |
1159 */ |
1047 function wp_refresh_post_nonces( $response, $data, $screen_id ) { |
1160 function wp_refresh_post_nonces( $response, $data, $screen_id ) { |
1048 if ( array_key_exists( 'wp-refresh-post-nonces', $data ) ) { |
1161 if ( array_key_exists( 'wp-refresh-post-nonces', $data ) ) { |
1049 $received = $data['wp-refresh-post-nonces']; |
1162 $received = $data['wp-refresh-post-nonces']; |
1050 $response['wp-refresh-post-nonces'] = array( 'check' => 1 ); |
1163 $response['wp-refresh-post-nonces'] = array( 'check' => 1 ); |
1051 |
1164 |
1052 if ( ! $post_id = absint( $received['post_id'] ) ) { |
1165 $post_id = absint( $received['post_id'] ); |
1166 if ( ! $post_id ) { |
|
1053 return $response; |
1167 return $response; |
1054 } |
1168 } |
1055 |
1169 |
1056 if ( ! current_user_can( 'edit_post', $post_id ) ) { |
1170 if ( ! current_user_can( 'edit_post', $post_id ) ) { |
1057 return $response; |
1171 return $response; |
1074 /** |
1188 /** |
1075 * Add the latest Heartbeat and REST-API nonce to the Heartbeat response. |
1189 * Add the latest Heartbeat and REST-API nonce to the Heartbeat response. |
1076 * |
1190 * |
1077 * @since 5.0.0 |
1191 * @since 5.0.0 |
1078 * |
1192 * |
1079 * @param array $response The Heartbeat response. |
1193 * @param array $response The Heartbeat response. |
1080 * @return array The Heartbeat response. |
1194 * @return array The Heartbeat response. |
1081 */ |
1195 */ |
1082 function wp_refresh_heartbeat_nonces( $response ) { |
1196 function wp_refresh_heartbeat_nonces( $response ) { |
1083 // Refresh the Rest API nonce. |
1197 // Refresh the Rest API nonce. |
1084 $response['rest_nonce'] = wp_create_nonce( 'wp_rest' ); |
1198 $response['rest_nonce'] = wp_create_nonce( 'wp_rest' ); |
1130 $response['wp_autosave'] = array( |
1244 $response['wp_autosave'] = array( |
1131 'success' => false, |
1245 'success' => false, |
1132 'message' => __( 'Error while saving.' ), |
1246 'message' => __( 'Error while saving.' ), |
1133 ); |
1247 ); |
1134 } else { |
1248 } else { |
1135 /* translators: draft saved date format, see https://secure.php.net/date */ |
1249 /* translators: Draft saved date format, see https://www.php.net/date */ |
1136 $draft_saved_date_format = __( 'g:i:s a' ); |
1250 $draft_saved_date_format = __( 'g:i:s a' ); |
1137 /* translators: %s: date and time */ |
|
1138 $response['wp_autosave'] = array( |
1251 $response['wp_autosave'] = array( |
1139 'success' => true, |
1252 'success' => true, |
1253 /* translators: %s: Date and time. */ |
|
1140 'message' => sprintf( __( 'Draft saved at %s.' ), date_i18n( $draft_saved_date_format ) ), |
1254 'message' => sprintf( __( 'Draft saved at %s.' ), date_i18n( $draft_saved_date_format ) ), |
1141 ); |
1255 ); |
1142 } |
1256 } |
1143 } |
1257 } |
1144 |
1258 |
1224 * |
1338 * |
1225 * @param string $old_value The old site admin email address. |
1339 * @param string $old_value The old site admin email address. |
1226 * @param string $value The proposed new site admin email address. |
1340 * @param string $value The proposed new site admin email address. |
1227 */ |
1341 */ |
1228 function update_option_new_admin_email( $old_value, $value ) { |
1342 function update_option_new_admin_email( $old_value, $value ) { |
1229 if ( $value == get_option( 'admin_email' ) || ! is_email( $value ) ) { |
1343 if ( get_option( 'admin_email' ) === $value || ! is_email( $value ) ) { |
1230 return; |
1344 return; |
1231 } |
1345 } |
1232 |
1346 |
1233 $hash = md5( $value . time() . wp_rand() ); |
1347 $hash = md5( $value . time() . wp_rand() ); |
1234 $new_admin_email = array( |
1348 $new_admin_email = array( |
1287 $content = str_replace( '###ADMIN_URL###', esc_url( self_admin_url( 'options.php?adminhash=' . $hash ) ), $content ); |
1401 $content = str_replace( '###ADMIN_URL###', esc_url( self_admin_url( 'options.php?adminhash=' . $hash ) ), $content ); |
1288 $content = str_replace( '###EMAIL###', $value, $content ); |
1402 $content = str_replace( '###EMAIL###', $value, $content ); |
1289 $content = str_replace( '###SITENAME###', wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $content ); |
1403 $content = str_replace( '###SITENAME###', wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $content ); |
1290 $content = str_replace( '###SITEURL###', home_url(), $content ); |
1404 $content = str_replace( '###SITEURL###', home_url(), $content ); |
1291 |
1405 |
1292 /* translators: New admin email address notification email subject. %s: Site title */ |
1406 wp_mail( |
1293 wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ), $content ); |
1407 $value, |
1408 sprintf( |
|
1409 /* translators: New admin email address notification email subject. %s: Site title. */ |
|
1410 __( '[%s] New Admin Email Address' ), |
|
1411 wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) |
|
1412 ), |
|
1413 $content |
|
1414 ); |
|
1294 |
1415 |
1295 if ( $switched_locale ) { |
1416 if ( $switched_locale ) { |
1296 restore_previous_locale(); |
1417 restore_previous_locale(); |
1297 } |
1418 } |
1298 } |
1419 } |
1304 * @since 4.9.8 |
1425 * @since 4.9.8 |
1305 * @access private |
1426 * @access private |
1306 * |
1427 * |
1307 * @param string $title Page title. |
1428 * @param string $title Page title. |
1308 * @param WP_Post $page Page data object. |
1429 * @param WP_Post $page Page data object. |
1309 * |
|
1310 * @return string Page title. |
1430 * @return string Page title. |
1311 */ |
1431 */ |
1312 function _wp_privacy_settings_filter_draft_page_titles( $title, $page ) { |
1432 function _wp_privacy_settings_filter_draft_page_titles( $title, $page ) { |
1313 if ( 'draft' === $page->post_status && 'privacy' === get_current_screen()->id ) { |
1433 if ( 'draft' === $page->post_status && 'privacy' === get_current_screen()->id ) { |
1314 /* translators: %s: Page Title */ |
1434 /* translators: %s: Page title. */ |
1315 $title = sprintf( __( '%s (Draft)' ), $title ); |
1435 $title = sprintf( __( '%s (Draft)' ), $title ); |
1316 } |
1436 } |
1317 |
1437 |
1318 return $title; |
1438 return $title; |
1319 } |
|
1320 |
|
1321 /** |
|
1322 * WP_Privacy_Policy_Content class. |
|
1323 * TODO: move this to a new file. |
|
1324 * |
|
1325 * @since 4.9.6 |
|
1326 */ |
|
1327 final class WP_Privacy_Policy_Content { |
|
1328 |
|
1329 private static $policy_content = array(); |
|
1330 |
|
1331 /** |
|
1332 * Constructor |
|
1333 * |
|
1334 * @since 4.9.6 |
|
1335 */ |
|
1336 private function __construct() {} |
|
1337 |
|
1338 /** |
|
1339 * Add content to the postbox shown when editing the privacy policy. |
|
1340 * |
|
1341 * Plugins and themes should suggest text for inclusion in the site's privacy policy. |
|
1342 * The suggested text should contain information about any functionality that affects user privacy, |
|
1343 * and will be shown in the Suggested Privacy Policy Content postbox. |
|
1344 * |
|
1345 * Intended for use from `wp_add_privacy_policy_content()`. |
|
1346 * |
|
1347 * @since 4.9.6 |
|
1348 * |
|
1349 * @param string $plugin_name The name of the plugin or theme that is suggesting content for the site's privacy policy. |
|
1350 * @param string $policy_text The suggested content for inclusion in the policy. |
|
1351 */ |
|
1352 public static function add( $plugin_name, $policy_text ) { |
|
1353 if ( empty( $plugin_name ) || empty( $policy_text ) ) { |
|
1354 return; |
|
1355 } |
|
1356 |
|
1357 $data = array( |
|
1358 'plugin_name' => $plugin_name, |
|
1359 'policy_text' => $policy_text, |
|
1360 ); |
|
1361 |
|
1362 if ( ! in_array( $data, self::$policy_content, true ) ) { |
|
1363 self::$policy_content[] = $data; |
|
1364 } |
|
1365 } |
|
1366 |
|
1367 /** |
|
1368 * Quick check if any privacy info has changed. |
|
1369 * |
|
1370 * @since 4.9.6 |
|
1371 */ |
|
1372 public static function text_change_check() { |
|
1373 |
|
1374 $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); |
|
1375 |
|
1376 // The site doesn't have a privacy policy. |
|
1377 if ( empty( $policy_page_id ) ) { |
|
1378 return false; |
|
1379 } |
|
1380 |
|
1381 if ( ! current_user_can( 'edit_post', $policy_page_id ) ) { |
|
1382 return false; |
|
1383 } |
|
1384 |
|
1385 $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); |
|
1386 |
|
1387 // Updates are not relevant if the user has not reviewed any suggestions yet. |
|
1388 if ( empty( $old ) ) { |
|
1389 return false; |
|
1390 } |
|
1391 |
|
1392 $cached = get_option( '_wp_suggested_policy_text_has_changed' ); |
|
1393 |
|
1394 /* |
|
1395 * When this function is called before `admin_init`, `self::$policy_content` |
|
1396 * has not been populated yet, so use the cached result from the last |
|
1397 * execution instead. |
|
1398 */ |
|
1399 if ( ! did_action( 'admin_init' ) ) { |
|
1400 return 'changed' === $cached; |
|
1401 } |
|
1402 |
|
1403 $new = self::$policy_content; |
|
1404 |
|
1405 // Remove the extra values added to the meta. |
|
1406 foreach ( $old as $key => $data ) { |
|
1407 if ( ! empty( $data['removed'] ) ) { |
|
1408 unset( $old[ $key ] ); |
|
1409 continue; |
|
1410 } |
|
1411 |
|
1412 $old[ $key ] = array( |
|
1413 'plugin_name' => $data['plugin_name'], |
|
1414 'policy_text' => $data['policy_text'], |
|
1415 ); |
|
1416 } |
|
1417 |
|
1418 // Normalize the order of texts, to facilitate comparison. |
|
1419 sort( $old ); |
|
1420 sort( $new ); |
|
1421 |
|
1422 // The == operator (equal, not identical) was used intentionally. |
|
1423 // See http://php.net/manual/en/language.operators.array.php |
|
1424 if ( $new != $old ) { |
|
1425 // A plugin was activated or deactivated, or some policy text has changed. |
|
1426 // Show a notice on the relevant screens to inform the admin. |
|
1427 add_action( 'admin_notices', array( 'WP_Privacy_Policy_Content', 'policy_text_changed_notice' ) ); |
|
1428 $state = 'changed'; |
|
1429 } else { |
|
1430 $state = 'not-changed'; |
|
1431 } |
|
1432 |
|
1433 // Cache the result for use before `admin_init` (see above). |
|
1434 if ( $cached !== $state ) { |
|
1435 update_option( '_wp_suggested_policy_text_has_changed', $state ); |
|
1436 } |
|
1437 |
|
1438 return 'changed' === $state; |
|
1439 } |
|
1440 |
|
1441 /** |
|
1442 * Output a warning when some privacy info has changed. |
|
1443 * |
|
1444 * @since 4.9.6 |
|
1445 */ |
|
1446 public static function policy_text_changed_notice() { |
|
1447 global $post; |
|
1448 |
|
1449 $screen = get_current_screen()->id; |
|
1450 |
|
1451 if ( 'privacy' !== $screen ) { |
|
1452 return; |
|
1453 } |
|
1454 |
|
1455 ?> |
|
1456 <div class="policy-text-updated notice notice-warning is-dismissible"> |
|
1457 <p> |
|
1458 <?php |
|
1459 printf( |
|
1460 /* translators: %s: Privacy Policy Guide URL */ |
|
1461 __( 'The suggested privacy policy text has changed. Please <a href="%s">review the guide</a> and update your privacy policy.' ), |
|
1462 esc_url( admin_url( 'tools.php?wp-privacy-policy-guide=1' ) ) |
|
1463 ); |
|
1464 ?> |
|
1465 </p> |
|
1466 </div> |
|
1467 <?php |
|
1468 } |
|
1469 |
|
1470 /** |
|
1471 * Update the cached policy info when the policy page is updated. |
|
1472 * |
|
1473 * @since 4.9.6 |
|
1474 * @access private |
|
1475 */ |
|
1476 public static function _policy_page_updated( $post_id ) { |
|
1477 $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); |
|
1478 |
|
1479 if ( ! $policy_page_id || $policy_page_id !== (int) $post_id ) { |
|
1480 return; |
|
1481 } |
|
1482 |
|
1483 // Remove updated|removed status. |
|
1484 $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); |
|
1485 $done = array(); |
|
1486 $update_cache = false; |
|
1487 |
|
1488 foreach ( $old as $old_key => $old_data ) { |
|
1489 if ( ! empty( $old_data['removed'] ) ) { |
|
1490 // Remove the old policy text. |
|
1491 $update_cache = true; |
|
1492 continue; |
|
1493 } |
|
1494 |
|
1495 if ( ! empty( $old_data['updated'] ) ) { |
|
1496 // 'updated' is now 'added'. |
|
1497 $done[] = array( |
|
1498 'plugin_name' => $old_data['plugin_name'], |
|
1499 'policy_text' => $old_data['policy_text'], |
|
1500 'added' => $old_data['updated'], |
|
1501 ); |
|
1502 $update_cache = true; |
|
1503 } else { |
|
1504 $done[] = $old_data; |
|
1505 } |
|
1506 } |
|
1507 |
|
1508 if ( $update_cache ) { |
|
1509 delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); |
|
1510 // Update the cache. |
|
1511 foreach ( $done as $data ) { |
|
1512 add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data ); |
|
1513 } |
|
1514 } |
|
1515 } |
|
1516 |
|
1517 /** |
|
1518 * Check for updated, added or removed privacy policy information from plugins. |
|
1519 * |
|
1520 * Caches the current info in post_meta of the policy page. |
|
1521 * |
|
1522 * @since 4.9.6 |
|
1523 * |
|
1524 * @return array The privacy policy text/informtion added by core and plugins. |
|
1525 */ |
|
1526 public static function get_suggested_policy_text() { |
|
1527 $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); |
|
1528 $checked = array(); |
|
1529 $time = time(); |
|
1530 $update_cache = false; |
|
1531 $new = self::$policy_content; |
|
1532 $old = array(); |
|
1533 |
|
1534 if ( $policy_page_id ) { |
|
1535 $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); |
|
1536 } |
|
1537 |
|
1538 // Check for no-changes and updates. |
|
1539 foreach ( $new as $new_key => $new_data ) { |
|
1540 foreach ( $old as $old_key => $old_data ) { |
|
1541 $found = false; |
|
1542 |
|
1543 if ( $new_data['policy_text'] === $old_data['policy_text'] ) { |
|
1544 // Use the new plugin name in case it was changed, translated, etc. |
|
1545 if ( $old_data['plugin_name'] !== $new_data['plugin_name'] ) { |
|
1546 $old_data['plugin_name'] = $new_data['plugin_name']; |
|
1547 $update_cache = true; |
|
1548 } |
|
1549 |
|
1550 // A plugin was re-activated. |
|
1551 if ( ! empty( $old_data['removed'] ) ) { |
|
1552 unset( $old_data['removed'] ); |
|
1553 $old_data['added'] = $time; |
|
1554 $update_cache = true; |
|
1555 } |
|
1556 |
|
1557 $checked[] = $old_data; |
|
1558 $found = true; |
|
1559 } elseif ( $new_data['plugin_name'] === $old_data['plugin_name'] ) { |
|
1560 // The info for the policy was updated. |
|
1561 $checked[] = array( |
|
1562 'plugin_name' => $new_data['plugin_name'], |
|
1563 'policy_text' => $new_data['policy_text'], |
|
1564 'updated' => $time, |
|
1565 ); |
|
1566 $found = $update_cache = true; |
|
1567 } |
|
1568 |
|
1569 if ( $found ) { |
|
1570 unset( $new[ $new_key ], $old[ $old_key ] ); |
|
1571 continue 2; |
|
1572 } |
|
1573 } |
|
1574 } |
|
1575 |
|
1576 if ( ! empty( $new ) ) { |
|
1577 // A plugin was activated. |
|
1578 foreach ( $new as $new_data ) { |
|
1579 if ( ! empty( $new_data['plugin_name'] ) && ! empty( $new_data['policy_text'] ) ) { |
|
1580 $new_data['added'] = $time; |
|
1581 $checked[] = $new_data; |
|
1582 } |
|
1583 } |
|
1584 $update_cache = true; |
|
1585 } |
|
1586 |
|
1587 if ( ! empty( $old ) ) { |
|
1588 // A plugin was deactivated. |
|
1589 foreach ( $old as $old_data ) { |
|
1590 if ( ! empty( $old_data['plugin_name'] ) && ! empty( $old_data['policy_text'] ) ) { |
|
1591 $data = array( |
|
1592 'plugin_name' => $old_data['plugin_name'], |
|
1593 'policy_text' => $old_data['policy_text'], |
|
1594 'removed' => $time, |
|
1595 ); |
|
1596 |
|
1597 $checked[] = $data; |
|
1598 } |
|
1599 } |
|
1600 $update_cache = true; |
|
1601 } |
|
1602 |
|
1603 if ( $update_cache && $policy_page_id ) { |
|
1604 delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); |
|
1605 // Update the cache. |
|
1606 foreach ( $checked as $data ) { |
|
1607 add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data ); |
|
1608 } |
|
1609 } |
|
1610 |
|
1611 return $checked; |
|
1612 } |
|
1613 |
|
1614 /** |
|
1615 * Add a notice with a link to the guide when editing the privacy policy page. |
|
1616 * |
|
1617 * @since 4.9.6 |
|
1618 * @since 5.0.0 The $post parameter is now optional. |
|
1619 * |
|
1620 * @param WP_Post|null $post The currently edited post. Default null. |
|
1621 */ |
|
1622 public static function notice( $post = null ) { |
|
1623 if ( is_null( $post ) ) { |
|
1624 global $post; |
|
1625 } else { |
|
1626 $post = get_post( $post ); |
|
1627 } |
|
1628 |
|
1629 if ( ! ( $post instanceof WP_Post ) ) { |
|
1630 return; |
|
1631 } |
|
1632 |
|
1633 if ( ! current_user_can( 'manage_privacy_options' ) ) { |
|
1634 return; |
|
1635 } |
|
1636 |
|
1637 $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); |
|
1638 |
|
1639 if ( ! $policy_page_id || $policy_page_id !== $post->ID ) { |
|
1640 return; |
|
1641 } |
|
1642 |
|
1643 $message = __( 'Need help putting together your new Privacy Policy page? Check out our guide for recommendations on what content to include, along with policies suggested by your plugins and theme.' ); |
|
1644 $url = esc_url( admin_url( 'tools.php?wp-privacy-policy-guide=1' ) ); |
|
1645 $label = __( 'View Privacy Policy Guide.' ); |
|
1646 |
|
1647 if ( get_current_screen()->is_block_editor() ) { |
|
1648 wp_enqueue_script( 'wp-notices' ); |
|
1649 $action = array( |
|
1650 'url' => $url, |
|
1651 'label' => $label, |
|
1652 ); |
|
1653 wp_add_inline_script( |
|
1654 'wp-notices', |
|
1655 sprintf( |
|
1656 'wp.data.dispatch( "core/notices" ).createWarningNotice( "%s", { actions: [ %s ], isDismissible: false } )', |
|
1657 $message, |
|
1658 wp_json_encode( $action ) |
|
1659 ), |
|
1660 'after' |
|
1661 ); |
|
1662 } else { |
|
1663 ?> |
|
1664 <div class="notice notice-warning inline wp-pp-notice"> |
|
1665 <p> |
|
1666 <?php |
|
1667 echo $message; |
|
1668 printf( |
|
1669 ' <a href="%s" target="_blank">%s <span class="screen-reader-text">%s</span></a>', |
|
1670 $url, |
|
1671 $label, |
|
1672 /* translators: accessibility text */ |
|
1673 __( '(opens in a new tab)' ) |
|
1674 ); |
|
1675 ?> |
|
1676 </p> |
|
1677 </div> |
|
1678 <?php |
|
1679 } |
|
1680 } |
|
1681 |
|
1682 /** |
|
1683 * Output the privacy policy guide together with content from the theme and plugins. |
|
1684 * |
|
1685 * @since 4.9.6 |
|
1686 */ |
|
1687 public static function privacy_policy_guide() { |
|
1688 |
|
1689 $content_array = self::get_suggested_policy_text(); |
|
1690 |
|
1691 $content = ''; |
|
1692 $toc = array( '<li><a href="#wp-privacy-policy-guide-introduction">' . __( 'Introduction' ) . '</a></li>' ); |
|
1693 $date_format = __( 'F j, Y' ); |
|
1694 $copy = __( 'Copy this section to clipboard' ); |
|
1695 $return_to_top = '<a href="#" class="return-to-top">' . __( '↑ Return to Top' ) . '</a>'; |
|
1696 |
|
1697 foreach ( $content_array as $section ) { |
|
1698 $class = $meta = $removed = ''; |
|
1699 |
|
1700 if ( ! empty( $section['removed'] ) ) { |
|
1701 $class = ' text-removed'; |
|
1702 $date = date_i18n( $date_format, $section['removed'] ); |
|
1703 $meta = sprintf( __( 'Removed %s.' ), $date ); |
|
1704 |
|
1705 $removed = __( 'You deactivated this plugin on %s and may no longer need this policy.' ); |
|
1706 $removed = '<div class="error inline"><p>' . sprintf( $removed, $date ) . '</p></div>'; |
|
1707 } elseif ( ! empty( $section['updated'] ) ) { |
|
1708 $class = ' text-updated'; |
|
1709 $date = date_i18n( $date_format, $section['updated'] ); |
|
1710 $meta = sprintf( __( 'Updated %s.' ), $date ); |
|
1711 } |
|
1712 |
|
1713 if ( $meta ) { |
|
1714 $meta = '<br><span class="privacy-text-meta">' . $meta . '</span>'; |
|
1715 } |
|
1716 |
|
1717 $plugin_name = esc_html( $section['plugin_name'] ); |
|
1718 $toc_id = 'wp-privacy-policy-guide-' . sanitize_title( $plugin_name ); |
|
1719 $toc[] = sprintf( '<li><a href="#%1$s">%2$s</a>' . $meta . '</li>', $toc_id, $plugin_name ); |
|
1720 |
|
1721 $content .= '<div class="privacy-text-section' . $class . '">'; |
|
1722 $content .= '<a id="' . $toc_id . '"> </a>'; |
|
1723 /* translators: %s: plugin name */ |
|
1724 $content .= '<h2>' . sprintf( __( 'Source: %s' ), $plugin_name ) . '</h2>'; |
|
1725 $content .= $removed; |
|
1726 |
|
1727 $content .= '<div class="policy-text">' . $section['policy_text'] . '</div>'; |
|
1728 $content .= $return_to_top; |
|
1729 |
|
1730 if ( empty( $section['removed'] ) ) { |
|
1731 $content .= '<div class="privacy-text-actions">'; |
|
1732 $content .= '<button type="button" class="privacy-text-copy button">'; |
|
1733 $content .= $copy; |
|
1734 $content .= '<span class="screen-reader-text">' . sprintf( __( 'Copy suggested policy text from %s.' ), $plugin_name ) . '</span>'; |
|
1735 $content .= '</button>'; |
|
1736 $content .= '</div>'; |
|
1737 } |
|
1738 |
|
1739 $content .= "</div>\n"; // End of .privacy-text-section. |
|
1740 } |
|
1741 |
|
1742 if ( count( $toc ) > 2 ) { |
|
1743 ?> |
|
1744 <div class="privacy-text-box-toc"> |
|
1745 <p><?php _e( 'Table of Contents' ); ?></p> |
|
1746 <ol> |
|
1747 <?php echo implode( "\n", $toc ); ?> |
|
1748 </ol> |
|
1749 </div> |
|
1750 <?php |
|
1751 } |
|
1752 |
|
1753 ?> |
|
1754 <div class="privacy-text-box"> |
|
1755 <div class="privacy-text-box-head"> |
|
1756 <a id="wp-privacy-policy-guide-introduction"> </a> |
|
1757 <h2><?php _e( 'Introduction' ); ?></h2> |
|
1758 <p><?php _e( 'Hello,' ); ?></p> |
|
1759 <p><?php _e( 'This text template will help you to create your web site’s privacy policy.' ); ?></p> |
|
1760 <p><?php _e( 'We have suggested the sections you will need. Under each section heading you will find a short summary of what information you should provide, which will help you to get started. Some sections include suggested policy content, others will have to be completed with information from your theme and plugins.' ); ?></p> |
|
1761 <p><?php _e( 'Please edit your privacy policy content, making sure to delete the summaries, and adding any information from your theme and plugins. Once you publish your policy page, remember to add it to your navigation menu.' ); ?></p> |
|
1762 <p><?php _e( 'It is your responsibility to write a comprehensive privacy policy, to make sure it reflects all national and international legal requirements on privacy, and to keep your policy current and accurate.' ); ?></p> |
|
1763 </div> |
|
1764 |
|
1765 <div class="privacy-text-box-body"> |
|
1766 <?php echo $content; ?> |
|
1767 </div> |
|
1768 </div> |
|
1769 <?php |
|
1770 } |
|
1771 |
|
1772 /** |
|
1773 * Return the default suggested privacy policy content. |
|
1774 * |
|
1775 * @since 4.9.6 |
|
1776 * @since 5.0.0 Added the `$blocks` parameter. |
|
1777 * |
|
1778 * @param bool $description Whether to include the descriptions under the section headings. Default false. |
|
1779 * @param bool $blocks Whether to format the content for the block editor. Default true. |
|
1780 * @return string The default policy content. |
|
1781 */ |
|
1782 public static function get_default_content( $description = false, $blocks = true ) { |
|
1783 $suggested_text = $description ? '<strong class="privacy-policy-tutorial">' . __( 'Suggested text:' ) . ' </strong>' : ''; |
|
1784 $content = ''; |
|
1785 $strings = array(); |
|
1786 |
|
1787 // Start of the suggested privacy policy text. |
|
1788 if ( $description ) { |
|
1789 $strings[] = '<div class="wp-suggested-text">'; |
|
1790 } |
|
1791 |
|
1792 /* translators: default privacy policy heading. */ |
|
1793 $strings[] = '<h2>' . __( 'Who we are' ) . '</h2>'; |
|
1794 |
|
1795 if ( $description ) { |
|
1796 /* translators: privacy policy tutorial. */ |
|
1797 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should note your site URL, as well as the name of the company, organization, or individual behind it, and some accurate contact information.' ) . '</p>'; |
|
1798 /* translators: privacy policy tutorial. */ |
|
1799 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'The amount of information you may be required to show will vary depending on your local or national business regulations. You may, for example, be required to display a physical address, a registered address, or your company registration number.' ) . '</p>'; |
|
1800 } |
|
1801 |
|
1802 /* translators: default privacy policy text, %s Site URL. */ |
|
1803 $strings[] = '<p>' . $suggested_text . sprintf( __( 'Our website address is: %s.' ), get_bloginfo( 'url', 'display' ) ) . '</p>'; |
|
1804 |
|
1805 /* translators: default privacy policy heading. */ |
|
1806 $strings[] = '<h2>' . __( 'What personal data we collect and why we collect it' ) . '</h2>'; |
|
1807 |
|
1808 if ( $description ) { |
|
1809 /* translators: privacy policy tutorial. */ |
|
1810 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should note what personal data you collect from users and site visitors. This may include personal data, such as name, email address, personal account preferences; transactional data, such as purchase information; and technical data, such as information about cookies.' ) . '</p>'; |
|
1811 /* translators: privacy policy tutorial. */ |
|
1812 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'You should also note any collection and retention of sensitive personal data, such as data concerning health.' ) . '</p>'; |
|
1813 /* translators: privacy policy tutorial. */ |
|
1814 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In addition to listing what personal data you collect, you need to note why you collect it. These explanations must note either the legal basis for your data collection and retention or the active consent the user has given.' ) . '</p>'; |
|
1815 /* translators: privacy policy tutorial. */ |
|
1816 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'Personal data is not just created by a user’s interactions with your site. Personal data is also generated from technical processes such as contact forms, comments, cookies, analytics, and third party embeds.' ) . '</p>'; |
|
1817 /* translators: privacy policy tutorial. */ |
|
1818 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'By default WordPress does not collect any personal data about visitors, and only collects the data shown on the User Profile screen from registered users. However some of your plugins may collect personal data. You should add the relevant information below.' ) . '</p>'; |
|
1819 } |
|
1820 |
|
1821 /* translators: default privacy policy heading. */ |
|
1822 $strings[] = '<h3>' . __( 'Comments' ) . '</h3>'; |
|
1823 |
|
1824 if ( $description ) { |
|
1825 /* translators: privacy policy tutorial. */ |
|
1826 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should note what information is captured through comments. We have noted the data which WordPress collects by default.' ) . '</p>'; |
|
1827 } |
|
1828 |
|
1829 /* translators: default privacy policy text. */ |
|
1830 $strings[] = '<p>' . $suggested_text . __( 'When visitors leave comments on the site we collect the data shown in the comments form, and also the visitor’s IP address and browser user agent string to help spam detection.' ) . '</p>'; |
|
1831 /* translators: default privacy policy text. */ |
|
1832 $strings[] = '<p>' . __( 'An anonymized string created from your email address (also called a hash) may be provided to the Gravatar service to see if you are using it. The Gravatar service privacy policy is available here: https://automattic.com/privacy/. After approval of your comment, your profile picture is visible to the public in the context of your comment.' ) . '</p>'; |
|
1833 |
|
1834 /* translators: default privacy policy heading. */ |
|
1835 $strings[] = '<h3>' . __( 'Media' ) . '</h3>'; |
|
1836 |
|
1837 if ( $description ) { |
|
1838 /* translators: privacy policy tutorial. */ |
|
1839 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should note what information may be disclosed by users who can upload media files. All uploaded files are usually publicly accessible.' ) . '</p>'; |
|
1840 } |
|
1841 |
|
1842 /* translators: default privacy policy text. */ |
|
1843 $strings[] = '<p>' . $suggested_text . __( 'If you upload images to the website, you should avoid uploading images with embedded location data (EXIF GPS) included. Visitors to the website can download and extract any location data from images on the website.' ) . '</p>'; |
|
1844 |
|
1845 /* translators: default privacy policy heading. */ |
|
1846 $strings[] = '<h3>' . __( 'Contact forms' ) . '</h3>'; |
|
1847 |
|
1848 if ( $description ) { |
|
1849 /* translators: privacy policy tutorial. */ |
|
1850 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'By default, WordPress does not include a contact form. If you use a contact form plugin, use this subsection to note what personal data is captured when someone submits a contact form, and how long you keep it. For example, you may note that you keep contact form submissions for a certain period for customer service purposes, but you do not use the information submitted through them for marketing purposes.' ) . '</p>'; |
|
1851 } |
|
1852 |
|
1853 /* translators: default privacy policy heading. */ |
|
1854 $strings[] = '<h3>' . __( 'Cookies' ) . '</h3>'; |
|
1855 |
|
1856 if ( $description ) { |
|
1857 /* translators: privacy policy tutorial. */ |
|
1858 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should list the cookies your web site uses, including those set by your plugins, social media, and analytics. We have provided the cookies which WordPress installs by default.' ) . '</p>'; |
|
1859 } |
|
1860 |
|
1861 /* translators: default privacy policy text. */ |
|
1862 $strings[] = '<p>' . $suggested_text . __( 'If you leave a comment on our site you may opt-in to saving your name, email address and website in cookies. These are for your convenience so that you do not have to fill in your details again when you leave another comment. These cookies will last for one year.' ) . '</p>'; |
|
1863 /* translators: default privacy policy text. */ |
|
1864 $strings[] = '<p>' . __( 'If you visit our login page, we will set a temporary cookie to determine if your browser accepts cookies. This cookie contains no personal data and is discarded when you close your browser.' ) . '</p>'; |
|
1865 /* translators: default privacy policy text. */ |
|
1866 $strings[] = '<p>' . __( 'When you log in, we will also set up several cookies to save your login information and your screen display choices. Login cookies last for two days, and screen options cookies last for a year. If you select "Remember Me", your login will persist for two weeks. If you log out of your account, the login cookies will be removed.' ) . '</p>'; |
|
1867 /* translators: default privacy policy text. */ |
|
1868 $strings[] = '<p>' . __( 'If you edit or publish an article, an additional cookie will be saved in your browser. This cookie includes no personal data and simply indicates the post ID of the article you just edited. It expires after 1 day.' ) . '</p>'; |
|
1869 |
|
1870 /* translators: default privacy policy heading. */ |
|
1871 $strings[] = '<h3>' . __( 'Embedded content from other websites' ) . '</h3>'; |
|
1872 /* translators: default privacy policy text. */ |
|
1873 $strings[] = '<p>' . $suggested_text . __( 'Articles on this site may include embedded content (e.g. videos, images, articles, etc.). Embedded content from other websites behaves in the exact same way as if the visitor has visited the other website.' ) . '</p>'; |
|
1874 /* translators: default privacy policy text. */ |
|
1875 $strings[] = '<p>' . __( 'These websites may collect data about you, use cookies, embed additional third-party tracking, and monitor your interaction with that embedded content, including tracking your interaction with the embedded content if you have an account and are logged in to that website.' ) . '</p>'; |
|
1876 |
|
1877 /* translators: default privacy policy heading. */ |
|
1878 $strings[] = '<h3>' . __( 'Analytics' ) . '</h3>'; |
|
1879 |
|
1880 if ( $description ) { |
|
1881 /* translators: privacy policy tutorial. */ |
|
1882 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should note what analytics package you use, how users can opt out of analytics tracking, and a link to your analytics provider’s privacy policy, if any.' ) . '</p>'; |
|
1883 /* translators: privacy policy tutorial. */ |
|
1884 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'By default WordPress does not collect any analytics data. However, many web hosting accounts collect some anonymous analytics data. You may also have installed a WordPress plugin that provides analytics services. In that case, add information from that plugin here.' ) . '</p>'; |
|
1885 } |
|
1886 |
|
1887 /* translators: default privacy policy heading. */ |
|
1888 $strings[] = '<h2>' . __( 'Who we share your data with' ) . '</h2>'; |
|
1889 |
|
1890 if ( $description ) { |
|
1891 /* translators: privacy policy tutorial. */ |
|
1892 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should name and list all third party providers with whom you share site data, including partners, cloud-based services, payment processors, and third party service providers, and note what data you share with them and why. Link to their own privacy policies if possible.' ) . '</p>'; |
|
1893 /* translators: privacy policy tutorial. */ |
|
1894 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'By default WordPress does not share any personal data with anyone.' ) . '</p>'; |
|
1895 } |
|
1896 |
|
1897 /* translators: default privacy policy heading. */ |
|
1898 $strings[] = '<h2>' . __( 'How long we retain your data' ) . '</h2>'; |
|
1899 |
|
1900 if ( $description ) { |
|
1901 /* translators: privacy policy tutorial. */ |
|
1902 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should explain how long you retain personal data collected or processed by the web site. While it is your responsibility to come up with the schedule of how long you keep each dataset for and why you keep it, that information does need to be listed here. For example, you may want to say that you keep contact form entries for six months, analytics records for a year, and customer purchase records for ten years.' ) . '</p>'; |
|
1903 } |
|
1904 |
|
1905 /* translators: default privacy policy text. */ |
|
1906 $strings[] = '<p>' . $suggested_text . __( 'If you leave a comment, the comment and its metadata are retained indefinitely. This is so we can recognize and approve any follow-up comments automatically instead of holding them in a moderation queue.' ) . '</p>'; |
|
1907 /* translators: default privacy policy text. */ |
|
1908 $strings[] = '<p>' . __( 'For users that register on our website (if any), we also store the personal information they provide in their user profile. All users can see, edit, or delete their personal information at any time (except they cannot change their username). Website administrators can also see and edit that information.' ) . '</p>'; |
|
1909 |
|
1910 /* translators: default privacy policy heading. */ |
|
1911 $strings[] = '<h2>' . __( 'What rights you have over your data' ) . '</h2>'; |
|
1912 |
|
1913 if ( $description ) { |
|
1914 /* translators: privacy policy tutorial. */ |
|
1915 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should explain what rights your users have over their data and how they can invoke those rights.' ) . '</p>'; |
|
1916 } |
|
1917 |
|
1918 /* translators: default privacy policy text. */ |
|
1919 $strings[] = '<p>' . $suggested_text . __( 'If you have an account on this site, or have left comments, you can request to receive an exported file of the personal data we hold about you, including any data you have provided to us. You can also request that we erase any personal data we hold about you. This does not include any data we are obliged to keep for administrative, legal, or security purposes.' ) . '</p>'; |
|
1920 |
|
1921 /* translators: default privacy policy heading. */ |
|
1922 $strings[] = '<h2>' . __( 'Where we send your data' ) . '</h2>'; |
|
1923 |
|
1924 if ( $description ) { |
|
1925 /* translators: privacy policy tutorial. */ |
|
1926 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should list all transfers of your site data outside the European Union and describe the means by which that data is safeguarded to European data protection standards. This could include your web hosting, cloud storage, or other third party services.' ) . '</p>'; |
|
1927 /* translators: privacy policy tutorial. */ |
|
1928 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'European data protection law requires data about European residents which is transferred outside the European Union to be safeguarded to the same standards as if the data was in Europe. So in addition to listing where data goes, you should describe how you ensure that these standards are met either by yourself or by your third party providers, whether that is through an agreement such as Privacy Shield, model clauses in your contracts, or binding corporate rules.' ) . '</p>'; |
|
1929 } |
|
1930 |
|
1931 /* translators: default privacy policy text. */ |
|
1932 $strings[] = '<p>' . $suggested_text . __( 'Visitor comments may be checked through an automated spam detection service.' ) . '</p>'; |
|
1933 |
|
1934 /* translators: default privacy policy heading. */ |
|
1935 $strings[] = '<h2>' . __( 'Your contact information' ) . '</h2>'; |
|
1936 |
|
1937 if ( $description ) { |
|
1938 /* translators: privacy policy tutorial. */ |
|
1939 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should provide a contact method for privacy-specific concerns. If you are required to have a Data Protection Officer, list their name and full contact details here as well.' ) . '</p>'; |
|
1940 } |
|
1941 |
|
1942 /* translators: default privacy policy heading. */ |
|
1943 $strings[] = '<h2>' . __( 'Additional information' ) . '</h2>'; |
|
1944 |
|
1945 if ( $description ) { |
|
1946 /* translators: privacy policy tutorial. */ |
|
1947 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'If you use your site for commercial purposes and you engage in more complex collection or processing of personal data, you should note the following information in your privacy policy in addition to the information we have already discussed.' ) . '</p>'; |
|
1948 } |
|
1949 |
|
1950 /* translators: default privacy policy heading. */ |
|
1951 $strings[] = '<h3>' . __( 'How we protect your data' ) . '</h3>'; |
|
1952 |
|
1953 if ( $description ) { |
|
1954 /* translators: privacy policy tutorial. */ |
|
1955 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should explain what measures you have taken to protect your users’ data. This could include technical measures such as encryption; security measures such as two factor authentication; and measures such as staff training in data protection. If you have carried out a Privacy Impact Assessment, you can mention it here too.' ) . '</p>'; |
|
1956 } |
|
1957 |
|
1958 /* translators: default privacy policy heading. */ |
|
1959 $strings[] = '<h3>' . __( 'What data breach procedures we have in place' ) . '</h3>'; |
|
1960 |
|
1961 if ( $description ) { |
|
1962 /* translators: privacy policy tutorial. */ |
|
1963 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should explain what procedures you have in place to deal with data breaches, either potential or real, such as internal reporting systems, contact mechanisms, or bug bounties.' ) . '</p>'; |
|
1964 } |
|
1965 |
|
1966 /* translators: default privacy policy heading. */ |
|
1967 $strings[] = '<h3>' . __( 'What third parties we receive data from' ) . '</h3>'; |
|
1968 |
|
1969 if ( $description ) { |
|
1970 /* translators: privacy policy tutorial. */ |
|
1971 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'If your web site receives data about users from third parties, including advertisers, this information must be included within the section of your privacy policy dealing with third party data.' ) . '</p>'; |
|
1972 } |
|
1973 |
|
1974 /* translators: default privacy policy heading. */ |
|
1975 $strings[] = '<h3>' . __( 'What automated decision making and/or profiling we do with user data' ) . '</h3>'; |
|
1976 |
|
1977 if ( $description ) { |
|
1978 /* translators: privacy policy tutorial. */ |
|
1979 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'If your web site provides a service which includes automated decision making - for example, allowing customers to apply for credit, or aggregating their data into an advertising profile - you must note that this is taking place, and include information about how that information is used, what decisions are made with that aggregated data, and what rights users have over decisions made without human intervention.' ) . '</p>'; |
|
1980 } |
|
1981 |
|
1982 /* translators: default privacy policy heading. */ |
|
1983 $strings[] = '<h3>' . __( 'Industry regulatory disclosure requirements' ) . '</h3>'; |
|
1984 |
|
1985 if ( $description ) { |
|
1986 /* translators: privacy policy tutorial. */ |
|
1987 $strings[] = '<p class="privacy-policy-tutorial">' . __( 'If you are a member of a regulated industry, or if you are subject to additional privacy laws, you may be required to disclose that information here.' ) . '</p>'; |
|
1988 $strings[] = '</div>'; |
|
1989 } |
|
1990 |
|
1991 if ( $blocks ) { |
|
1992 foreach ( $strings as $key => $string ) { |
|
1993 if ( 0 === strpos( $string, '<p>' ) ) { |
|
1994 $strings[ $key ] = '<!-- wp:paragraph -->' . $string . '<!-- /wp:paragraph -->'; |
|
1995 } |
|
1996 |
|
1997 if ( 0 === strpos( $string, '<h2>' ) ) { |
|
1998 $strings[ $key ] = '<!-- wp:heading -->' . $string . '<!-- /wp:heading -->'; |
|
1999 } |
|
2000 |
|
2001 if ( 0 === strpos( $string, '<h3>' ) ) { |
|
2002 $strings[ $key ] = '<!-- wp:heading {"level":3} -->' . $string . '<!-- /wp:heading -->'; |
|
2003 } |
|
2004 } |
|
2005 } |
|
2006 |
|
2007 $content = implode( '', $strings ); |
|
2008 // End of the suggested privacy policy text. |
|
2009 |
|
2010 /** |
|
2011 * Filters the default content suggested for inclusion in a privacy policy. |
|
2012 * |
|
2013 * @since 4.9.6 |
|
2014 * @since 5.0.0 Added the `$strings`, `$description`, and `$blocks` parameters. |
|
2015 * |
|
2016 * @param string $content The default policy content. |
|
2017 * @param array $strings An array of privacy policy content strings. |
|
2018 * @param bool $description Whether policy descriptions should be included. |
|
2019 * @param bool $blocks Whether the content should be formatted for the block editor. |
|
2020 */ |
|
2021 return apply_filters( 'wp_get_default_privacy_policy_content', $content, $strings, $description, $blocks ); |
|
2022 } |
|
2023 |
|
2024 /** |
|
2025 * Add the suggested privacy policy text to the policy postbox. |
|
2026 * |
|
2027 * @since 4.9.6 |
|
2028 */ |
|
2029 public static function add_suggested_content() { |
|
2030 $content = self::get_default_content( true, false ); |
|
2031 wp_add_privacy_policy_content( __( 'WordPress' ), $content ); |
|
2032 } |
|
2033 } |
1439 } |
2034 |
1440 |
2035 /** |
1441 /** |
2036 * Checks if the user needs to update PHP. |
1442 * Checks if the user needs to update PHP. |
2037 * |
1443 * |
2038 * @since 5.1.0 |
1444 * @since 5.1.0 |
2039 * @since 5.1.1 Added the {@see 'wp_is_php_version_acceptable'} filter. |
1445 * @since 5.1.1 Added the {@see 'wp_is_php_version_acceptable'} filter. |
2040 * |
1446 * |
2041 * @return array|false $response Array of PHP version data. False on failure. |
1447 * @return array|false Array of PHP version data. False on failure. |
2042 */ |
1448 */ |
2043 function wp_check_php_version() { |
1449 function wp_check_php_version() { |
2044 $version = phpversion(); |
1450 $version = phpversion(); |
2045 $key = md5( $version ); |
1451 $key = md5( $version ); |
2046 |
1452 |