|
1 <?php |
|
2 /** |
|
3 * Privacy Settings Screen. |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage Administration |
|
7 */ |
|
8 |
|
9 /** WordPress Administration Bootstrap */ |
|
10 require_once __DIR__ . '/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 setting 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( 'page_for_privacy_policy', 'page_for_privacy_policy', $privacy_page_updated_message, 'success' ); |
|
49 } elseif ( 'create-privacy-page' === $action ) { |
|
50 |
|
51 if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) { |
|
52 require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php'; |
|
53 } |
|
54 |
|
55 $privacy_policy_page_content = WP_Privacy_Policy_Content::get_default_content(); |
|
56 $privacy_policy_page_id = wp_insert_post( |
|
57 array( |
|
58 'post_title' => __( 'Privacy Policy' ), |
|
59 'post_status' => 'draft', |
|
60 'post_type' => 'page', |
|
61 'post_content' => $privacy_policy_page_content, |
|
62 ), |
|
63 true |
|
64 ); |
|
65 |
|
66 if ( is_wp_error( $privacy_policy_page_id ) ) { |
|
67 add_settings_error( |
|
68 'page_for_privacy_policy', |
|
69 'page_for_privacy_policy', |
|
70 __( 'Unable to create a Privacy Policy page.' ), |
|
71 'error' |
|
72 ); |
|
73 } else { |
|
74 update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id ); |
|
75 |
|
76 wp_redirect( admin_url( 'post.php?post=' . $privacy_policy_page_id . '&action=edit' ) ); |
|
77 exit; |
|
78 } |
|
79 } |
|
80 } |
|
81 |
|
82 // If a Privacy Policy page ID is available, make sure the page actually exists. If not, display an error. |
|
83 $privacy_policy_page_exists = false; |
|
84 $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); |
|
85 |
|
86 if ( ! empty( $privacy_policy_page_id ) ) { |
|
87 |
|
88 $privacy_policy_page = get_post( $privacy_policy_page_id ); |
|
89 |
|
90 if ( ! $privacy_policy_page instanceof WP_Post ) { |
|
91 add_settings_error( |
|
92 'page_for_privacy_policy', |
|
93 'page_for_privacy_policy', |
|
94 __( 'The currently selected Privacy Policy page does not exist. Please create or select a new page.' ), |
|
95 'error' |
|
96 ); |
|
97 } else { |
|
98 if ( 'trash' === $privacy_policy_page->post_status ) { |
|
99 add_settings_error( |
|
100 'page_for_privacy_policy', |
|
101 'page_for_privacy_policy', |
|
102 sprintf( |
|
103 /* translators: %s: URL to Pages Trash. */ |
|
104 __( '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>.' ), |
|
105 'edit.php?post_status=trash&post_type=page' |
|
106 ), |
|
107 'error' |
|
108 ); |
|
109 } else { |
|
110 $privacy_policy_page_exists = true; |
|
111 } |
|
112 } |
|
113 } |
|
114 |
|
115 $title = __( 'Privacy Settings' ); |
|
116 $parent_file = 'options-general.php'; |
|
117 |
|
118 require_once ABSPATH . 'wp-admin/admin-header.php'; |
|
119 |
|
120 ?> |
|
121 <div class="wrap"> |
|
122 <h1><?php echo $title; ?></h1> |
|
123 <h2><?php _e( 'Privacy Policy Page' ); ?></h2> |
|
124 <p> |
|
125 <?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.' ); ?> |
|
126 <?php _e( 'If you already have a Privacy Policy page, please select it below. If not, please create one.' ); ?> |
|
127 </p> |
|
128 <p> |
|
129 <?php _e( 'The new page will include help and suggestions for your Privacy Policy.' ); ?> |
|
130 <?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.' ); ?> |
|
131 </p> |
|
132 <p> |
|
133 <?php _e( 'After your Privacy Policy page is set, we suggest that you edit it.' ); ?> |
|
134 <?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.' ); ?> |
|
135 </p> |
|
136 <?php |
|
137 |
|
138 if ( $privacy_policy_page_exists ) { |
|
139 $edit_href = add_query_arg( |
|
140 array( |
|
141 'post' => $privacy_policy_page_id, |
|
142 'action' => 'edit', |
|
143 ), |
|
144 admin_url( 'post.php' ) |
|
145 ); |
|
146 |
|
147 $view_href = get_permalink( $privacy_policy_page_id ); |
|
148 ?> |
|
149 <p class="tools-privacy-edit"><strong> |
|
150 <?php |
|
151 if ( 'publish' === get_post_status( $privacy_policy_page_id ) ) { |
|
152 printf( |
|
153 /* translators: 1: URL to edit Privacy Policy page, 2: URL to view Privacy Policy page. */ |
|
154 __( '<a href="%1$s">Edit</a> or <a href="%2$s">view</a> your Privacy Policy page content.' ), |
|
155 esc_url( $edit_href ), |
|
156 esc_url( $view_href ) |
|
157 ); |
|
158 } else { |
|
159 printf( |
|
160 /* translators: 1: URL to edit Privacy Policy page, 2: URL to preview Privacy Policy page. */ |
|
161 __( '<a href="%1$s">Edit</a> or <a href="%2$s">preview</a> your Privacy Policy page content.' ), |
|
162 esc_url( $edit_href ), |
|
163 esc_url( $view_href ) |
|
164 ); |
|
165 } |
|
166 ?> |
|
167 </strong></p> |
|
168 <?php |
|
169 } |
|
170 ?> |
|
171 <p> |
|
172 <?php |
|
173 printf( |
|
174 /* translators: 1: Privacy Policy guide URL, 2: Additional link attributes, 3: Accessibility text. */ |
|
175 __( '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.' ), |
|
176 esc_url( admin_url( 'privacy-policy-guide.php' ) ), |
|
177 '', |
|
178 '' |
|
179 ); |
|
180 ?> |
|
181 </p> |
|
182 |
|
183 <hr> |
|
184 <table class="form-table tools-privacy-policy-page" role="presentation"> |
|
185 <tr> |
|
186 <th scope="row"> |
|
187 <label for="page_for_privacy_policy"> |
|
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 </label> |
|
196 </th> |
|
197 <td> |
|
198 <?php |
|
199 $has_pages = (bool) get_posts( |
|
200 array( |
|
201 'post_type' => 'page', |
|
202 'posts_per_page' => 1, |
|
203 'post_status' => array( |
|
204 'publish', |
|
205 'draft', |
|
206 ), |
|
207 ) |
|
208 ); |
|
209 |
|
210 if ( $has_pages ) : |
|
211 ?> |
|
212 <form method="post" action=""> |
|
213 <input type="hidden" name="action" value="set-privacy-page" /> |
|
214 <?php |
|
215 wp_dropdown_pages( |
|
216 array( |
|
217 'name' => 'page_for_privacy_policy', |
|
218 'show_option_none' => __( '— Select —' ), |
|
219 'option_none_value' => '0', |
|
220 'selected' => $privacy_policy_page_id, |
|
221 'post_status' => array( 'draft', 'publish' ), |
|
222 ) |
|
223 ); |
|
224 |
|
225 wp_nonce_field( 'set-privacy-page' ); |
|
226 |
|
227 submit_button( __( 'Use This Page' ), 'primary', 'submit', false, array( 'id' => 'set-page' ) ); |
|
228 ?> |
|
229 </form> |
|
230 <?php endif; ?> |
|
231 |
|
232 <form class="wp-create-privacy-page" method="post" action=""> |
|
233 <input type="hidden" name="action" value="create-privacy-page" /> |
|
234 <span> |
|
235 <?php |
|
236 if ( $has_pages ) { |
|
237 _e( 'Or:' ); |
|
238 } else { |
|
239 _e( 'There are no pages.' ); |
|
240 } |
|
241 ?> |
|
242 </span> |
|
243 <?php |
|
244 wp_nonce_field( 'create-privacy-page' ); |
|
245 |
|
246 submit_button( __( 'Create New Page' ), 'primary', 'submit', false, array( 'id' => 'create-page' ) ); |
|
247 ?> |
|
248 </form> |
|
249 </td> |
|
250 </tr> |
|
251 </table> |
|
252 </div> |
|
253 <?php |
|
254 |
|
255 require_once ABSPATH . 'wp-admin/admin-footer.php'; |