From bb904b81aa4a293f71cba07e7e843158afe84369 Mon Sep 17 00:00:00 2001 From: uttam sharma Date: Wed, 17 Oct 2018 18:31:19 +0530 Subject: [PATCH 1/3] added rating notice --- classes/class-bsf-sb-sidebar.php | 12 + includes/assets/css/sidebar-manager.css | 39 +++ .../assets/images/sidebar-manager-icon.png | Bin 0 -> 3674 bytes includes/lib/notices/class-astra-notices.php | 308 ++++++++++++++++++ includes/lib/notices/notices.js | 94 ++++++ sidebar-manager.php | 56 ++++ 6 files changed, 509 insertions(+) create mode 100644 includes/assets/css/sidebar-manager.css create mode 100644 includes/assets/images/sidebar-manager-icon.png create mode 100644 includes/lib/notices/class-astra-notices.php create mode 100644 includes/lib/notices/notices.js diff --git a/classes/class-bsf-sb-sidebar.php b/classes/class-bsf-sb-sidebar.php index 1c22d6a..e468c7b 100644 --- a/classes/class-bsf-sb-sidebar.php +++ b/classes/class-bsf-sb-sidebar.php @@ -43,6 +43,18 @@ public static function get_instance() { */ public function __construct() { $this->load_actions(); + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); + } + + /** + * Enqueue Admin Scripts + * + * @since 1.0.0 + */ + public function enqueue_admin_scripts() { + + wp_enqueue_style( 'bsf-sidebar-manager-css', BSF_SB_URL . 'includes/assets/css/sidebar-manager.css', array(), BSF_SB_VER ); + } /** diff --git a/includes/assets/css/sidebar-manager.css b/includes/assets/css/sidebar-manager.css new file mode 100644 index 0000000..591a12e --- /dev/null +++ b/includes/assets/css/sidebar-manager.css @@ -0,0 +1,39 @@ +.astra-review-notice-container { + display: flex; + align-items: center; + padding-top: 10px; +} + +.astra-review-notice-container .dashicons { + font-size: 1.4em; + padding-left: 10px; +} + +.astra-review-notice-container a { + padding-left: 5px; + text-decoration: none; +} + +.astra-review-notice-container .dashicons:first-child { + padding-left: 0; +} + +.notice-image img { + max-width: 90px; +} + +.notice-content .notice-heading { + padding-bottom: 5px; +} + +.notice-content { + margin-left: 15px; +} + +.notice-container { + padding-top: 10px; + padding-bottom: 10px; + display: flex; + justify-content: left; + align-items: center; +} \ No newline at end of file diff --git a/includes/assets/images/sidebar-manager-icon.png b/includes/assets/images/sidebar-manager-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1c8c6cb55b8db03566bf9ccb20bed5ae218c7925 GIT binary patch literal 3674 zcmaJ^2{@E%`+rSj8CxOQ$557I9ox(xgRz!fH6e^K7|dd3m_ai3B^8BeQ94rM&_bnb z2{EWhS+b-YTZJqk+c(a4I$ziSI{n}4eeY+ve)sSG-OqEs*ZaI_&W<)h0@4Bi00`OH zqFp&HYy08b$+6E4VB0y36x|9#cOwVT8CWVFF!v|>;URWJY#`nhkM)lXYr~rWzz!(E z9Ye=B975vAL@n$#MvFzzfqXrH-4irm# z5WzNzig$~0bjL-7;1K>$vjY$lCXz!y#M7}5CNY#mLo!XFfAJzY{q1RODC92)J;W6H zUr`tbXNV=4iia3z>1pD0baf$yhFZG%28M>Z8W5O{E=*g8a~o>v>LU#dkuW33-xrh< zjp`qObVXbL9g8zEg$B{-6r{E`gTc^Z=xLFuf!ewV1Y(;52GisqG-;6}I+m$PqAC4g zK;vmRDuF^LkV%kjMyww>oNfx`DE)5=M9M$3B--E0#91(HCYGYDtEID@(hs16!~YK@ z68}Nd=&tzx>HSw?ntLP#ukDJbk;ADt&c+2OZHJ;DEva}colJEnlS6;3qH_?LPNoHs zDG*CHLx}280?D7upsD?ZcW^-3k!W-*35T~sn?gAZS_FbW5^i7sv(!cCz^$yzb#<+b z%wcFW+7fMOXbm^iH-}mO@I{kx;Y2)%{=?V*f4;iE^xZB6B83wfji(YK@c!0RG7<7u z%1FX5wZN@@$@jOf|1Y(`t$*pO%@L!$y|F)S^p7b{^=xX&t(M9@LwbR5cCInlqDDF0|A z7GY$x7Su>G?C;#D%WqGtWz24D(drgfwrCMXM2B$P@2S~5XIY{oi-@_PcEL@z@X@3b z?56NmCy~w9=7>joNKi_*4-EiAEvy&eM5>*Dwe>OAb0oN6rk7VsTs?||gghPGY zRb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??N5F8)1~~AvamRax@G&uY8>DPA$__=!IEHbOmU&HpI_?tmF8R<7lzIK zQxO9o$^w8)d9{2K@7Z*+Dj3786p1flckAQ%0HbJ{Lj%TaKHmA0O&PEGHAs^e@wL3j zbe#|OoB^@R;&lpWM%FYdD{3<<7E&?>qnw*7wRvY_a2_64EQWg5t1o;uDZL%`#b1b> zA{l1b5NzyG^li4jz9)pQq?+HBZyp^Yag#Sy40F$FO%OUzGgocJj2l>byIZu-PouKV zIH+Q;DCoVp=&}JXeDP@MzM(0H%#}hg#N4v=_0yyB3se+G-FWDFu&gwJEQb1m@7eRp@$p~_hcz-(Y zjk<#7jA{l?EkIEGobzDzwct3il{#3Si~a0y!`py&TReM#fY;w;)pal3-~QXPvvNe2 ITlmKR2cd{PfB*mh literal 0 HcmV?d00001 diff --git a/includes/lib/notices/class-astra-notices.php b/includes/lib/notices/class-astra-notices.php new file mode 100644 index 0000000..0d40532 --- /dev/null +++ b/includes/lib/notices/class-astra-notices.php @@ -0,0 +1,308 @@ + Create custom close notice link in the notice markup. E.g. + * `` + * It close the notice for 30 days. + * + * @package Astra Sites + * @since 1.4.0 + */ + +if ( ! class_exists( 'Astra_Notices' ) ) : + + /** + * Astra_Notices + * + * @since 1.4.0 + */ + class Astra_Notices { + + /** + * Notices + * + * @access private + * @var array Notices. + * @since 1.4.0 + */ + private static $version = '1.0.0'; + + /** + * Notices + * + * @access private + * @var array Notices. + * @since 1.4.0 + */ + private static $notices = array(); + + /** + * Instance + * + * @access private + * @var object Class object. + * @since 1.4.0 + */ + private static $instance; + + /** + * Initiator + * + * @since 1.4.0 + * @return object initialized object of class. + */ + public static function get_instance() { + if ( ! isset( self::$instance ) ) { + self::$instance = new self; + } + return self::$instance; + } + + /** + * Constructor + * + * @since 1.4.0 + */ + public function __construct() { + add_action( 'admin_notices', array( $this, 'show_notices' ), 30 ); + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + add_action( 'wp_ajax_astra-notice-dismiss', array( $this, 'dismiss_notice' ) ); + add_filter( 'wp_kses_allowed_html', array( $this, 'add_data_attributes' ), 10, 2 ); + } + + /** + * Filters and Returns a list of allowed tags and attributes for a given context. + * + * @param Array $allowedposttags Array of allowed tags. + * @param String $context Context type (explicit). + * @since 1.4.0 + * @return Array + */ + function add_data_attributes( $allowedposttags, $context ) { + $allowedposttags['a']['data-repeat-notice-after'] = true; + + return $allowedposttags; + } + + /** + * Add Notice. + * + * @since 1.4.0 + * @param array $args Notice arguments. + * @return void + */ + public static function add_notice( $args = array() ) { + self::$notices[] = $args; + } + + /** + * Dismiss Notice. + * + * @since 1.4.0 + * @return void + */ + function dismiss_notice() { + $notice_id = ( isset( $_POST['notice_id'] ) ) ? sanitize_key( $_POST['notice_id'] ) : ''; + $repeat_notice_after = ( isset( $_POST['repeat_notice_after'] ) ) ? absint( $_POST['repeat_notice_after'] ) : ''; + + // Valid inputs? + if ( ! empty( $notice_id ) ) { + + if ( ! empty( $repeat_notice_after ) ) { + set_transient( $notice_id, true, $repeat_notice_after ); + } else { + update_user_meta( get_current_user_id(), $notice_id, true ); + } + + wp_send_json_success(); + } + + wp_send_json_error(); + } + + /** + * Enqueue Scripts. + * + * @since 1.4.0 + * @return void + */ + function enqueue_scripts() { + wp_register_script( 'astra-notices', self::_get_uri() . 'notices.js', array( 'jquery' ), null, self::$version ); + } + + /** + * Rating priority sort + * + * @since 1.5.2 + * @param array $array1 array one. + * @param array $array2 array two. + * @return array + */ + function sort_notices( $array1, $array2 ) { + return strnatcmp( $array1['priority'], $array2['priority'] ); + } + + /** + * Notice Types + * + * @since 1.4.0 + * @return void + */ + function show_notices() { + + $defaults = array( + 'id' => '', // Optional, Notice ID. If empty it set `astra-notices-id-<$array-index>`. + 'type' => 'info', // Optional, Notice type. Default `info`. Expected [info, warning, notice, error]. + 'message' => '', // Optional, Message. + 'show_if' => true, // Optional, Show notice on custom condition. E.g. 'show_if' => if( is_admin() ) ? true, false, . + 'repeat-notice-after' => '', // Optional, Dismiss-able notice time. It'll auto show after given time. + 'class' => '', // Optional, Additional notice wrapper class. + 'priority' => 10, // Priority of the notice. + 'display-with-other-notices' => true, // Should the notice be displayed if other notices are being displayed from Astra_Notices. + ); + + // Count for the notices that are rendered. + $notices_displayed = 0; + + // sort the array with priority. + usort( self::$notices, array( $this, 'sort_notices' ) ); + + foreach ( self::$notices as $key => $notice ) { + + $notice = wp_parse_args( $notice, $defaults ); + + $notice['id'] = self::get_notice_id( $notice, $key ); + + $notice['classes'] = self::get_wrap_classes( $notice ); + + // Notices visible after transient expire. + if ( isset( $notice['show_if'] ) && true === $notice['show_if'] ) { + if ( self::is_expired( $notice ) ) { + + // don't display the notice if it is not supposed to be displayed with other notices. + if ( 0 !== $notices_displayed && false === $notice['display-with-other-notices'] ) { + return; + } + + self::markup( $notice ); + $notices_displayed++; + } + } else { + // No transient notices. + self::markup( $notice ); + } + } + + } + + /** + * Markup Notice. + * + * @since 1.4.0 + * @param array $notice Notice markup. + * @return void + */ + public static function markup( $notice = array() ) { + + wp_enqueue_script( 'astra-notices' ); + + ?> +
+
+ +
+
+ 'sidebar-manager-rating', + 'type' => '', + 'message' => sprintf( + '
+
+
', + $image_path, + __( 'Hello! Seems like you have used Astra Hooks to build this website — Thanks a ton!', 'bsfsidebars' ), + __( 'Could you please do us a BIG favor and give it a 5-star rating on WordPress? This would boost our motivation and help other users make a comfortable decision while choosing the Astra Hooks.', 'bsfsidebars' ), + 'https://wordpress.org/support/plugin/sidebar-manager/reviews/?filter=5#new-post', + __( 'Ok, you deserve it', 'bsfsidebars' ), + MONTH_IN_SECONDS, + __( 'Nope, maybe later', 'bsfsidebars' ), + __( 'I already did', 'bsfsidebars' ) + ), + 'repeat-notice-after' => MONTH_IN_SECONDS, + 'priority' => 25, + 'display-with-other-notices' => false, + ) + ); + } + + add_action( 'admin_notices', 'register_notices' ); + +endif; From ffdf3878575509246867735716313b904b26b0bc Mon Sep 17 00:00:00 2001 From: uttam sharma Date: Fri, 19 Oct 2018 18:01:09 +0530 Subject: [PATCH 2/3] updated notice file --- includes/lib/notices/class-astra-notices.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/includes/lib/notices/class-astra-notices.php b/includes/lib/notices/class-astra-notices.php index 0d40532..973b1b0 100644 --- a/includes/lib/notices/class-astra-notices.php +++ b/includes/lib/notices/class-astra-notices.php @@ -145,7 +145,14 @@ function enqueue_scripts() { * @return array */ function sort_notices( $array1, $array2 ) { - return strnatcmp( $array1['priority'], $array2['priority'] ); + if ( ! isset( $array1['priority'] ) ) { + $array1['priority'] = 10; + } + if ( ! isset( $array2['priority'] ) ) { + $array2['priority'] = 10; + } + + return $array1['priority'] - $array2['priority']; } /** @@ -187,16 +194,17 @@ function show_notices() { // don't display the notice if it is not supposed to be displayed with other notices. if ( 0 !== $notices_displayed && false === $notice['display-with-other-notices'] ) { - return; + continue; } self::markup( $notice ); - $notices_displayed++; } } else { // No transient notices. self::markup( $notice ); } + + ++$notices_displayed; } } @@ -236,7 +244,7 @@ private static function get_wrap_classes( $notice ) { $classes[] = 'notice-' . $notice['type']; } - return implode( ' ', $classes ); + return esc_attr( implode( ' ', $classes ) ); } /** @@ -305,4 +313,4 @@ public static function _get_uri() { */ Astra_Notices::get_instance(); -endif; +endif; \ No newline at end of file From 9ef8b60d6acaf898e36bfdf3f8077ed3cb2458bc Mon Sep 17 00:00:00 2001 From: Uttam Sharma Date: Tue, 5 Nov 2019 14:20:11 +0530 Subject: [PATCH 3/3] phpcs fixes --- includes/lib/notices/class-astra-notices.php | 14 +++++++++++++- includes/lib/notices/notices.js | 1 + sidebar-manager.php | 8 ++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/includes/lib/notices/class-astra-notices.php b/includes/lib/notices/class-astra-notices.php index 973b1b0..607b5f6 100644 --- a/includes/lib/notices/class-astra-notices.php +++ b/includes/lib/notices/class-astra-notices.php @@ -110,6 +110,11 @@ public static function add_notice( $args = array() ) { function dismiss_notice() { $notice_id = ( isset( $_POST['notice_id'] ) ) ? sanitize_key( $_POST['notice_id'] ) : ''; $repeat_notice_after = ( isset( $_POST['repeat_notice_after'] ) ) ? absint( $_POST['repeat_notice_after'] ) : ''; + $nonce = ( isset( $_POST['nonce'] ) ) ? sanitize_key( $_POST['nonce'] ) : ''; + + if ( false === wp_verify_nonce( $nonce, 'astra-notices' ) ) { + wp_send_json_error( _e( 'WordPress Nonce not validated.', 'astra-sites' ) ); + } // Valid inputs? if ( ! empty( $notice_id ) ) { @@ -134,6 +139,13 @@ function dismiss_notice() { */ function enqueue_scripts() { wp_register_script( 'astra-notices', self::_get_uri() . 'notices.js', array( 'jquery' ), null, self::$version ); + wp_localize_script( + 'astra-notices', + 'astraNotices', + array( + '_notice_nonce' => wp_create_nonce( 'astra-notices' ), + ) + ); } /** @@ -313,4 +325,4 @@ public static function _get_uri() { */ Astra_Notices::get_instance(); -endif; \ No newline at end of file +endif; diff --git a/includes/lib/notices/notices.js b/includes/lib/notices/notices.js index 2c7497b..b7062a1 100644 --- a/includes/lib/notices/notices.js +++ b/includes/lib/notices/notices.js @@ -82,6 +82,7 @@ action : 'astra-notice-dismiss', notice_id : notice_id, repeat_notice_after : parseInt( repeat_notice_after ), + nonce : astraNotices._notice_nonce }, }); diff --git a/sidebar-manager.php b/sidebar-manager.php index 2721f37..50cf9cb 100644 --- a/sidebar-manager.php +++ b/sidebar-manager.php @@ -35,10 +35,10 @@ if ( ! function_exists( 'register_notices' ) ) : /** - * Ask Theme Rating - * - * @since 1.4.0 - */ + * Ask Theme Rating + * + * @since 1.4.0 + */ function register_notices() { $image_path = BSF_SB_URL . 'includes/assets/images/sidebar-manager-icon.png'; Astra_Notices::add_notice(