|
1 <?php |
|
2 /** |
|
3 * Privacy Settings Screen. |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage Administration |
|
7 */ |
|
8 |
|
9 /** WordPress Administration Bootstrap */ |
|
10 require_once( dirname( __FILE__ ) . '/admin.php' ); |
|
11 |
|
12 if ( ! current_user_can( 'manage_privacy_options' ) ) { |
|
13 wp_die( __( 'Sorry, you are not allowed to manage privacy on this site.' ) ); |
|
14 } |
|
15 |
|
16 $action = isset( $_POST['action'] ) ? $_POST['action'] : ''; |
|
17 |
|
18 if ( ! empty( $action ) ) { |
|
19 check_admin_referer( $action ); |
|
20 |
|
21 if ( 'set-privacy-page' === $action ) { |
|
22 $privacy_policy_page_id = isset( $_POST['page_for_privacy_policy'] ) ? (int) $_POST['page_for_privacy_policy'] : 0; |
|
23 update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id ); |
|
24 |
|
25 $privacy_page_updated_message = __( 'Privacy Policy page updated successfully.' ); |
|
26 |
|
27 if ( $privacy_policy_page_id ) { |
|
28 /* |
|
29 * Don't always link to the menu customizer: |
|
30 * |
|
31 * - Unpublished pages can't be selected by default. |
|
32 * - `WP_Customize_Nav_Menus::__construct()` checks the user's capabilities. |
|
33 * - Themes might not "officially" support menus. |
|
34 */ |
|
35 if ( |
|
36 'publish' === get_post_status( $privacy_policy_page_id ) |
|
37 && current_user_can( 'edit_theme_options' ) |
|
38 && current_theme_supports( 'menus' ) |
|
39 ) { |
|
40 $privacy_page_updated_message = sprintf( |
|
41 /* translators: %s: URL to Customizer -> Menus */ |
|
42 __( 'Privacy Policy page updated successfully. Remember to <a href="%s">update your menus</a>!' ), |
|
43 esc_url( add_query_arg( 'autofocus[panel]', 'nav_menus', admin_url( 'customize.php' ) ) ) |
|
44 ); |
|
45 } |
|
46 } |
|
47 |
|
48 add_settings_error( |
|
49 'page_for_privacy_policy', |
|
50 'page_for_privacy_policy', |
|
51 $privacy_page_updated_message, |
|
52 'updated' |
|
53 ); |
|
54 } elseif ( 'create-privacy-page' === $action ) { |
|
55 |
|
56 if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) { |
|
57 require_once( ABSPATH . 'wp-admin/includes/misc.php' ); |
|
58 } |
|
59 |
|
60 $privacy_policy_page_content = WP_Privacy_Policy_Content::get_default_content(); |
|
61 $privacy_policy_page_id = wp_insert_post( |
|
62 array( |
|
63 'post_title' => __( 'Privacy Policy' ), |
|
64 'post_status' => 'draft', |
|
65 'post_type' => 'page', |
|
66 'post_content' => $privacy_policy_page_content, |
|
67 ), |
|
68 true |
|
69 ); |
|
70 |
|
71 if ( is_wp_error( $privacy_policy_page_id ) ) { |
|
72 add_settings_error( |
|
73 'page_for_privacy_policy', |
|
74 'page_for_privacy_policy', |
|
75 __( 'Unable to create a Privacy Policy page.' ), |
|
76 'error' |
|
77 ); |
|
78 } else { |
|
79 update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id ); |
|
80 |
|
81 wp_redirect( admin_url( 'post.php?post=' . $privacy_policy_page_id . '&action=edit' ) ); |
|
82 exit; |
|
83 } |
|
84 } |
|
85 } |
|
86 |
|
87 // If a Privacy Policy page ID is available, make sure the page actually exists. If not, display an error. |
|
88 $privacy_policy_page_exists = false; |
|
89 $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); |
|
90 |
|
91 if ( ! empty( $privacy_policy_page_id ) ) { |
|
92 |
|
93 $privacy_policy_page = get_post( $privacy_policy_page_id ); |
|
94 |
|
95 if ( ! $privacy_policy_page instanceof WP_Post ) { |
|
96 add_settings_error( |
|
97 'page_for_privacy_policy', |
|
98 'page_for_privacy_policy', |
|
99 __( 'The currently selected Privacy Policy page does not exist. Please create or select a new page.' ), |
|
100 'error' |
|
101 ); |
|
102 } else { |
|
103 if ( 'trash' === $privacy_policy_page->post_status ) { |
|
104 add_settings_error( |
|
105 'page_for_privacy_policy', |
|
106 'page_for_privacy_policy', |
|
107 sprintf( |
|
108 /* translators: URL to Pages Trash */ |
|
109 __( 'The currently selected Privacy Policy page is in the trash. Please create or select a new Privacy Policy page or <a href="%s">restore the current page</a>.' ), |
|
110 'edit.php?post_status=trash&post_type=page' |
|
111 ), |
|
112 'error' |
|
113 ); |
|
114 } else { |
|
115 $privacy_policy_page_exists = true; |
|
116 } |
|
117 } |
|
118 } |
|
119 |
|
120 $title = __( 'Privacy Settings' ); |
|
121 $parent_file = 'options-general.php'; |
|
122 |
|
123 require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
|
124 |
|
125 ?> |
|
126 <div class="wrap"> |
|
127 <h1><?php echo $title; ?></h1> |
|
128 <h2><?php _e( 'Privacy Policy page' ); ?></h2> |
|
129 <p> |
|
130 <?php _e( 'As a website owner, you may need to follow national or international privacy laws. For example, you may need to create and display a Privacy Policy.' ); ?> |
|
131 <?php _e( 'If you already have a Privacy Policy page, please select it below. If not, please create one.' ); ?> |
|
132 </p> |
|
133 <p> |
|
134 <?php _e( 'The new page will include help and suggestions for your Privacy Policy.' ); ?> |
|
135 <?php _e( 'However, it is your responsibility to use those resources correctly, to provide the information that your Privacy Policy requires, and to keep that information current and accurate.' ); ?> |
|
136 </p> |
|
137 <p> |
|
138 <?php _e( 'After your Privacy Policy page is set, we suggest that you edit it.' ); ?> |
|
139 <?php _e( 'We would also suggest reviewing your Privacy Policy from time to time, especially after installing or updating any themes or plugins. There may be changes or new suggested information for you to consider adding to your policy.' ); ?> |
|
140 </p> |
|
141 <?php |
|
142 |
|
143 if ( $privacy_policy_page_exists ) { |
|
144 $edit_href = add_query_arg( |
|
145 array( |
|
146 'post' => $privacy_policy_page_id, |
|
147 'action' => 'edit', |
|
148 ), |
|
149 admin_url( 'post.php' ) |
|
150 ); |
|
151 |
|
152 $view_href = get_permalink( $privacy_policy_page_id ); |
|
153 |
|
154 ?> |
|
155 <p class="tools-privacy-edit"><strong> |
|
156 <?php |
|
157 |
|
158 if ( 'publish' === get_post_status( $privacy_policy_page_id ) ) { |
|
159 /* translators: 1: URL to edit page, 2: URL to view page */ |
|
160 printf( __( '<a href="%1$s">Edit</a> or <a href="%2$s">view</a> your Privacy Policy page content.' ), $edit_href, $view_href ); |
|
161 } else { |
|
162 /* translators: 1: URL to edit page, 2: URL to preview page */ |
|
163 printf( __( '<a href="%1$s">Edit</a> or <a href="%2$s">preview</a> your Privacy Policy page content.' ), $edit_href, $view_href ); |
|
164 } |
|
165 |
|
166 ?> |
|
167 </strong></p> |
|
168 <p> |
|
169 <?php |
|
170 |
|
171 /* translators: 1: Privacy Policy guide URL, 2: additional link attributes, 3: accessibility text */ |
|
172 printf( |
|
173 __( 'Need help putting together your new Privacy Policy page? <a href="%1$s" %2$s>Check out our guide%3$s</a> for recommendations on what content to include, along with policies suggested by your plugins and theme.' ), |
|
174 admin_url( 'tools.php?wp-privacy-policy-guide' ), |
|
175 '', |
|
176 '' |
|
177 ); |
|
178 |
|
179 ?> |
|
180 </p> |
|
181 <?php |
|
182 } |
|
183 ?> |
|
184 <hr> |
|
185 <table class="form-table tools-privacy-policy-page"> |
|
186 <tr> |
|
187 <th scope="row"> |
|
188 <?php |
|
189 if ( $privacy_policy_page_exists ) { |
|
190 _e( 'Change your Privacy Policy page' ); |
|
191 } else { |
|
192 _e( 'Select a Privacy Policy page' ); |
|
193 } |
|
194 ?> |
|
195 </th> |
|
196 <td> |
|
197 <?php |
|
198 $has_pages = (bool) get_posts( array( |
|
199 'post_type' => 'page', |
|
200 'posts_per_page' => 1, |
|
201 'post_status' => array( |
|
202 'publish', |
|
203 'draft', |
|
204 ), |
|
205 ) ); |
|
206 |
|
207 if ( $has_pages ) : ?> |
|
208 <form method="post" action=""> |
|
209 <label for="page_for_privacy_policy"> |
|
210 <?php _e( 'Select an existing page:' ); ?> |
|
211 </label> |
|
212 <input type="hidden" name="action" value="set-privacy-page" /> |
|
213 <?php |
|
214 wp_dropdown_pages( |
|
215 array( |
|
216 'name' => 'page_for_privacy_policy', |
|
217 'show_option_none' => __( '— Select —' ), |
|
218 'option_none_value' => '0', |
|
219 'selected' => $privacy_policy_page_id, |
|
220 'post_status' => array( 'draft', 'publish' ), |
|
221 ) |
|
222 ); |
|
223 |
|
224 wp_nonce_field( 'set-privacy-page' ); |
|
225 |
|
226 submit_button( __( 'Use This Page' ), 'primary', 'submit', false, array( 'id' => 'set-page' ) ); |
|
227 ?> |
|
228 </form> |
|
229 <?php endif; ?> |
|
230 |
|
231 <form class="wp-create-privacy-page" method="post" action=""> |
|
232 <input type="hidden" name="action" value="create-privacy-page" /> |
|
233 <span> |
|
234 <?php |
|
235 if ( $has_pages ) { |
|
236 _e( 'Or:' ); |
|
237 } else { |
|
238 _e( 'There are no pages.' ); |
|
239 } |
|
240 ?> |
|
241 </span> |
|
242 <?php |
|
243 wp_nonce_field( 'create-privacy-page' ); |
|
244 |
|
245 submit_button( __( 'Create New Page' ), 'primary', 'submit', false, array( 'id' => 'create-page' ) ); |
|
246 ?> |
|
247 </form> |
|
248 </td> |
|
249 </tr> |
|
250 </table> |
|
251 </div> |
|
252 <?php |
|
253 |
|
254 include( ABSPATH . 'wp-admin/admin-footer.php' ); |