From 398c40c7d5a8a5d9246e6ffde2100da6e2d57eb6 Mon Sep 17 00:00:00 2001 From: Jonathan De Jong Date: Tue, 12 Mar 2019 13:10:15 +0100 Subject: [PATCH 1/7] fixed js errors due to unset options and formatting on main class --- assets/js/custom-cookie-message-popup.js | 11 ++++++----- src/class-main.php | 15 ++++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/assets/js/custom-cookie-message-popup.js b/assets/js/custom-cookie-message-popup.js index a943a8e..ef10886 100644 --- a/assets/js/custom-cookie-message-popup.js +++ b/assets/js/custom-cookie-message-popup.js @@ -127,19 +127,20 @@ jQuery( function ( $ ) { get_height.remove(); - /* banner animation */ - if ( 'scroll' === customCookieMessageLocalize.options.styles.banner_animation ) { + /* banner animation */ + /* First make sure we even have these settings. */ + if ( typeof customCookieMessageLocalize.options.styles.banner_animation != 'undefined' && 'scroll' === customCookieMessageLocalize.options.styles.banner_animation ) { $( '#custom-cookie-message-banner' ).slideDown(); } else - if ( 'fade' === customCookieMessageLocalize.options.styles.banner_animation ) { + if ( typeof customCookieMessageLocalize.options.styles.banner_animation != 'undefined' && 'fade' === customCookieMessageLocalize.options.styles.banner_animation ) { $( '#custom-cookie-message-banner' ).fadeIn(); } else { $( '#custom-cookie-message-banner' ).show(); } /* Scroll content container */ - if ( 'yes' === customCookieMessageLocalize.options.styles.scroll_body ) { - if ( 'bottom-fixed' === customCookieMessageLocalize.options.general.location_options ) { + if ( typeof customCookieMessageLocalize.options.styles.scroll_body != 'undefined' && 'yes' === customCookieMessageLocalize.options.styles.scroll_body ) { + if ( typeof customCookieMessageLocalize.options.general.location_options != 'undefined' && 'bottom-fixed' === customCookieMessageLocalize.options.general.location_options ) { $( 'body' ).animate({marginBottom: scroll_height}); } else { diff --git a/src/class-main.php b/src/class-main.php index 0a014a1..6b8f3f5 100644 --- a/src/class-main.php +++ b/src/class-main.php @@ -185,7 +185,7 @@ public static function update() { } } - // Is empty, nani? + // Bail early if empty. if ( empty( $update_queue ) ) { return; } @@ -237,7 +237,8 @@ protected function ccm_patter_list( $pattern_array ) { } $pattern_array = array_filter( - $pattern_array, function ( $value ) { + $pattern_array, + function ( $value ) { return '' !== trim( $value ); } ); @@ -245,7 +246,8 @@ protected function ccm_patter_list( $pattern_array ) { $pattern_array = array_map( function ( $pattern ) { return '(' . trim( $pattern ) . ')'; - }, $pattern_array + }, + $pattern_array ); return implode( '|', $pattern_array ); @@ -288,7 +290,9 @@ public function display_frontend_notice() { wp_add_inline_style( 'custom-cookie-message-popup-styles', $this->custom_css() ); wp_enqueue_script( 'custom-cookie-message-popup', CUSTOM_COOKIE_MESSAGE_PLUGIN_URL . '/assets/js/custom-cookie-message-popup.js', [ 'jquery' ], $this->version, true ); wp_localize_script( - 'custom-cookie-message-popup', 'customCookieMessageLocalize', [ + 'custom-cookie-message-popup', + 'customCookieMessageLocalize', + [ 'options' => get_option( 'custom_cookie_message' ), 'wp_rest_nonce' => wp_create_nonce( 'wp_rest' ), 'rest_url_banner' => rest_url( 'custom-cm/banner' ), @@ -362,7 +366,8 @@ protected function custom_css() { $css .= sprintf( 'background-color: %s;', $styles['button_color_picker'] ); $css .= sprintf( 'color: %s;', $styles['button_text_color_picker'] ); $css .= sprintf( - 'padding: %spx %spx;', $styles['button_height_slider_amount'], + 'padding: %spx %spx;', + $styles['button_height_slider_amount'], $styles['button_width_slider_amount'] ); $css .= '}'; From 93c3aa0d898fe7bafdf350662a1c75580a0bcce8 Mon Sep 17 00:00:00 2001 From: Jonathan De Jong Date: Tue, 12 Mar 2019 13:24:15 +0100 Subject: [PATCH 2/7] refactor --- assets/js/custom-cookie-message-popup.js | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/assets/js/custom-cookie-message-popup.js b/assets/js/custom-cookie-message-popup.js index ef10886..1645e97 100644 --- a/assets/js/custom-cookie-message-popup.js +++ b/assets/js/custom-cookie-message-popup.js @@ -128,25 +128,25 @@ jQuery( function ( $ ) { get_height.remove(); /* banner animation */ - /* First make sure we even have these settings. */ - if ( typeof customCookieMessageLocalize.options.styles.banner_animation != 'undefined' && 'scroll' === customCookieMessageLocalize.options.styles.banner_animation ) { + if ( typeof customCookieMessageLocalize.options.styles != 'undefined' ) { + if ( typeof customCookieMessageLocalize.options.styles.banner_animation != 'undefined' && 'scroll' === customCookieMessageLocalize.options.styles.banner_animation ) { $( '#custom-cookie-message-banner' ).slideDown(); - } else - if ( typeof customCookieMessageLocalize.options.styles.banner_animation != 'undefined' && 'fade' === customCookieMessageLocalize.options.styles.banner_animation ) { + } else if ( typeof customCookieMessageLocalize.options.styles.banner_animation != 'undefined' && 'fade' === customCookieMessageLocalize.options.styles.banner_animation ) { $( '#custom-cookie-message-banner' ).fadeIn(); } - else { - $( '#custom-cookie-message-banner' ).show(); - } - /* Scroll content container */ - if ( typeof customCookieMessageLocalize.options.styles.scroll_body != 'undefined' && 'yes' === customCookieMessageLocalize.options.styles.scroll_body ) { - if ( typeof customCookieMessageLocalize.options.general.location_options != 'undefined' && 'bottom-fixed' === customCookieMessageLocalize.options.general.location_options ) { - $( 'body' ).animate({marginBottom: scroll_height}); - } - else { - $( 'body' ).animate({marginTop: scroll_height}); - } - } + } else { + $( '#custom-cookie-message-banner' ).show(); + } + + /* Scroll content container */ + if ( typeof customCookieMessageLocalize.options.styles.scroll_body != 'undefined' && 'yes' === customCookieMessageLocalize.options.styles.scroll_body ) { + if ( typeof customCookieMessageLocalize.options.general.location_options != 'undefined' && 'bottom-fixed' === customCookieMessageLocalize.options.general.location_options ) { + $( 'body' ).animate({marginBottom: scroll_height}); + } + else { + $( 'body' ).animate({marginTop: scroll_height}); + } + } } else { console.warn( 'Custom Cookie Message options are not set' ); From c8963992664e66807f7c5cb541daa03cae41c0b4 Mon Sep 17 00:00:00 2001 From: Jonathan De Jong Date: Tue, 12 Mar 2019 13:30:53 +0100 Subject: [PATCH 3/7] lower object tree --- assets/js/custom-cookie-message-popup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/custom-cookie-message-popup.js b/assets/js/custom-cookie-message-popup.js index 1645e97..df300aa 100644 --- a/assets/js/custom-cookie-message-popup.js +++ b/assets/js/custom-cookie-message-popup.js @@ -139,7 +139,7 @@ jQuery( function ( $ ) { } /* Scroll content container */ - if ( typeof customCookieMessageLocalize.options.styles.scroll_body != 'undefined' && 'yes' === customCookieMessageLocalize.options.styles.scroll_body ) { + if ( typeof customCookieMessageLocalize.options.styles != 'undefined' && 'yes' === customCookieMessageLocalize.options.styles.scroll_body ) { if ( typeof customCookieMessageLocalize.options.general.location_options != 'undefined' && 'bottom-fixed' === customCookieMessageLocalize.options.general.location_options ) { $( 'body' ).animate({marginBottom: scroll_height}); } From ee9e57a8d205557a530fdadbb6f815948aa8d8d7 Mon Sep 17 00:00:00 2001 From: Jonathan De Jong Date: Tue, 12 Mar 2019 13:38:22 +0100 Subject: [PATCH 4/7] removed update notice etc. --- assets/js/custom-cookie-message-popup.js | 2 +- src/class-main.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/assets/js/custom-cookie-message-popup.js b/assets/js/custom-cookie-message-popup.js index df300aa..67d2835 100644 --- a/assets/js/custom-cookie-message-popup.js +++ b/assets/js/custom-cookie-message-popup.js @@ -113,7 +113,7 @@ jQuery( function ( $ ) { }, } ) .done( function ( response ) { - if ( null !== response.template && '' !== customCookieMessageLocalize.options ) { + if ( null !== response.template && typeof customCookieMessageLocalize.options != 'undefined' ) { if ( 'bottom-fixed' === customCookieMessageLocalize.options.general.location_options ) { $( 'body' ).append( response.template ); } diff --git a/src/class-main.php b/src/class-main.php index 6b8f3f5..3416766 100644 --- a/src/class-main.php +++ b/src/class-main.php @@ -122,7 +122,8 @@ public function init() { add_action( 'upgrader_process_complete', [ __CLASS__, 'update' ] ); - add_action( 'admin_notices', [ __CLASS__, 'admin_notices' ] ); + // NO! We do NOT spam users with update notices! - Jonathan + //add_action( 'admin_notices', [ __CLASS__, 'admin_notices' ] ); } add_action( 'wp_footer', [ $this, 'display_frontend_notice' ] ); From 430849c444d8ee3099ea235f4d3354b89c8e93da Mon Sep 17 00:00:00 2001 From: Jonathan De Jong Date: Tue, 12 Mar 2019 14:16:56 +0100 Subject: [PATCH 5/7] test --- assets/js/custom-cookie-message-popup.js | 56 ++++++++++++------------ templates/cookie-notice.php | 6 ++- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/assets/js/custom-cookie-message-popup.js b/assets/js/custom-cookie-message-popup.js index 67d2835..ce41947 100644 --- a/assets/js/custom-cookie-message-popup.js +++ b/assets/js/custom-cookie-message-popup.js @@ -113,40 +113,40 @@ jQuery( function ( $ ) { }, } ) .done( function ( response ) { - if ( null !== response.template && typeof customCookieMessageLocalize.options != 'undefined' ) { + if ( null !== response.template && typeof customCookieMessageLocalize.options.general != 'undefined' ) { if ( 'bottom-fixed' === customCookieMessageLocalize.options.general.location_options ) { $( 'body' ).append( response.template ); } else { $( 'body' ).prepend( response.template ); } - /* Get height of the banner before showing it */ - var get_height = $( '#custom-cookie-message-banner' ).clone().attr("id", false).css({display:"block", position:"absolute"}); - $( 'body' ).append(get_height); - var scroll_height = get_height.outerHeight(); - - get_height.remove(); - - /* banner animation */ - if ( typeof customCookieMessageLocalize.options.styles != 'undefined' ) { - if ( typeof customCookieMessageLocalize.options.styles.banner_animation != 'undefined' && 'scroll' === customCookieMessageLocalize.options.styles.banner_animation ) { - $( '#custom-cookie-message-banner' ).slideDown(); - } else if ( typeof customCookieMessageLocalize.options.styles.banner_animation != 'undefined' && 'fade' === customCookieMessageLocalize.options.styles.banner_animation ) { - $( '#custom-cookie-message-banner' ).fadeIn(); - } - } else { - $( '#custom-cookie-message-banner' ).show(); - } - - /* Scroll content container */ - if ( typeof customCookieMessageLocalize.options.styles != 'undefined' && 'yes' === customCookieMessageLocalize.options.styles.scroll_body ) { - if ( typeof customCookieMessageLocalize.options.general.location_options != 'undefined' && 'bottom-fixed' === customCookieMessageLocalize.options.general.location_options ) { - $( 'body' ).animate({marginBottom: scroll_height}); - } - else { - $( 'body' ).animate({marginTop: scroll_height}); - } - } + /* Get height of the banner before showing it */ + var get_height = $( '#custom-cookie-message-banner' ).clone().attr("id", false).css({display:"block", position:"absolute"}); + $( 'body' ).append(get_height); + var scroll_height = get_height.outerHeight(); + + get_height.remove(); + + /* banner animation */ + if ( typeof customCookieMessageLocalize.options.styles != 'undefined' ) { + if ( typeof customCookieMessageLocalize.options.styles.banner_animation != 'undefined' && 'scroll' === customCookieMessageLocalize.options.styles.banner_animation ) { + $( '#custom-cookie-message-banner' ).slideDown(); + } else if ( typeof customCookieMessageLocalize.options.styles.banner_animation != 'undefined' && 'fade' === customCookieMessageLocalize.options.styles.banner_animation ) { + $( '#custom-cookie-message-banner' ).fadeIn(); + } + } else { + $( '#custom-cookie-message-banner' ).show(); + } + + /* Scroll content container */ + if ( typeof customCookieMessageLocalize.options.styles != 'undefined' && 'yes' === customCookieMessageLocalize.options.styles.scroll_body ) { + if ( typeof customCookieMessageLocalize.options.general.location_options != 'undefined' && 'bottom-fixed' === customCookieMessageLocalize.options.general.location_options ) { + $( 'body' ).animate({marginBottom: scroll_height}); + } + else { + $( 'body' ).animate({marginTop: scroll_height}); + } + } } else { console.warn( 'Custom Cookie Message options are not set' ); diff --git a/templates/cookie-notice.php b/templates/cookie-notice.php index 42bb194..2afecc6 100644 --- a/templates/cookie-notice.php +++ b/templates/cookie-notice.php @@ -20,6 +20,8 @@ $esc_html = 'pll_e'; } +error_log( print_r( $esc_html, true ) ); + $functional_check = 'checked'; $advertising_check = 'checked'; @@ -46,9 +48,9 @@