Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'wcfm_page_heading', function() {
- global $WCFM, $wpdb;
- if(apply_filters( 'wcfm_is_allow_notifications', true )) {
- $message_to = apply_filters( 'wcfm_message_author', get_current_user_id() );
- if( !$message_to || !wcfm_is_allow_wcfm() ) return;
- $total_messages = 0;
- if( wcfm_is_vendor() || ( function_exists( 'wcfm_is_delivery_boy' ) && wcfm_is_delivery_boy() ) || ( function_exists( 'wcfm_is_affiliate' ) && wcfm_is_affiliate() ) ) {
- $cache_key = $WCFM->wcfm_notification->cache_group . '-message-' . $message_to;
- } else {
- $cache_key = $WCFM->wcfm_notification->cache_group . '-message-0';
- }
- $total_messages = get_transient( $cache_key );
- if( empty( $total_messages ) ) {
- $sql = 'SELECT COUNT(wcfm_messages.ID) FROM ' . $wpdb->prefix . 'wcfm_messages AS wcfm_messages';
- $sql .= ' WHERE 1=1';
- $status_filter = " AND `is_direct_message` = 1";
- $sql .= $status_filter;
- if( wcfm_is_vendor() || ( function_exists( 'wcfm_is_delivery_boy' ) && wcfm_is_delivery_boy() ) || ( function_exists( 'wcfm_is_affiliate' ) && wcfm_is_affiliate() ) ) {
- $vendor_filter = " AND ( `author_id` = {$message_to} OR `message_to` = -1 OR `message_to` = {$message_to} )";
- $sql .= $vendor_filter;
- } else {
- $group_manager_filter = apply_filters( 'wcfm_notification_group_manager_filter', '' );
- if( $group_manager_filter ) {
- $sql .= $group_manager_filter;
- } else {
- $sql .= " AND `author_id` != -1";
- }
- }
- $message_status_filter = " ID NOT IN (SELECT message FROM {$wpdb->prefix}wcfm_messages_modifier WHERE read_by={$message_to})";
- $sql .= $message_status_filter;
- $total_messages = $wpdb->get_var( $sql );
- set_transient( $cache_key, $total_messages );
- }
- }
- }, 9 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement