From 49901cb028ebcd1027528aeb70da9f34e54a472d Mon Sep 17 00:00:00 2001 From: Fernando Claussen Date: Tue, 17 Jul 2018 15:13:13 -0400 Subject: [PATCH 01/12] Removing telemetry component (#215) --- admin/class-gdpr-admin.php | 30 ----------------------------- admin/partials/settings.php | 3 +-- includes/class-gdpr-activator.php | 2 -- includes/class-gdpr-deactivator.php | 1 - includes/class-gdpr.php | 14 -------------- 5 files changed, 1 insertion(+), 49 deletions(-) diff --git a/admin/class-gdpr-admin.php b/admin/class-gdpr-admin.php index 2679fac8..f58f8112 100755 --- a/admin/class-gdpr-admin.php +++ b/admin/class-gdpr-admin.php @@ -135,19 +135,9 @@ public function add_menu() { $settings_hook = add_submenu_page( $parent_slug, $menu_title, $menu_title, $capability, $menu_slug, $function ); - $menu_slug = 'edit.php?post_type=telemetry'; - - $cpt = 'telemetry'; - $cpt_obj = get_post_type_object( $cpt ); - - if ( $cpt_obj ) { - add_submenu_page( $parent_slug, $cpt_obj->labels->name, $cpt_obj->labels->menu_name, $capability, $menu_slug ); - } - add_action( "load-{$requests_hook}", array( 'GDPR_Help', 'add_requests_help' ) ); add_action( "load-{$tools_hook}", array( 'GDPR_Help', 'add_tools_help' ) ); add_action( "load-{$settings_hook}", array( 'GDPR_Help', 'add_settings_help' ) ); - add_action( 'load-edit.php', array( 'GDPR_Help', 'add_telemetry_help' ) ); } /** @@ -201,7 +191,6 @@ public function register_settings() { 'gdpr_consent_types' => array( $this, 'sanitize_consents' ), 'gdpr_deletion_needs_review' => 'boolval', 'gdpr_disable_css' => 'boolval', - 'gdpr_enable_telemetry_tracker' => 'boolval', 'gdpr_use_recaptcha' => 'boolval', 'gdpr_recaptcha_site_key' => 'sanitize_text_field', 'gdpr_recaptcha_secret_key' => 'sanitize_text_field', @@ -710,25 +699,6 @@ public function clean_data_breach_request() { delete_option( 'gdpr_data_breach_initiated' ); } - /** - * CRON job runs this to clean up the telemetry post type every 12 hours. - * @since 1.0.0 - * @author Fernando Claussen - */ - public function telemetry_cleanup() { - $args = array( - 'post_type' => 'telemetry', - 'posts_per_page' => -1, - 'fields' => 'ids', - ); - - $telemetry_posts = get_posts( $args ); - - foreach ( $telemetry_posts as $post ) { - wp_delete_post( $post, true ); - } - } - /** * Sanitizes the consents during WordPress registration. * @since 1.0.0 diff --git a/admin/partials/settings.php b/admin/partials/settings.php index a49cc234..7dc2d8a1 100755 --- a/admin/partials/settings.php +++ b/admin/partials/settings.php @@ -64,8 +64,7 @@ - - > + diff --git a/includes/class-gdpr-activator.php b/includes/class-gdpr-activator.php index 3b406fef..d0a54fa4 100755 --- a/includes/class-gdpr-activator.php +++ b/includes/class-gdpr-activator.php @@ -25,7 +25,6 @@ class GDPR_Activator { /** * Runs when the user first activates the plugin. - * Sets a CRON jo to clean up the telemetry post type every 12 hours. * * @since 1.0.0 * @static @@ -37,7 +36,6 @@ public static function activate() { } add_option( 'gdpr_disable_css', false ); - add_option( 'gdpr_enable_telemetry_tracker', false ); add_option( 'gdpr_use_recaptcha', false ); add_option( 'gdpr_recaptcha_site_key', '' ); add_option( 'gdpr_recaptcha_secret_key', '' ); diff --git a/includes/class-gdpr-deactivator.php b/includes/class-gdpr-deactivator.php index f0c4463c..24ecf315 100755 --- a/includes/class-gdpr-deactivator.php +++ b/includes/class-gdpr-deactivator.php @@ -32,7 +32,6 @@ class GDPR_Deactivator { * @author Fernando Claussen */ public static function deactivate() { - wp_clear_scheduled_hook( 'telemetry_cleanup' ); } } diff --git a/includes/class-gdpr.php b/includes/class-gdpr.php index 449e815b..fc58f701 100755 --- a/includes/class-gdpr.php +++ b/includes/class-gdpr.php @@ -96,11 +96,6 @@ private function load_dependencies() { */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-gdpr-audit-log.php'; - /** - * The class responsible for defining the telemetry post type. - */ - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-gdpr-telemetry.php'; - /** * The class responsible for defining the requests section of the plugin. */ @@ -175,7 +170,6 @@ private function define_admin_hooks() { $plugin_admin = new GDPR_Admin( $this->get_plugin_name(), $this->get_version() ); $requests_admin = new GDPR_Requests_Admin( $this->get_plugin_name(), $this->get_version() ); - $telemetry = new GDPR_Telemetry( $this->get_plugin_name(), $this->get_version() ); $requests = new GDPR_Requests( $this->get_plugin_name(), $this->get_version() ); $plugin_emails = new GDPR_Email(); $woo_add_to_registration = get_option( 'gdpr_add_consent_checkboxes_registration', false ); @@ -213,7 +207,6 @@ private function define_admin_hooks() { add_action( 'wp_ajax_gdpr_audit_log', array( $plugin_admin, 'audit_log' ) ); add_action( 'admin_post_gdpr_data_breach', array( $plugin_admin, 'send_data_breach_confirmation_email' ) ); add_action( 'clean_gdpr_data_breach_request', array( $plugin_admin, 'clean_data_breach_request' ), 10, 2 ); // CRON JOB - add_action( 'telemetry_cleanup', array( $plugin_admin, 'telemetry_cleanup' ) ); // CRON JOB add_action( 'admin_post_gdpr_delete_user', array( $requests_admin, 'delete_user' ) ); add_action( 'admin_post_gdpr_cancel_request', array( $requests_admin, 'cancel_request' ) ); @@ -222,13 +215,6 @@ private function define_admin_hooks() { add_action( 'wp_ajax_gdpr_anonymize_comments', array( $requests_admin, 'anonymize_comments' ) ); add_action( 'wp_ajax_gdpr_reassign_content', array( $requests_admin, 'reassign_content' ) ); - add_action( 'init', array( $telemetry, 'register_post_type' ) ); - add_filter( 'http_api_debug', array( $telemetry, 'log_request' ), 10, 5 ); - add_filter( 'manage_telemetry_posts_columns', array( $telemetry, 'manage_columns' ) ); - add_filter( 'manage_telemetry_posts_custom_column', array( $telemetry, 'custom_column' ), 10, 2 ); - add_filter( 'restrict_manage_posts', array( $telemetry, 'actions_above_table' ) ); - add_filter( 'views_edit-telemetry', '__return_null' ); - // CRON JOBS add_action( 'clean_gdpr_requests', array( $requests, 'clean_requests' ) ); add_action( 'clean_gdpr_user_request_key', array( $requests, 'clean_user_request_key' ), 10, 2 ); From ca5759d13757b3f804fb90e0f4cbf7f987d42de7 Mon Sep 17 00:00:00 2001 From: Fernando Claussen Date: Tue, 17 Jul 2018 15:18:38 -0400 Subject: [PATCH 02/12] Move Public Partials to Templates for overriding (#216) * Moving public partials to the templates folder * Add new class to handle template loading * Change email class to load emails the new way * Revert "Add initial compatibility to old php (array_filter function) (#192)" This reverts commit be3f39945eeffb7173e3e3fef313bce8065a5ff4. * Slipping one compatibility function here * Finish moving templates out of the partials folder * Calling the templates from the templates folder * Minor adjustments * Slipping another compatibility function change into this branch --- includes/class-gdpr-email.php | 63 ++----------------- includes/class-gdpr-templates.php | 62 ++++++++++++++++++ includes/class-gdpr.php | 2 +- includes/compatibility-functions.php | 22 ++----- public/class-gdpr-public.php | 28 +++++++-- public/class-gdpr-requests-public.php | 4 +- .../forms}/complaint-form.php | 2 +- .../forms}/delete-form.php | 2 +- .../forms}/export-data-form.php | 2 +- templates/forms/index.php | 1 + .../forms}/rectify-form.php | 2 +- templates/index.php | 1 + .../partials => templates}/privacy-bar.php | 8 +-- .../privacy-preferences-modal.php | 32 +++++----- .../partials => templates}/reconsent-bar.php | 2 +- .../reconsent-modal.php | 26 +++----- 16 files changed, 131 insertions(+), 128 deletions(-) create mode 100644 includes/class-gdpr-templates.php rename {public/partials => templates/forms}/complaint-form.php (87%) rename {public/partials => templates/forms}/delete-form.php (88%) rename {public/partials => templates/forms}/export-data-form.php (84%) create mode 100644 templates/forms/index.php rename {public/partials => templates/forms}/rectify-form.php (87%) create mode 100644 templates/index.php rename {public/partials => templates}/privacy-bar.php (85%) rename {public/partials => templates}/privacy-preferences-modal.php (82%) rename {public/partials => templates}/reconsent-bar.php (93%) rename {public/partials => templates}/reconsent-modal.php (74%) diff --git a/includes/class-gdpr-email.php b/includes/class-gdpr-email.php index a855f117..3ecbd57c 100644 --- a/includes/class-gdpr-email.php +++ b/includes/class-gdpr-email.php @@ -10,6 +10,8 @@ * @author Fernando Claussen */ +require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-gdpr-templates.php'; + /** * Handles emailing users. * @@ -19,63 +21,6 @@ * @author Fernando Claussen */ class GDPR_Email { - /** - * Locate template. - * - * Locate the called template. - * Search Order: - * 1. /themes/theme/gdpr/templates/email/$template_name - * 2. /plugins/gdpr/templates/$template_name. - * - * @since 1.0.0 - * @author Fernando Claussen - * @access private - * @static - * @param string $template_name Template to load. - * @return string Path to the template file. - */ - private static function locate_template( $template_name ) { - // Set variable to search in gdpr folder of theme. - $theme_path = 'gdpr/email/'; - - // Set default plugin templates path. - $plugin_path = plugin_dir_path( dirname( __FILE__ ) ) . 'templates/email/'; // Path to the template folder - - // Search template file in theme folder. - $template = locate_template( - array( - $theme_path . $template_name, - ) - ); - - // Get plugins template file. - if ( ! $template ) { - $template = $plugin_path . $template_name; - } - return $template; - } - - /** - * Get template. - * - * Search for the template and include the file. - * - * @since 1.0.0 - * @author Fernando Claussen - * @access private - * @static - * @param string $template_name Template to load. - * @param array $args Arguments passed to the template file. - */ - private static function get_template( $template_name, $args = array() ) { - $template_file = self::locate_template( $template_name ); - - if ( ! file_exists( $template_file ) ) { - return; - } - include $template_file; - } - /** * Get the email content from the correct file. * @since 1.0.0 @@ -87,7 +32,7 @@ private static function get_template( $template_name, $args = array() ) { */ public static function get_email_content( $template_name, $args = array() ) { ob_start(); - self::get_template( $template_name, $args ); + GDPR_Templates::get_template( $template_name, $args ); return ob_get_clean(); } @@ -224,7 +169,7 @@ public static function send( $emails, $type, $args = array(), $attachments = arr $headers[] = 'Bcc: ' . sanitize_email( $email ); } - $content = self::get_email_content( $type . '.php', $args ); + $content = self::get_email_content( 'email/' . $type . '.php', $args ); return wp_mail( $no_reply, diff --git a/includes/class-gdpr-templates.php b/includes/class-gdpr-templates.php new file mode 100644 index 00000000..8b15f93c --- /dev/null +++ b/includes/class-gdpr-templates.php @@ -0,0 +1,62 @@ + + * @access private + * @static + * @param string $template_name Template to load. + * @return string Path to the template file. + */ + private static function locate_template( $template_name ) { + // Set variable to search in gdpr folder of theme. + $theme_path = 'gdpr/'; + + // Set default plugin templates path. + $plugin_path = plugin_dir_path( dirname( __FILE__ ) ) . 'templates/'; // Path to the template folder + + // Search template file in theme folder. + $template = locate_template( + array( + $theme_path . $template_name, + ) + ); + + // Get plugins template file. + if ( ! $template ) { + $template = $plugin_path . $template_name; + } + return $template; + } + + /** + * Get template. + * + * Search for the template and include the file. + * + * @since 1.0.0 + * @author Fernando Claussen + * @access private + * @static + * @param string $template_name Template to load. + * @param array $args Arguments passed to the template file. + */ + public static function get_template( $template_name, $args = array() ) { + $template_file = self::locate_template( $template_name ); + + if ( ! file_exists( $template_file ) ) { + return; + } + include $template_file; + } + +} diff --git a/includes/class-gdpr.php b/includes/class-gdpr.php index fc58f701..51b14476 100755 --- a/includes/class-gdpr.php +++ b/includes/class-gdpr.php @@ -329,7 +329,7 @@ public static function get_consent_checkboxes( $consent_key = false ) { ); if ( $consent_key ) { - $consent_types = array_filter_compat( + $consent_types = array_filter( $consent_types, function( $key ) use ( $consent_key ) { return $key === $consent_key; }, ARRAY_FILTER_USE_KEY diff --git a/includes/compatibility-functions.php b/includes/compatibility-functions.php index 3e3f9ddd..a18431cf 100644 --- a/includes/compatibility-functions.php +++ b/includes/compatibility-functions.php @@ -5,22 +5,8 @@ * @package GDPR */ -/** - * compatibility function array_filter before php 5.6 - * $flag is new in php 5.6 - */ -function array_filter_compat( array $array, $callback, $flag = 0 ) { - if ( $flag == 0 ) { - return array_filter( $array, $callback ); - } - elseif ( $flag == ARRAY_FILTER_USE_KEY ) { - $matchedKeys = array_filter( array_keys( $array ), $callback ); - return array_intersect_key( $array, array_flip( $matchedKeys ) ); - } - else { /* ARRAY_FILTER_USE_BOTH */ - $matchedKeys = array_filter(array_keys( $array ), $callback ); - $matchedValues = array_filter( $array, $callback ); - return array_intersect_key( $array, array_flip( $matchedKeys ) + $matchedValues ); - } +if( ! function_exists( 'boolval' ) ) { + function boolval( $var ){ + return (bool) $var; + } } - diff --git a/public/class-gdpr-public.php b/public/class-gdpr-public.php index c17a56e9..bb44ced5 100755 --- a/public/class-gdpr-public.php +++ b/public/class-gdpr-public.php @@ -11,6 +11,8 @@ * @author Fernando Claussen */ +require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-gdpr-templates.php'; + /** * The public-facing functionality of the plugin. * @@ -158,7 +160,12 @@ public function privacy_bar() { return; } - include plugin_dir_path( __FILE__ ) . 'partials/privacy-bar.php'; + GDPR_Templates::get_template( 'privacy-bar.php', array( + 'content' => $content, + 'registered_cookies' => $registered_cookies, + 'show_cookie_cat_checkboxes' => $show_cookie_cat_checkboxes, + 'button_text' => $button_text, + ) ); } /** @@ -178,7 +185,14 @@ public function privacy_preferences_modal() { return; } - include plugin_dir_path( __FILE__ ) . 'partials/privacy-preferences-modal.php'; + GDPR_Templates::get_template( 'privacy-preferences-modal.php', array( + 'cookie_privacy_excerpt' => $cookie_privacy_excerpt, + 'consent_types' => $consent_types, + 'approved_cookies' => $approved_cookies, + 'user_consents' => $user_consents, + 'tabs' => $tabs, + 'allowed_html' => $this->allowed_html, + ) ); } /** @@ -297,7 +311,7 @@ public function is_consent_needed() { return; } - $updated_consents = array_filter_compat( + $updated_consents = array_filter( $required_consents, function( $consent, $consent_id ) use ( $user_consents ) { return ! in_array( $consent_id, $user_consents, true ); }, ARRAY_FILTER_USE_BOTH @@ -310,9 +324,13 @@ public function is_consent_needed() { $reconsent_template = get_option( 'gdpr_reconsent_template', 'modal' ); if ( 'bar' === $reconsent_template ) { - include plugin_dir_path( __FILE__ ) . 'partials/reconsent-bar.php'; + GDPR_Templates::get_template( 'reconsent-bar.php', array( + 'updated_consents' => $updated_consents, + ) ); } else { - include plugin_dir_path( __FILE__ ) . 'partials/reconsent-modal.php'; + GDPR_Templates::get_template( 'reconsent-modal.php', array( + 'updated_consents' => $updated_consents, + ) ); } } diff --git a/public/class-gdpr-requests-public.php b/public/class-gdpr-requests-public.php index 90f1c1d8..c38d64f9 100644 --- a/public/class-gdpr-requests-public.php +++ b/public/class-gdpr-requests-public.php @@ -11,6 +11,8 @@ * @author Fernando Claussen */ +require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-gdpr-templates.php'; + /** * The public facing requests functionality of the plugin. * @@ -64,7 +66,7 @@ public static function request_form( $type, $submit_button_text = '' ) { } ob_start(); - include plugin_dir_path( dirname( __FILE__ ) ) . 'public/partials/' . $type . '-form.php'; + GDPR_Templates::get_template( 'forms/' . $type . '-form.php', array( 'submit_button_text' => $submit_button_text ) ); return ob_get_clean(); } diff --git a/public/partials/complaint-form.php b/templates/forms/complaint-form.php similarity index 87% rename from public/partials/complaint-form.php rename to templates/forms/complaint-form.php index c5020f04..4cfd9eff 100644 --- a/public/partials/complaint-form.php +++ b/templates/forms/complaint-form.php @@ -8,6 +8,6 @@ - + diff --git a/public/partials/delete-form.php b/templates/forms/delete-form.php similarity index 88% rename from public/partials/delete-form.php rename to templates/forms/delete-form.php index 3d723c58..a45bb511 100644 --- a/public/partials/delete-form.php +++ b/templates/forms/delete-form.php @@ -19,6 +19,6 @@ - + diff --git a/public/partials/export-data-form.php b/templates/forms/export-data-form.php similarity index 84% rename from public/partials/export-data-form.php rename to templates/forms/export-data-form.php index 7e27772d..a36cc3ef 100644 --- a/public/partials/export-data-form.php +++ b/templates/forms/export-data-form.php @@ -6,6 +6,6 @@ - + diff --git a/templates/forms/index.php b/templates/forms/index.php new file mode 100644 index 00000000..8142269b --- /dev/null +++ b/templates/forms/index.php @@ -0,0 +1 @@ + - + diff --git a/templates/index.php b/templates/index.php new file mode 100644 index 00000000..8142269b --- /dev/null +++ b/templates/index.php @@ -0,0 +1 @@ +
-

+

- +
diff --git a/public/partials/privacy-preferences-modal.php b/templates/privacy-preferences-modal.php similarity index 82% rename from public/partials/privacy-preferences-modal.php rename to templates/privacy-preferences-modal.php index 62f35dd0..ccca008d 100755 --- a/public/partials/privacy-preferences-modal.php +++ b/templates/privacy-preferences-modal.php @@ -30,12 +30,12 @@
  • - - -
  • + + +
    • $tab ) { + foreach ( $args['tabs'] as $key => $tab ) { if ( ( isset( $tab['cookies_used'] ) && empty( $tab['cookies_used'] ) ) && ( isset( $tab['hosts'] ) && empty( $tab['hosts'] ) ) ) { continue; } @@ -47,8 +47,8 @@
      - - $type ) : ?> + + $type ) : ?>
      -

      - - $type ) : ?> +

      + + $type ) : ?>
      - allowed_html ); ?> +
      @@ -92,7 +92,7 @@
- $tab ) : ?> + $tab ) : ?>

@@ -107,12 +107,12 @@ $site_cookies = array(); $enabled = ( 'off' === $tab['status'] ) ? false : true; $cookies_used = explode( ',', $tab['cookies_used'] ); - $approved_cookies = isset( $_COOKIE['gdpr']['allowed_cookies'] ) ? json_decode( sanitize_text_field( wp_unslash( $_COOKIE['gdpr']['allowed_cookies'] ) ) ) : array(); // WPCS: input var ok. + $args['approved_cookies'] = isset( $_COOKIE['gdpr']['allowed_cookies'] ) ? json_decode( sanitize_text_field( wp_unslash( $_COOKIE['gdpr']['allowed_cookies'] ) ) ) : array(); // WPCS: input var ok. foreach ( $cookies_used as $cookie ) { $site_cookies[] = trim( $cookie ); $all_cookies[] = trim( $cookie ); - if ( ! empty( $approved_cookies ) && isset( $_COOKIE['gdpr']['privacy_bar'] ) ) { - if ( in_array( trim( $cookie ), $approved_cookies, true ) ) { + if ( ! empty( $args['approved_cookies'] ) && isset( $_COOKIE['gdpr']['privacy_bar'] ) ) { + if ( in_array( trim( $cookie ), $args['approved_cookies'], true ) ) { $enabled = true; } else { $enabled = false; @@ -123,7 +123,7 @@ - +
    - $consent ) : ?> + $consent ) : ?>
  • diff --git a/public/partials/reconsent-modal.php b/templates/reconsent-modal.php similarity index 74% rename from public/partials/reconsent-modal.php rename to templates/reconsent-modal.php index 67a12afe..6a1a9339 100755 --- a/public/partials/reconsent-modal.php +++ b/templates/reconsent-modal.php @@ -26,37 +26,25 @@
      - - -
    • + + +
      • $consent ) : + foreach ( $args['updated_consents'] as $consent_id => $consent ) : echo '
      • ' . esc_html( $consent['name'] ) . '
      • '; $policy_counter++; - endforeach + endforeach; ?>
    -
      - - $type ) : ?> - -
    • - - -
    - $consent ) : ?> + $consent ) : ?>

    @@ -81,7 +69,7 @@