| 1 | <?php |
| 2 | /** |
| 3 | * Privacy Policy 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_options' ) ) { |
| 13 | wp_die( __( 'Sorry, you are not allowed to manage privacy on this site.' ) ); |
| 14 | } |
| 15 | |
| 16 | $action = isset( $_GET['action'] ) ? $_GET['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'] ) ? $_POST['page_for_privacy_policy'] : 0; |
| 23 | update_option( 'page_for_privacy_policy', $privacy_policy_page_id ); |
| 24 | add_settings_error( |
| 25 | 'page_for_privacy_policy', |
| 26 | 'page_for_privacy_policy', |
| 27 | __( 'Privacy policy page updated successfully' ), |
| 28 | 'updated' |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | if ( 'create-privacy-page' === $action ) { |
| 33 | $privacy_policy_page_id = wp_insert_post( |
| 34 | array( |
| 35 | 'post_title' => __( 'Privacy Policy' ), |
| 36 | 'post_status' => 'publish', |
| 37 | 'post_type' => 'page', |
| 38 | ), |
| 39 | true |
| 40 | ); |
| 41 | |
| 42 | if ( is_wp_error( $privacy_policy_page_id ) ) { |
| 43 | add_settings_error( |
| 44 | 'page_for_privacy_policy', |
| 45 | 'page_for_privacy_policy', |
| 46 | __( 'Unable to create privacy policy page' ), |
| 47 | 'error' |
| 48 | ); |
| 49 | } else { |
| 50 | update_option( 'page_for_privacy_policy', $privacy_policy_page_id ); |
| 51 | add_settings_error( |
| 52 | 'page_for_privacy_policy', |
| 53 | 'page_for_privacy_policy', |
| 54 | __( 'Privacy policy page created successfully' ), |
| 55 | 'updated' |
| 56 | ); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // If a privacy policy page ID is available, make sure the page actually exists. If not, display a warning |
| 62 | $privacy_policy_page_exists = false; |
| 63 | $privacy_policy_page_id = get_option( 'page_for_privacy_policy' ); |
| 64 | if ( ! empty( $privacy_policy_page_id ) ) { |
| 65 | $privacy_policy_page = get_post( $privacy_policy_page_id ); |
| 66 | if ( ! $privacy_policy_page instanceof WP_Post ) { |
| 67 | add_settings_error( |
| 68 | 'page_for_privacy_policy', |
| 69 | 'page_for_privacy_policy', |
| 70 | __( 'The currently selected privacy policy page does not exist' ), |
| 71 | 'warning' |
| 72 | ); |
| 73 | } else { |
| 74 | if ( 'trash' === $privacy_policy_page->post_status ) { |
| 75 | add_settings_error( |
| 76 | 'page_for_privacy_policy', |
| 77 | 'page_for_privacy_policy', |
| 78 | __( 'The currently selected privacy policy page is in the trash. Please select a new privacy policy page.' ), |
| 79 | 'error' |
| 80 | ); |
| 81 | } else { |
| 82 | $privacy_policy_page_exists = true; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | $title = __( 'Privacy Tools' ); |
| 88 | |
| 89 | get_current_screen()->add_help_tab( array( |
| 90 | 'id' => 'privacy', |
| 91 | 'title' => __( 'Privacy' ), |
| 92 | 'content' => '<p>' . __( 'This page provides tools with which you can manage your user\'s personal data and site\'s privacy policy.' ) . '</p>', |
| 93 | ) ); |
| 94 | |
| 95 | get_current_screen()->set_help_sidebar( |
| 96 | '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
| 97 | '<p>' . __( '<a href="#">Documentation on privacy</a>' ) . '</p>' |
| 98 | ); |
| 99 | |
| 100 | require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
| 101 | |
| 102 | ?> |
| 103 | <div class="wrap"> |
| 104 | <h1><?php echo esc_html( $title ); ?></h1> |
| 105 | <?php settings_errors(); ?> |
| 106 | <table class="form-table"> |
| 107 | <tr> |
| 108 | <th scope="row"><?php _e( 'Privacy policy page' ); ?></th> |
| 109 | <td id="front-static-pages"> |
| 110 | <form method="post" action="tools-privacy.php?action=set-privacy-page"> |
| 111 | <?php wp_nonce_field( 'set-privacy-page' ); ?> |
| 112 | <fieldset> |
| 113 | <legend class="screen-reader-text"><span><?php _e( 'Privacy policy page' ); ?></span></legend> |
| 114 | <label for="page_for_privacy_policy"> |
| 115 | <?php wp_dropdown_pages( |
| 116 | array( |
| 117 | 'name' => 'page_for_privacy_policy', |
| 118 | 'show_option_none' => __( '— Select —' ), |
| 119 | 'option_none_value' => '0', |
| 120 | 'selected' => get_option( 'page_for_privacy_policy' ), |
| 121 | ) |
| 122 | ); |
| 123 | ?> |
| 124 | </label> |
| 125 | </fieldset> |
| 126 | <?php submit_button( __( 'Set Page' ) ); ?> |
| 127 | </form> |
| 128 | <?php |
| 129 | if ( empty( $privacy_policy_page_id ) ) { |
| 130 | ?> |
| 131 | <form method="post" action="tools-privacy.php?action=create-privacy-page"> |
| 132 | <?php wp_nonce_field( 'create-privacy-page' ); ?> |
| 133 | <p> |
| 134 | <?php _e( 'If you don\'t already have a page for your privacy policy, you can create one now' ); ?> |
| 135 | </p> |
| 136 | <?php submit_button( __( 'Create Page' ) ); ?> |
| 137 | </form> |
| 138 | <?php |
| 139 | } |
| 140 | if( $privacy_policy_page_exists ) { |
| 141 | $edit_href = add_query_arg( |
| 142 | array( |
| 143 | 'post' => $privacy_policy_page_id, |
| 144 | 'action' => 'edit', |
| 145 | ), |
| 146 | admin_url( 'post.php' ) |
| 147 | ); |
| 148 | $view_href = get_permalink( $privacy_policy_page_id ); |
| 149 | $prompt = sprintf( |
| 150 | __( 'You may also <a href="%1$s">edit</a> or <a href="%2$s">view</a> your privacy policy page' ), |
| 151 | $edit_href, |
| 152 | $view_href |
| 153 | ); |
| 154 | $allowed_html = array( 'a' => array( 'href' => array() ) ); |
| 155 | ?> |
| 156 | <p class="description" id="page_for_privacy_policy_view_edit"> |
| 157 | <?php echo wp_kses( $prompt, $allowed_html ); ?> |
| 158 | </p> |
| 159 | <?php |
| 160 | } |
| 161 | ?> |
| 162 | </td> |
| 163 | </tr> |
| 164 | </table> |
| 165 | </div> |
| 166 | <!-- scripts for creating the page --> |
| 167 | <script> |
| 168 | ( function( $ ) { |
| 169 | $( document ).ready( function() { |
| 170 | $( '#page_for_privacy_policy' ).change( function() { |
| 171 | $( '#page_for_privacy_policy_view_edit' ).hide(); |
| 172 | } ); |
| 173 | } ); |
| 174 | } ( jQuery ) ); |
| 175 | </script> |
| 176 | <?php |
| 177 | |
| 178 | include( ABSPATH . 'wp-admin/admin-footer.php' ); |