| 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 | $page_for_privacy_policy = isset( $_POST['page_for_privacy_policy'] ) ? $_POST['page_for_privacy_policy'] : 0; |
| 23 | update_option( 'page_for_privacy_policy', $page_for_privacy_policy ); |
| 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 | |
| 33 | // Make sure the privacy policy page exists. If not, display a warning |
| 34 | $privacy_policy_page_id = get_option( 'page_for_privacy_policy' ); |
| 35 | if ( ! empty( $privacy_policy_page_id ) ) { |
| 36 | $privacy_policy_page = get_post( $privacy_policy_page_id ); |
| 37 | if ( ! $privacy_policy_page instanceof WP_Post ) { |
| 38 | add_settings_error( |
| 39 | 'page_for_privacy_policy', |
| 40 | 'page_for_privacy_policy', |
| 41 | __( 'The currently selected privacy policy page does not exist' ), |
| 42 | 'warning' |
| 43 | ); |
| 44 | } else { |
| 45 | if ( 'trash' === $privacy_policy_page->post_status ) { |
| 46 | add_settings_error( |
| 47 | 'page_for_privacy_policy', |
| 48 | 'page_for_privacy_policy', |
| 49 | __( 'The currently selected privacy policy page is in the trash. Please select a new privacy policy page.' ), |
| 50 | 'error' |
| 51 | ); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | $title = __( 'Privacy Tools' ); |
| 57 | |
| 58 | get_current_screen()->add_help_tab( array( |
| 59 | 'id' => 'privacy', |
| 60 | 'title' => __( 'Privacy' ), |
| 61 | 'content' => '<p>' . __( 'This page provides tools with which you can manage your user\'s personal data and site\'s privacy policy.' ) . '</p>', |
| 62 | ) ); |
| 63 | |
| 64 | get_current_screen()->set_help_sidebar( |
| 65 | '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
| 66 | '<p>' . __( '<a href="#">Documentation on privacy</a>' ) . '</p>' |
| 67 | ); |
| 68 | |
| 69 | require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
| 70 | |
| 71 | ?> |
| 72 | <div class="wrap"> |
| 73 | <h1><?php echo esc_html( $title ); ?></h1> |
| 74 | <?php settings_errors(); ?> |
| 75 | <table class="form-table"> |
| 76 | <tr> |
| 77 | <th scope="row"><?php _e( 'Privacy policy page' ); ?></th> |
| 78 | <td id="front-static-pages"> |
| 79 | <form method="post" action="tools-privacy.php?action=set-privacy-page"> |
| 80 | <?php wp_nonce_field( 'set-privacy-page' ); ?> |
| 81 | <fieldset> |
| 82 | <legend class="screen-reader-text"><span><?php _e( 'Privacy policy page' ); ?></span></legend> |
| 83 | <label for="page_for_privacy_policy"> |
| 84 | <?php wp_dropdown_pages( |
| 85 | array( |
| 86 | 'name' => 'page_for_privacy_policy', |
| 87 | 'show_option_none' => __( '— Select —' ), |
| 88 | 'option_none_value' => '0', |
| 89 | 'selected' => get_option( 'page_for_privacy_policy' ), |
| 90 | ) |
| 91 | ); |
| 92 | ?> |
| 93 | </label> |
| 94 | </fieldset> |
| 95 | <?php submit_button('Set Page'); ?> |
| 96 | </form> |
| 97 | <?php |
| 98 | if ( empty( $privacy_policy_page_id ) ) { |
| 99 | ?> |
| 100 | <form action="#" id="create-privacy-policy-page" method="POST"> |
| 101 | <p><?php _e( 'It seems that you have not set up a Privacy Policy Page yet!'); ?></p> |
| 102 | <p><input type="submit" class="button button-primary" value="<?php _e( 'Create Page' ); ?>"></p> |
| 103 | </form> |
| 104 | <p class="ajaxresults"> |
| 105 | <span class="spinner"></span> |
| 106 | </p> |
| 107 | <?php |
| 108 | } |
| 109 | ?> |
| 110 | </td> |
| 111 | </tr> |
| 112 | </table> |
| 113 | </div> |
| 114 | <!-- scripts for creating the page --> |
| 115 | <script> |
| 116 | (function($){ |
| 117 | $( document ).ready( function(){ |
| 118 | $( '#create-privacy-policy-page' ).submit( function( e ) { |
| 119 | e.preventDefault(); |
| 120 | $( 'body.tools-privacy-php .spinner' ).addClass( 'is-active' ); |
| 121 | |
| 122 | var data = { |
| 123 | 'action': 'create_privacy_policy_page' |
| 124 | }; |
| 125 | |
| 126 | $.post( |
| 127 | ajaxurl, |
| 128 | data, |
| 129 | function( response ) { |
| 130 | $( 'body.tools-privacy-php .spinner' ).removeClass( 'is-active' ); |
| 131 | $( 'body.tools-privacy-php .ajaxresults ').html('<div class="notice notice-success inline">Your Privacy Policy Page has been created. Click <a rel="noopener" href="post.php?post=' + response.data.message + '&action=edit">HERE</a> to view or edit it.</div>'); |
| 132 | $( 'body.tools-privacy-php #page_for_privacy_policy' ).append('<option value="' + response.data.message + '">Privacy Policy</option>'); |
| 133 | $( 'body.tools-privacy-php #page_for_privacy_policy option[value="' + response.data.message + '"]').prop('selected', 'se;ected').change(); |
| 134 | }); |
| 135 | }); |
| 136 | }); |
| 137 | })(jQuery); |
| 138 | </script> |
| 139 | <!-- certain styles needed for this page --> |
| 140 | <style> |
| 141 | body.tools-privacy-php .spinner { |
| 142 | float: none; |
| 143 | } |
| 144 | </style> |
| 145 | <?php |
| 146 | |
| 147 | include( ABSPATH . 'wp-admin/admin-footer.php' ); |