'notipulse', 'orderby' => 'post_date', 'order' => 'DESC', 'post_status' => 'publish', 'posts_per_page' => -1, ); $notifiers = get_posts( $args ); if ( empty( $notifiers ) ) { return $active_notifiers; } global $post; $post_title = ( is_object( $post ) && isset( $post->post_title ) ) ? $post->post_title : ''; $post_type = ( is_object( $post ) && isset( $post->post_type ) ) ? $post->post_type : ''; $current_user = wp_get_current_user(); $current_roles = (array) $current_user->roles; $current_role = ! empty( $current_roles ) ? strtolower( $current_roles[0] ) : ''; foreach ( $notifiers as $row ) { $un_data = get_post_meta( $row->ID, 'notipulse_meta_key', true ); if ( ! is_array( $un_data ) ) { $un_data = maybe_unserialize( $un_data ); } if ( ! is_array( $un_data ) ) { continue; } $display_in = ! empty( $un_data['display_in'] ) ? explode( ',', $un_data['display_in'] ) : array( 'All Pages' ); $user_roles = isset( $un_data['user_roles'] ) ? strtolower( trim( $un_data['user_roles'] ) ) : ''; // User role check: if specified, user must match that role. if ( ! empty( $user_roles ) && $current_role !== $user_roles ) { continue; } // Display location check. $is_matching_page = false; if ( in_array( 'All Pages', $display_in, true ) ) { $is_matching_page = true; } elseif ( in_array( $post_title, $display_in, true ) ) { $is_matching_page = true; } elseif ( in_array( $post_type, $display_in, true ) ) { $is_matching_page = true; } if ( ! $is_matching_page ) { continue; } $active_notifiers[] = array( 'post' => $row, 'un_data' => $un_data, ); } return $active_notifiers; } /** * Generate dynamic inline CSS for a notifier instance. * * @param int $notifier_id Notifier post ID. * @param array $un_data Notifier meta options. * @return string CSS string. */ function notipulse_generate_dynamic_css( $notifier_id, $un_data ) { $notipulse_type = isset( $un_data['notipulse_type'] ) ? $un_data['notipulse_type'] : 'Simple'; $bg_color_opacity = isset( $un_data['bg_color_opacity'] ) ? intval( $un_data['bg_color_opacity'] ) : 6; $bg_color_main = ''; if ( 'Custom' === $notipulse_type ) { $full_op = ( 10 !== $bg_color_opacity ) ? '0.' . $bg_color_opacity : '1'; $bg_color = isset( $un_data['bg_color'] ) ? trim( $un_data['bg_color'], '#' ) : ''; if ( 6 === strlen( $bg_color ) ) { $r = hexdec( substr( $bg_color, 0, 2 ) ); $g = hexdec( substr( $bg_color, 2, 2 ) ); $b = hexdec( substr( $bg_color, 4, 2 ) ); $bg_color_main = 'rgba(' . $r . ',' . $g . ',' . $b . ',' . $full_op . ')'; } } $headline_color = isset( $un_data['headline_color'] ) ? sanitize_hex_color( $un_data['headline_color'] ) : ''; $text_color = isset( $un_data['text_color'] ) ? sanitize_hex_color( $un_data['text_color'] ) : ''; $head_top_mar = isset( $un_data['head_top_mar'] ) ? intval( $un_data['head_top_mar'] ) : 0; $head_btm_mar = isset( $un_data['head_btm_mar'] ) ? intval( $un_data['head_btm_mar'] ) : 0; $head_lft_mar = isset( $un_data['head_lft_mar'] ) ? intval( $un_data['head_lft_mar'] ) : 0; $head_ryt_mar = isset( $un_data['head_ryt_mar'] ) ? intval( $un_data['head_ryt_mar'] ) : 0; $head_top_pad = isset( $un_data['head_top_pad'] ) ? intval( $un_data['head_top_pad'] ) : 0; $head_btm_pad = isset( $un_data['head_btm_pad'] ) ? intval( $un_data['head_btm_pad'] ) : 0; $head_lft_pad = isset( $un_data['head_lft_pad'] ) ? intval( $un_data['head_lft_pad'] ) : 0; $head_ryt_pad = isset( $un_data['head_ryt_pad'] ) ? intval( $un_data['head_ryt_pad'] ) : 0; $head_margin = $head_top_mar . 'px ' . $head_ryt_mar . 'px ' . $head_btm_mar . 'px ' . $head_lft_mar . 'px'; $head_padding = $head_top_pad . 'px ' . $head_ryt_pad . 'px ' . $head_btm_pad . 'px ' . $head_lft_pad . 'px'; $content_top_mar = isset( $un_data['content_top_mar'] ) ? intval( $un_data['content_top_mar'] ) : 0; $content_btm_mar = isset( $un_data['content_btm_mar'] ) ? intval( $un_data['content_btm_mar'] ) : 0; $content_lft_mar = isset( $un_data['content_lft_mar'] ) ? intval( $un_data['content_lft_mar'] ) : 0; $content_ryt_mar = isset( $un_data['content_ryt_mar'] ) ? intval( $un_data['content_ryt_mar'] ) : 0; $content_top_pad = isset( $un_data['content_top_pad'] ) ? intval( $un_data['content_top_pad'] ) : 0; $content_btm_pad = isset( $un_data['content_btm_pad'] ) ? intval( $un_data['content_btm_pad'] ) : 0; $content_lft_pad = isset( $un_data['content_lft_pad'] ) ? intval( $un_data['content_lft_pad'] ) : 0; $content_ryt_pad = isset( $un_data['content_ryt_pad'] ) ? intval( $un_data['content_ryt_pad'] ) : 0; $content_margin = $content_top_mar . 'px ' . $content_ryt_mar . 'px ' . $content_btm_mar . 'px ' . $content_lft_mar . 'px'; $content_padding = $content_top_pad . 'px ' . $content_ryt_pad . 'px ' . $content_btm_pad . 'px ' . $content_lft_pad . 'px'; $font_size = isset( $un_data['font_size'] ) ? intval( $un_data['font_size'] ) : 18; $line_height = isset( $un_data['line_height'] ) ? intval( $un_data['line_height'] ) : 28; $cont_fs = $font_size ? 'font-size:' . $font_size . 'px;' : ''; $cont_lh = $line_height ? 'line-height:' . $line_height . 'px;' : ''; $countdown_top_mar = isset( $un_data['countdown_top_mar'] ) ? intval( $un_data['countdown_top_mar'] ) : 0; $countdown_btm_mar = isset( $un_data['countdown_btm_mar'] ) ? intval( $un_data['countdown_btm_mar'] ) : 0; $countdown_lft_mar = isset( $un_data['countdown_lft_mar'] ) ? intval( $un_data['countdown_lft_mar'] ) : 0; $countdown_ryt_mar = isset( $un_data['countdown_ryt_mar'] ) ? intval( $un_data['countdown_ryt_mar'] ) : 0; $countdown_top_pad = isset( $un_data['countdown_top_pad'] ) ? intval( $un_data['countdown_top_pad'] ) : 0; $countdown_btm_pad = isset( $un_data['countdown_btm_pad'] ) ? intval( $un_data['countdown_btm_pad'] ) : 0; $countdown_lft_pad = isset( $un_data['countdown_lft_pad'] ) ? intval( $un_data['countdown_lft_pad'] ) : 0; $countdown_ryt_pad = isset( $un_data['countdown_ryt_pad'] ) ? intval( $un_data['countdown_ryt_pad'] ) : 0; $countdown_margin = $countdown_top_mar . 'px ' . $countdown_ryt_mar . 'px ' . $countdown_btm_mar . 'px ' . $countdown_lft_mar . 'px'; $countdown_padding = $countdown_top_pad . 'px ' . $countdown_ryt_pad . 'px ' . $countdown_btm_pad . 'px ' . $countdown_lft_pad . 'px'; $notipulse_btn_bg_clr = isset( $un_data['notipulse_btn_bg_clr'] ) ? sanitize_hex_color( $un_data['notipulse_btn_bg_clr'] ) : ''; $notipulse_btn_txt_clr = isset( $un_data['notipulse_btn_txt_clr'] ) ? sanitize_hex_color( $un_data['notipulse_btn_txt_clr'] ) : ''; $notipulse_btn_size = ''; if ( isset( $un_data['notipulse_btn_size'] ) && 'Medium' === $un_data['notipulse_btn_size'] ) { $notipulse_btn_size = 'padding:10px 15px;'; } elseif ( isset( $un_data['notipulse_btn_size'] ) && 'Large' === $un_data['notipulse_btn_size'] ) { $notipulse_btn_size = 'padding:12px 15px;'; } $countdown_font_size = ! empty( $un_data['countdown_font_size'] ) ? 'font-size:' . intval( $un_data['countdown_font_size'] ) . 'px;' : ''; $countdown_bg_clr = ! empty( $un_data['countdown_bg_clr'] ) ? 'background-color:' . sanitize_hex_color( $un_data['countdown_bg_clr'] ) . ';' : ''; $countdown_txt_clr = ! empty( $un_data['countdown_txt_clr'] ) ? 'color:' . sanitize_hex_color( $un_data['countdown_txt_clr'] ) . ';' : ''; $wrapper_id = 'np-notify-' . intval( $notifier_id ); $css = '#' . $wrapper_id . ' .np_main_fe_ui.np_type_Custom { background-color: ' . $bg_color_main . '; } '; $css .= '#' . $wrapper_id . ' .np_main_fe_ui.np_type_Custom span.close_box { color: ' . $bg_color_main . '; background-color: ' . $headline_color . '; } '; $css .= '#' . $wrapper_id . ' .np_main_fe_ui.np_type_Custom .notiPulse_inner .notiPulse_head .tmp_clr { color: ' . $headline_color . '; } '; $css .= '#' . $wrapper_id . ' .np_main_fe_ui.np_type_Custom .notiPulse_inner .content.tmp_clr { color: ' . $text_color . '; } '; $css .= '#' . $wrapper_id . ' .np_main_fe_ui .notiPulse_inner .notiPulse_head .tmp_clr { margin: ' . $head_margin . '; padding: ' . $head_padding . '; } '; $css .= '#' . $wrapper_id . ' .np_main_fe_ui .notiPulse_inner .content.tmp_clr { margin: ' . $content_margin . '; padding: ' . $content_padding . '; ' . $cont_fs . ' ' . $cont_lh . ' } '; $css .= '#' . $wrapper_id . ' .np_main_fe_ui .notiPulse_inner .countdownWrap { margin: ' . $countdown_margin . '; } '; $css .= '#' . $wrapper_id . ' .np_main_fe_ui .notiPulse_inner .countdownWrap > div { padding: ' . $countdown_padding . '; } '; if ( ! empty( $notipulse_btn_bg_clr ) || ! empty( $notipulse_btn_txt_clr ) || ! empty( $notipulse_btn_size ) ) { $css .= '#' . $wrapper_id . ' .np_main_fe_ui .notiPulse_inner .content a.btn_type_Custom { background-color: ' . $notipulse_btn_bg_clr . '; color: ' . $notipulse_btn_txt_clr . '; ' . $notipulse_btn_size . ' } '; } if ( ! empty( $countdown_font_size ) ) { $css .= '#' . $wrapper_id . ' .np_main_fe_ui .notiPulse_inner .countdownWrap .np-count { ' . $countdown_font_size . ' } '; } if ( ! empty( $countdown_bg_clr ) || ! empty( $countdown_txt_clr ) ) { $css .= '#' . $wrapper_id . ' .np_main_fe_ui.np_type_Custom .notiPulse_inner .countdownWrap > div { ' . $countdown_bg_clr . ' ' . $countdown_txt_clr . ' } '; } $css .= '#' . $wrapper_id . ' .np_main_fe_ui.np_type_Custom .notiPulse_inner .countdownWrap span { color: inherit; } '; return $css; } /** * Register & enqueue frontend scripts & styles, including dynamic inline CSS. */ function notipulse_frontend_enqueue() { $active = notipulse_get_active_notifiers(); if ( empty( $active ) ) { return; } wp_enqueue_style( 'notipulse-frontend', NOTIPULSE_URL . 'assets/css/front_end_ui.css', array(), NOTIPULSE_VERSION ); wp_enqueue_script( 'notipulse-frontend-js', NOTIPULSE_URL . 'assets/js/front_end_ui_script.js', array( 'jquery' ), NOTIPULSE_VERSION, true ); $all_css = ''; foreach ( $active as $item ) { $all_css .= notipulse_generate_dynamic_css( $item['post']->ID, $item['un_data'] ); } if ( ! empty( $all_css ) ) { wp_add_inline_style( 'notipulse-frontend', $all_css ); } } /** * Render NotiPulse banners on frontend. */ function notipulse_frontend_ui() { $active = notipulse_get_active_notifiers(); if ( empty( $active ) ) { return; } foreach ( $active as $item ) { $row = $item['post']; $un_data = $item['un_data']; $notifier_id = $row->ID; $notipulse_time = isset( $un_data['notipulse_time'] ) ? $un_data['notipulse_time'] : 'Every Time On Page Load'; // Get options with safe fallbacks. $notipulse_link = isset( $un_data['notipulse_link'] ) ? $un_data['notipulse_link'] : ''; $open_in = ( isset( $un_data['open_in'] ) && '_blank' === $un_data['open_in'] ) ? '_blank' : '_self'; $notipulse_type = isset( $un_data['notipulse_type'] ) ? $un_data['notipulse_type'] : 'Simple'; $allowed_tags = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div' ); $head_tags = ( isset( $un_data['head_tags'] ) && in_array( strtolower( $un_data['head_tags'] ), $allowed_tags, true ) ) ? tag_escape( strtolower( $un_data['head_tags'] ) ) : 'h2'; $notipulse_position = isset( $un_data['notipulse_position'] ) ? $un_data['notipulse_position'] : 'Top'; $notipulse_close_when = isset( $un_data['notipulse_close_when'] ) ? $un_data['notipulse_close_when'] : ''; $notipulse_how_much_time = isset( $un_data['notipulse_how_much_time'] ) ? intval( $un_data['notipulse_how_much_time'] ) : 0; $auto_close_seconds = ( 'After a time delay' === $notipulse_close_when && $notipulse_how_much_time > 0 ) ? $notipulse_how_much_time : 0; // Countdown fields. $countdown_on_off = isset( $un_data['countdown_on_off'] ) ? $un_data['countdown_on_off'] : 'Off'; $countdown_date_time = ''; if ( 'On' === $countdown_on_off && ! empty( $un_data['countdown_date_time'] ) ) { $countdown_date_time = gmdate( 'Y-m-d H:i:s', strtotime( $un_data['countdown_date_time'] ) ); } $add_class = 'np_fixed_top'; if ( 'Popup' === $notipulse_position ) { $add_class = 'np_popup'; } elseif ( 'Bottom' === $notipulse_position ) { $add_class = 'np_fixed_btm'; } $wrapper_id = 'np-notify-' . $notifier_id; ?>