Skip to:
Content

BuddyPress.org

Changeset 10523


Ignore:
Timestamp:
02/05/2016 05:26:45 AM (9 years ago)
Author:
boonebgorges
Message:

Move bp-notifications classes to their own files.

See #6870.

Location:
trunk/src/bp-notifications
Files:
2 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-notifications/bp-notifications-loader.php

    r10429 r10523  
    1313defined( 'ABSPATH' ) || exit;
    1414
    15 /**
    16  * Extends the component class to set up the Notifications component.
    17  */
    18 class BP_Notifications_Component extends BP_Component {
    19 
    20     /**
    21      * Start the notifications component creation process.
    22      *
    23      * @since 1.9.0
    24      */
    25     public function __construct() {
    26         parent::start(
    27             'notifications',
    28             _x( 'Notifications', 'Page <title>', 'buddypress' ),
    29             buddypress()->plugin_dir,
    30             array(
    31                 'adminbar_myaccount_order' => 30
    32             )
    33         );
    34     }
    35 
    36     /**
    37      * Include notifications component files.
    38      *
    39      * @since 1.9.0
    40      *
    41      * @see BP_Component::includes() for a description of arguments.
    42      *
    43      * @param array $includes See BP_Component::includes() for a description.
    44      */
    45     public function includes( $includes = array() ) {
    46         $includes = array(
    47             'actions',
    48             'classes',
    49             'screens',
    50             'adminbar',
    51             'template',
    52             'functions',
    53             'cache',
    54         );
    55 
    56         parent::includes( $includes );
    57     }
    58 
    59     /**
    60      * Set up component global data.
    61      *
    62      * @since 1.9.0
    63      *
    64      * @see BP_Component::setup_globals() for a description of arguments.
    65      *
    66      * @param array $args See BP_Component::setup_globals() for a description.
    67      */
    68     public function setup_globals( $args = array() ) {
    69         $bp = buddypress();
    70 
    71         // Define a slug, if necessary.
    72         if ( ! defined( 'BP_NOTIFICATIONS_SLUG' ) ) {
    73             define( 'BP_NOTIFICATIONS_SLUG', $this->id );
    74         }
    75 
    76         // Global tables for the notifications component.
    77         $global_tables = array(
    78             'table_name'      => $bp->table_prefix . 'bp_notifications',
    79             'table_name_meta' => $bp->table_prefix . 'bp_notifications_meta',
    80         );
    81 
    82         // All globals for the notifications component.
    83         // Note that global_tables is included in this array.
    84         $args = array(
    85             'slug'          => BP_NOTIFICATIONS_SLUG,
    86             'has_directory' => false,
    87             'search_string' => __( 'Search Notifications...', 'buddypress' ),
    88             'global_tables' => $global_tables,
    89         );
    90 
    91         parent::setup_globals( $args );
    92     }
    93 
    94     /**
    95      * Set up component navigation.
    96      *
    97      * @since 1.9.0
    98      *
    99      * @see BP_Component::setup_nav() for a description of arguments.
    100      *
    101      * @param array $main_nav Optional. See BP_Component::setup_nav() for
    102      *                        description.
    103      * @param array $sub_nav  Optional. See BP_Component::setup_nav() for
    104      *                        description.
    105      */
    106     public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    107 
    108         // Determine user to use.
    109         if ( bp_displayed_user_domain() ) {
    110             $user_domain = bp_displayed_user_domain();
    111         } elseif ( bp_loggedin_user_domain() ) {
    112             $user_domain = bp_loggedin_user_domain();
    113         } else {
    114             return;
    115         }
    116 
    117         $access             = bp_core_can_edit_settings();
    118         $slug               = bp_get_notifications_slug();
    119         $notifications_link = trailingslashit( $user_domain . $slug );
    120 
    121         // Only grab count if we're on a user page and current user has access.
    122         if ( bp_is_user() && bp_user_has_access() ) {
    123             $count    = bp_notifications_get_unread_notification_count( bp_displayed_user_id() );
    124             $class    = ( 0 === $count ) ? 'no-count' : 'count';
    125             $nav_name = sprintf( _x( 'Notifications <span class="%s">%s</span>', 'Profile screen nav', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count ) );
    126         } else {
    127             $nav_name = _x( 'Notifications', 'Profile screen nav', 'buddypress' );
    128         }
    129 
    130         // Add 'Notifications' to the main navigation.
    131         $main_nav = array(
    132             'name'                    => $nav_name,
    133             'slug'                    => $slug,
    134             'position'                => 30,
    135             'show_for_displayed_user' => $access,
    136             'screen_function'         => 'bp_notifications_screen_unread',
    137             'default_subnav_slug'     => 'unread',
    138             'item_css_id'             => $this->id,
    139         );
    140 
    141         // Add the subnav items to the notifications nav item.
    142         $sub_nav[] = array(
    143             'name'            => _x( 'Unread', 'Notification screen nav', 'buddypress' ),
    144             'slug'            => 'unread',
    145             'parent_url'      => $notifications_link,
    146             'parent_slug'     => $slug,
    147             'screen_function' => 'bp_notifications_screen_unread',
    148             'position'        => 10,
    149             'item_css_id'     => 'notifications-my-notifications',
    150             'user_has_access' => $access,
    151         );
    152 
    153         $sub_nav[] = array(
    154             'name'            => _x( 'Read', 'Notification screen nav', 'buddypress' ),
    155             'slug'            => 'read',
    156             'parent_url'      => $notifications_link,
    157             'parent_slug'     => $slug,
    158             'screen_function' => 'bp_notifications_screen_read',
    159             'position'        => 20,
    160             'user_has_access' => $access,
    161         );
    162 
    163         parent::setup_nav( $main_nav, $sub_nav );
    164     }
    165 
    166     /**
    167      * Set up the component entries in the WordPress Admin Bar.
    168      *
    169      * @since 1.9.0
    170      *
    171      * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
    172      *      parameter array.
    173      *
    174      * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
    175      *                            description.
    176      */
    177     public function setup_admin_bar( $wp_admin_nav = array() ) {
    178 
    179         // Menus for logged in user.
    180         if ( is_user_logged_in() ) {
    181 
    182             // Setup the logged in user variables.
    183             $notifications_link = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() );
    184 
    185             // Pending notification requests.
    186             $count = bp_notifications_get_unread_notification_count( bp_loggedin_user_id() );
    187             if ( ! empty( $count ) ) {
    188                 $title  = sprintf( _x( 'Notifications <span class="count">%s</span>', 'My Account Notification pending', 'buddypress' ), bp_core_number_format( $count ) );
    189                 $unread = sprintf( _x( 'Unread <span class="count">%s</span>',        'My Account Notification pending', 'buddypress' ), bp_core_number_format( $count ) );
    190             } else {
    191                 $title  = _x( 'Notifications', 'My Account Notification',         'buddypress' );
    192                 $unread = _x( 'Unread',        'My Account Notification sub nav', 'buddypress' );
    193             }
    194 
    195             // Add the "My Account" sub menus.
    196             $wp_admin_nav[] = array(
    197                 'parent' => buddypress()->my_account_menu_id,
    198                 'id'     => 'my-account-' . $this->id,
    199                 'title'  => $title,
    200                 'href'   => $notifications_link
    201             );
    202 
    203             // Unread.
    204             $wp_admin_nav[] = array(
    205                 'parent' => 'my-account-' . $this->id,
    206                 'id'     => 'my-account-' . $this->id . '-unread',
    207                 'title'  => $unread,
    208                 'href'   => $notifications_link
    209             );
    210 
    211             // Read.
    212             $wp_admin_nav[] = array(
    213                 'parent' => 'my-account-' . $this->id,
    214                 'id'     => 'my-account-' . $this->id . '-read',
    215                 'title'  => _x( 'Read', 'My Account Notification sub nav', 'buddypress' ),
    216                 'href'   => trailingslashit( $notifications_link . 'read' ),
    217             );
    218         }
    219 
    220         parent::setup_admin_bar( $wp_admin_nav );
    221     }
    222 
    223     /**
    224      * Set up the title for pages and <title>.
    225      *
    226      * @since 1.9.0
    227      */
    228     public function setup_title() {
    229 
    230         // Adjust title.
    231         if ( bp_is_notifications_component() ) {
    232             $bp = buddypress();
    233 
    234             if ( bp_is_my_profile() ) {
    235                 $bp->bp_options_title = __( 'Notifications', 'buddypress' );
    236             } else {
    237                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    238                     'item_id' => bp_displayed_user_id(),
    239                     'type'    => 'thumb',
    240                     'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
    241                 ) );
    242                 $bp->bp_options_title = bp_get_displayed_user_fullname();
    243             }
    244         }
    245 
    246         parent::setup_title();
    247     }
    248 
    249     /**
    250      * Setup cache groups.
    251      *
    252      * @since 2.2.0
    253      */
    254     public function setup_cache_groups() {
    255 
    256         // Global groups.
    257         wp_cache_add_global_groups( array(
    258             'bp_notifications',
    259             'notification_meta'
    260         ) );
    261 
    262         parent::setup_cache_groups();
    263     }
    264 }
     15require dirname( __FILE__ ) . '/classes/class-bp-notifications-component.php';
    26516
    26617/**
  • trunk/src/bp-notifications/bp-notifications-template.php

    r10420 r10523  
    1111defined( 'ABSPATH' ) || exit;
    1212
     13require dirname( __FILE__ ) . '/classes/class-bp-notifications-template.php';
     14
    1315/**
    1416 * Output the notifications component slug.
     
    121123        return apply_filters( 'bp_get_notifications_unread_permalink', $retval );
    122124    }
    123 
    124 /** Main Loop *****************************************************************/
    125 
    126 /**
    127  * The main notifications template loop class.
    128  *
    129  * Responsible for loading a group of notifications into a loop for display.
    130  *
    131  * @since 1.9.0
    132  */
    133 class BP_Notifications_Template {
    134 
    135     /**
    136      * The loop iterator.
    137      *
    138      * @since 1.9.0
    139      * @var int
    140      */
    141     public $current_notification = -1;
    142 
    143     /**
    144      * The number of notifications returned by the paged query.
    145      *
    146      * @since 1.9.0
    147      * @var int
    148      */
    149     public $current_notification_count;
    150 
    151     /**
    152      * Total number of notifications matching the query.
    153      *
    154      * @since 1.9.0
    155      * @var int
    156      */
    157     public $total_notification_count;
    158 
    159     /**
    160      * Array of notifications located by the query.
    161      *
    162      * @since 1.9.0
    163      * @var array
    164      */
    165     public $notifications;
    166 
    167     /**
    168      * The notification object currently being iterated on.
    169      *
    170      * @since 1.9.0
    171      * @var object
    172      */
    173     public $notification;
    174 
    175     /**
    176      * A flag for whether the loop is currently being iterated.
    177      *
    178      * @since 1.9.0
    179      * @var bool
    180      */
    181     public $in_the_loop;
    182 
    183     /**
    184      * The ID of the user to whom the displayed notifications belong.
    185      *
    186      * @since 1.9.0
    187      * @var int
    188      */
    189     public $user_id;
    190 
    191     /**
    192      * The page number being requested.
    193      *
    194      * @since 1.9.0
    195      * @var int
    196      */
    197     public $pag_page;
    198 
    199     /**
    200      * The $_GET argument used in URLs for determining pagination.
    201      *
    202      * @since 1.9.0
    203      * @var int
    204      */
    205     public $pag_arg;
    206 
    207     /**
    208      * The number of items to display per page of results.
    209      *
    210      * @since 1.9.0
    211      * @var int
    212      */
    213     public $pag_num;
    214 
    215     /**
    216      * An HTML string containing pagination links.
    217      *
    218      * @since 1.9.0
    219      * @var string
    220      */
    221     public $pag_links;
    222 
    223     /**
    224      * A string to match against.
    225      *
    226      * @since 1.9.0
    227      * @var string
    228      */
    229     public $search_terms;
    230 
    231     /**
    232      * A database column to order the results by.
    233      *
    234      * @since 1.9.0
    235      * @var string
    236      */
    237     public $order_by;
    238 
    239     /**
    240      * The direction to sort the results (ASC or DESC).
    241      *
    242      * @since 1.9.0
    243      * @var string
    244      */
    245     public $sort_order;
    246 
    247     /**
    248      * Array of variables used in this notification query.
    249      *
    250      * @since 2.2.2
    251      * @var array
    252      */
    253     public $query_vars;
    254 
    255     /**
    256      * Constructor method.
    257      *
    258      * @see bp_has_notifications() For information on the array format.
    259      *
    260      * @since 1.9.0
    261      *
    262      * @param array $args {
    263      *     An array of arguments. See {@link bp_has_notifications()}
    264      *     for more details.
    265      * }
    266      */
    267     public function __construct( $args = array() ) {
    268 
    269         // Parse arguments.
    270         $r = wp_parse_args( $args, array(
    271             'id'                => false,
    272             'user_id'           => 0,
    273             'item_id'           => false,
    274             'secondary_item_id' => false,
    275             'component_name'    => bp_notifications_get_registered_components(),
    276             'component_action'  => false,
    277             'is_new'            => true,
    278             'search_terms'      => '',
    279             'order_by'          => 'date_notified',
    280             'sort_order'        => 'DESC',
    281             'page_arg'          => 'npage',
    282             'page'              => 1,
    283             'per_page'          => 25,
    284             'max'               => null,
    285             'meta_query'        => false,
    286             'date_query'        => false
    287         ) );
    288 
    289         // Sort order direction.
    290         $orders = array( 'ASC', 'DESC' );
    291         if ( ! empty( $_GET['sort_order'] ) && in_array( $_GET['sort_order'], $orders ) ) {
    292             $r['sort_order'] = $_GET['sort_order'];
    293         } else {
    294             $r['sort_order'] = in_array( $r['sort_order'], $orders ) ? $r['sort_order'] : 'DESC';
    295         }
    296 
    297         // Setup variables.
    298         $this->pag_arg      = sanitize_key( $r['page_arg'] );
    299         $this->pag_page     = bp_sanitize_pagination_arg( $this->pag_arg, $r['page']     );
    300         $this->pag_num      = bp_sanitize_pagination_arg( 'num',          $r['per_page'] );
    301         $this->user_id      = $r['user_id'];
    302         $this->is_new       = $r['is_new'];
    303         $this->search_terms = $r['search_terms'];
    304         $this->order_by     = $r['order_by'];
    305         $this->sort_order   = $r['sort_order'];
    306         $this->query_vars   = array(
    307             'id'                => $r['id'],
    308             'user_id'           => $this->user_id,
    309             'item_id'           => $r['item_id'],
    310             'secondary_item_id' => $r['secondary_item_id'],
    311             'component_name'    => $r['component_name'],
    312             'component_action'  => $r['component_action'],
    313             'meta_query'        => $r['meta_query'],
    314             'date_query'        => $r['date_query'],
    315             'is_new'            => $this->is_new,
    316             'search_terms'      => $this->search_terms,
    317             'order_by'          => $this->order_by,
    318             'sort_order'        => $this->sort_order,
    319             'page'              => $this->pag_page,
    320             'per_page'          => $this->pag_num,
    321         );
    322 
    323         // Setup the notifications to loop through.
    324         $this->notifications            = BP_Notifications_Notification::get( $this->query_vars );
    325         $this->total_notification_count = BP_Notifications_Notification::get_total_count( $this->query_vars );
    326 
    327         if ( empty( $this->notifications ) ) {
    328             $this->notification_count       = 0;
    329             $this->total_notification_count = 0;
    330 
    331         } else {
    332             if ( ! empty( $r['max'] ) ) {
    333                 if ( $r['max'] >= count( $this->notifications ) ) {
    334                     $this->notification_count = count( $this->notifications );
    335                 } else {
    336                     $this->notification_count = (int) $r['max'];
    337                 }
    338             } else {
    339                 $this->notification_count = count( $this->notifications );
    340             }
    341         }
    342 
    343         if ( (int) $this->total_notification_count && (int) $this->pag_num ) {
    344             $add_args = array(
    345                 'sort_order' => $this->sort_order,
    346             );
    347 
    348             $this->pag_links = paginate_links( array(
    349                 'base'      => add_query_arg( $this->pag_arg, '%#%' ),
    350                 'format'    => '',
    351                 'total'     => ceil( (int) $this->total_notification_count / (int) $this->pag_num ),
    352                 'current'   => $this->pag_page,
    353                 'prev_text' => _x( '&larr;', 'Notifications pagination previous text', 'buddypress' ),
    354                 'next_text' => _x( '&rarr;', 'Notifications pagination next text',     'buddypress' ),
    355                 'mid_size'  => 1,
    356                 'add_args'  => $add_args,
    357             ) );
    358         }
    359     }
    360 
    361     /**
    362      * Whether there are notifications available in the loop.
    363      *
    364      * @since 1.9.0
    365      *
    366      * @see bp_has_notifications()
    367      *
    368      * @return bool True if there are items in the loop, otherwise false.
    369      */
    370     public function has_notifications() {
    371         if ( $this->notification_count ) {
    372             return true;
    373         }
    374 
    375         return false;
    376     }
    377 
    378     /**
    379      * Set up the next notification and iterate index.
    380      *
    381      * @since 1.9.0
    382      *
    383      * @return object The next notification to iterate over.
    384      */
    385     public function next_notification() {
    386 
    387         $this->current_notification++;
    388 
    389         $this->notification = $this->notifications[ $this->current_notification ];
    390 
    391         return $this->notification;
    392     }
    393 
    394     /**
    395      * Rewind the blogs and reset blog index.
    396      *
    397      * @since 1.9.0
    398      */
    399     public function rewind_notifications() {
    400 
    401         $this->current_notification = -1;
    402 
    403         if ( $this->notification_count > 0 ) {
    404             $this->notification = $this->notifications[0];
    405         }
    406     }
    407 
    408     /**
    409      * Whether there are notifications left in the loop to iterate over.
    410      *
    411      * This method is used by {@link bp_notifications()} as part of the
    412      * while loop that controls iteration inside the notifications loop, eg:
    413      *     while ( bp_notifications() ) { ...
    414      *
    415      * @since 1.9.0
    416      *
    417      * @see bp_notifications()
    418      *
    419      * @return bool True if there are more notifications to show,
    420      *              otherwise false.
    421      */
    422     public function notifications() {
    423 
    424         if ( $this->current_notification + 1 < $this->notification_count ) {
    425             return true;
    426 
    427         } elseif ( $this->current_notification + 1 == $this->notification_count ) {
    428 
    429             /**
    430              * Fires right before the rewinding of notification posts.
    431              *
    432              * @since 1.9.0
    433              */
    434             do_action( 'notifications_loop_end');
    435 
    436             $this->rewind_notifications();
    437         }
    438 
    439         $this->in_the_loop = false;
    440         return false;
    441     }
    442 
    443     /**
    444      * Set up the current notification inside the loop.
    445      *
    446      * Used by {@link bp_the_notification()} to set up the current
    447      * notification data while looping, so that template tags used during
    448      * that iteration make reference to the current notification.
    449      *
    450      * @since 1.9.0
    451      *
    452      * @see bp_the_notification()
    453      */
    454     public function the_notification() {
    455         $this->in_the_loop  = true;
    456         $this->notification = $this->next_notification();
    457 
    458         // Loop has just started.
    459         if ( 0 === $this->current_notification ) {
    460 
    461             /**
    462              * Fires if the current notification item is the first in the notification loop.
    463              *
    464              * @since 1.9.0
    465              */
    466             do_action( 'notifications_loop_start' );
    467         }
    468     }
    469 }
    470125
    471126/** The Loop ******************************************************************/
  • trunk/src/bp-notifications/classes/class-bp-notifications-component.php

    r10515 r10523  
    263263    }
    264264}
    265 
    266 /**
    267  * Bootstrap the Notifications component.
    268  *
    269  * @since 1.9.0
    270  */
    271 function bp_setup_notifications() {
    272     buddypress()->notifications = new BP_Notifications_Component();
    273 }
    274 add_action( 'bp_setup_components', 'bp_setup_notifications', 6 );
  • trunk/src/bp-notifications/classes/class-bp-notifications-template.php

    r10515 r10523  
    11<?php
    22/**
    3  * BuddyPress Notifications Template Functions.
     3 * BuddyPress Notifications Template Loop Class.
    44 *
    55 * @package BuddyPress
     
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
    12 
    13 /**
    14  * Output the notifications component slug.
    15  *
    16  * @since 1.9.0
    17  */
    18 function bp_notifications_slug() {
    19     echo bp_get_notifications_slug();
    20 }
    21     /**
    22      * Return the notifications component slug.
    23      *
    24      * @since 1.9.0
    25      *
    26      * @return string Slug of the Notifications component.
    27      */
    28     function bp_get_notifications_slug() {
    29 
    30         /**
    31          * Filters the notifications component slug.
    32          *
    33          * @since 1.9.0
    34          *
    35          * @param string $slug Notifications component slug.
    36          */
    37         return apply_filters( 'bp_get_notifications_slug', buddypress()->notifications->slug );
    38     }
    39 
    40 /**
    41  * Output the notifications permalink.
    42  *
    43  * @since 1.9.0
    44  */
    45 function bp_notifications_permalink() {
    46     echo bp_get_notifications_permalink();
    47 }
    48     /**
    49      * Return the notifications permalink.
    50      *
    51      * @since 1.9.0
    52      *
    53      * @return string Notifications permalink.
    54      */
    55     function bp_get_notifications_permalink() {
    56         $retval = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() );
    57 
    58         /**
    59          * Filters the notifications permalink.
    60          *
    61          * @since 1.9.0
    62          *
    63          * @param string $retval Permalink for the notifications.
    64          */
    65         return apply_filters( 'bp_get_notifications_permalink', $retval );
    66     }
    67 
    68 /**
    69  * Output the unread notifications permalink.
    70  *
    71  * @since 1.9.0
    72  */
    73 function bp_notifications_unread_permalink() {
    74     echo bp_get_notifications_unread_permalink();
    75 }
    76     /**
    77      * Return the unread notifications permalink.
    78      *
    79      * @since 1.9.0
    80      *
    81      * @return string Unread notifications permalink.
    82      */
    83     function bp_get_notifications_unread_permalink() {
    84         $retval = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() . '/unread' );
    85 
    86         /**
    87          * Filters the unread notifications permalink.
    88          *
    89          * @since 1.9.0
    90          *
    91          * @param string $retval Permalink for the unread notifications.
    92          */
    93         return apply_filters( 'bp_get_notifications_unread_permalink', $retval );
    94     }
    95 
    96 /**
    97  * Output the read notifications permalink.
    98  *
    99  * @since 1.9.0
    100  */
    101 function bp_notifications_read_permalink() {
    102     echo bp_get_notifications_read_permalink();
    103 }
    104     /**
    105      * Return the read notifications permalink.
    106      *
    107      * @since 1.9.0
    108      *
    109      * @return string Read notifications permalink.
    110      */
    111     function bp_get_notifications_read_permalink() {
    112         $retval = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() . '/read' );
    113 
    114         /**
    115          * Filters the read notifications permalink.
    116          *
    117          * @since 1.9.0
    118          *
    119          * @param string $retval Permalink for the read notifications.
    120          */
    121         return apply_filters( 'bp_get_notifications_unread_permalink', $retval );
    122     }
    123 
    124 /** Main Loop *****************************************************************/
    12512
    12613/**
     
    468355    }
    469356}
    470 
    471 /** The Loop ******************************************************************/
    472 
    473 /**
    474  * Initialize the notifications loop.
    475  *
    476  * Based on the $args passed, bp_has_notifications() populates
    477  * buddypress()->notifications->query_loop global, enabling the use of BP
    478  * templates and template functions to display a list of notifications.
    479  *
    480  * @since 1.9.0
    481  *
    482  * @param array|string $args {
    483  *     Arguments for limiting the contents of the notifications loop. Can be
    484  *     passed as an associative array, or as a URL query string.
    485  *
    486  *     See {@link BP_Notifications_Notification::get()} for detailed
    487  *     information on the arguments.  In addition, also supports:
    488  *
    489  *     @type int    $max      Optional. Max items to display. Default: false.
    490  *     @type string $page_arg URL argument to use for pagination.
    491  *                            Default: 'npage'.
    492  * }
    493  * @return bool
    494  */
    495 function bp_has_notifications( $args = '' ) {
    496 
    497     // Get the default is_new argument.
    498     if ( bp_is_current_action( 'unread' ) ) {
    499         $is_new = 1;
    500     } elseif ( bp_is_current_action( 'read' ) ) {
    501         $is_new = 0;
    502 
    503     // Not on a notifications page? default to fetch new notifications.
    504     } else {
    505         $is_new = 1;
    506     }
    507 
    508     // Get the user ID.
    509     if ( bp_displayed_user_id() ) {
    510         $user_id = bp_displayed_user_id();
    511     } else {
    512         $user_id = bp_loggedin_user_id();
    513     }
    514 
    515     // Parse the args.
    516     $r = bp_parse_args( $args, array(
    517         'id'                => false,
    518         'user_id'           => $user_id,
    519         'secondary_item_id' => false,
    520         'component_name'    => bp_notifications_get_registered_components(),
    521         'component_action'  => false,
    522         'is_new'            => $is_new,
    523         'search_terms'      => isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '',
    524         'order_by'          => 'date_notified',
    525         'sort_order'        => 'DESC',
    526         'meta_query'        => false,
    527         'date_query'        => false,
    528         'page'              => 1,
    529         'per_page'          => 25,
    530 
    531         // These are additional arguments that are not available in
    532         // BP_Notifications_Notification::get().
    533         'max'               => false,
    534         'page_arg'          => 'npage',
    535     ), 'has_notifications' );
    536 
    537     // Get the notifications.
    538     $query_loop = new BP_Notifications_Template( $r );
    539 
    540     // Setup the global query loop.
    541     buddypress()->notifications->query_loop = $query_loop;
    542 
    543     /**
    544      * Filters whether or not the user has notifications to display.
    545      *
    546      * @since 1.9.0
    547      *
    548      * @param bool                      $value      Whether or not there are notifications to display.
    549      * @param BP_Notifications_Template $query_loop BP_Notifications_Template object instance.
    550      */
    551     return apply_filters( 'bp_has_notifications', $query_loop->has_notifications(), $query_loop );
    552 }
    553 
    554 /**
    555  * Get the notifications returned by the template loop.
    556  *
    557  * @since 1.9.0
    558  *
    559  * @return array List of notifications.
    560  */
    561 function bp_the_notifications() {
    562     return buddypress()->notifications->query_loop->notifications();
    563 }
    564 
    565 /**
    566  * Get the current notification object in the loop.
    567  *
    568  * @since 1.9.0
    569  *
    570  * @return object The current notification within the loop.
    571  */
    572 function bp_the_notification() {
    573     return buddypress()->notifications->query_loop->the_notification();
    574 }
    575 
    576 /** Loop Output ***************************************************************/
    577 
    578 /**
    579  * Output the ID of the notification currently being iterated on.
    580  *
    581  * @since 1.9.0
    582  */
    583 function bp_the_notification_id() {
    584     echo bp_get_the_notification_id();
    585 }
    586     /**
    587      * Return the ID of the notification currently being iterated on.
    588      *
    589      * @since 1.9.0
    590      *
    591      * @return int ID of the current notification.
    592      */
    593     function bp_get_the_notification_id() {
    594 
    595         /**
    596          * Filters the ID of the notification currently being iterated on.
    597          *
    598          * @since 1.9.0
    599          *
    600          * @param int $id ID of the notification being iterated on.
    601          */
    602         return apply_filters( 'bp_get_the_notification_id', buddypress()->notifications->query_loop->notification->id );
    603     }
    604 
    605 /**
    606  * Output the associated item ID of the notification currently being iterated on.
    607  *
    608  * @since 1.9.0
    609  */
    610 function bp_the_notification_item_id() {
    611     echo bp_get_the_notification_item_id();
    612 }
    613     /**
    614      * Return the associated item ID of the notification currently being iterated on.
    615      *
    616      * @since 1.9.0
    617      *
    618      * @return int ID of the item associated with the current notification.
    619      */
    620     function bp_get_the_notification_item_id() {
    621 
    622         /**
    623          * Filters the associated item ID of the notification currently being iterated on.
    624          *
    625          * @since 1.9.0
    626          *
    627          * @param int $item_id ID of the associated item.
    628          */
    629         return apply_filters( 'bp_get_the_notification_item_id', buddypress()->notifications->query_loop->notification->item_id );
    630     }
    631 
    632 /**
    633  * Output the secondary associated item ID of the notification currently being iterated on.
    634  *
    635  * @since 1.9.0
    636  */
    637 function bp_the_notification_secondary_item_id() {
    638     echo bp_get_the_notification_secondary_item_id();
    639 }
    640     /**
    641      * Return the secondary associated item ID of the notification currently being iterated on.
    642      *
    643      * @since 1.9.0
    644      *
    645      * @return int ID of the secondary item associated with the current notification.
    646      */
    647     function bp_get_the_notification_secondary_item_id() {
    648 
    649         /**
    650          * Filters the secondary associated item ID of the notification currently being iterated on.
    651          *
    652          * @since 1.9.0
    653          *
    654          * @param int $secondary_item_id ID of the secondary associated item.
    655          */
    656         return apply_filters( 'bp_get_the_notification_secondary_item_id', buddypress()->notifications->query_loop->notification->secondary_item_id );
    657     }
    658 
    659 /**
    660  * Output the name of the component associated with the notification currently being iterated on.
    661  *
    662  * @since 1.9.0
    663  */
    664 function bp_the_notification_component_name() {
    665     echo bp_get_the_notification_component_name();
    666 }
    667     /**
    668      * Return the name of the component associated with the notification currently being iterated on.
    669      *
    670      * @since 1.9.0
    671      *
    672      * @return int Name of the component associated with the current notification.
    673      */
    674     function bp_get_the_notification_component_name() {
    675 
    676         /**
    677          * Filters the name of the component associated with the notification currently being iterated on.
    678          *
    679          * @since 1.9.0
    680          *
    681          * @param int $component_name Name of the component associated with the current notification.
    682          */
    683         return apply_filters( 'bp_get_the_notification_component_name', buddypress()->notifications->query_loop->notification->component_name );
    684     }
    685 
    686 /**
    687  * Output the name of the action associated with the notification currently being iterated on.
    688  *
    689  * @since 1.9.0
    690  */
    691 function bp_the_notification_component_action() {
    692     echo bp_get_the_notification_component_action();
    693 }
    694     /**
    695      * Return the name of the action associated with the notification currently being iterated on.
    696      *
    697      * @since 1.9.0
    698      *
    699      * @return int Name of the action associated with the current notification.
    700      */
    701     function bp_get_the_notification_component_action() {
    702 
    703         /**
    704          * Filters the name of the action associated with the notification currently being iterated on.
    705          *
    706          * @since 1.9.0
    707          *
    708          * @param int $component_action Name of the action associated with the current notification.
    709          */
    710         return apply_filters( 'bp_get_the_notification_component_action', buddypress()->notifications->query_loop->notification->component_action );
    711     }
    712 
    713 /**
    714  * Output the timestamp of the current notification.
    715  *
    716  * @since 1.9.0
    717  */
    718 function bp_the_notification_date_notified() {
    719     echo bp_get_the_notification_date_notified();
    720 }
    721     /**
    722      * Return the timestamp of the current notification.
    723      *
    724      * @since 1.9.0
    725      *
    726      * @return string Timestamp of the current notification.
    727      */
    728     function bp_get_the_notification_date_notified() {
    729 
    730         /**
    731          * Filters the timestamp of the current notification.
    732          *
    733          * @since 1.9.0
    734          *
    735          * @param string $date_notified Timestamp of the current notification.
    736          */
    737         return apply_filters( 'bp_get_the_notification_date_notified', buddypress()->notifications->query_loop->notification->date_notified );
    738     }
    739 
    740 /**
    741  * Output the timestamp of the current notification.
    742  *
    743  * @since 1.9.0
    744  */
    745 function bp_the_notification_time_since() {
    746     echo bp_get_the_notification_time_since();
    747 }
    748     /**
    749      * Return the timestamp of the current notification.
    750      *
    751      * @since 1.9.0
    752      *
    753      * @return string Timestamp of the current notification.
    754      */
    755     function bp_get_the_notification_time_since() {
    756 
    757         // Get the notified date.
    758         $date_notified = bp_get_the_notification_date_notified();
    759 
    760         // Notified date has legitimate data.
    761         if ( '0000-00-00 00:00:00' !== $date_notified ) {
    762             $retval = bp_core_time_since( $date_notified );
    763 
    764         // Notified date is empty, so return a fun string.
    765         } else {
    766             $retval = __( 'Date not found', 'buddypress' );
    767         }
    768 
    769         /**
    770          * Filters the time since value of the current notification.
    771          *
    772          * @since 1.9.0
    773          *
    774          * @param string $retval Time since value for current notification.
    775          */
    776         return apply_filters( 'bp_get_the_notification_time_since', $retval );
    777     }
    778 
    779 /**
    780  * Output full-text description for a specific notification.
    781  *
    782  * @since 1.9.0
    783  */
    784 function bp_the_notification_description() {
    785     echo bp_get_the_notification_description();
    786 }
    787 
    788     /**
    789      * Get full-text description for a specific notification.
    790      *
    791      * @since 1.9.0
    792      *
    793      * @return string
    794      */
    795     function bp_get_the_notification_description() {
    796         $bp           = buddypress();
    797         $notification = $bp->notifications->query_loop->notification;
    798 
    799         // Callback function exists.
    800         if ( isset( $bp->{ $notification->component_name }->notification_callback ) && is_callable( $bp->{ $notification->component_name }->notification_callback ) ) {
    801             $description = call_user_func( $bp->{ $notification->component_name }->notification_callback, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1 );
    802 
    803         // @deprecated format_notification_function - 1.5
    804         } elseif ( isset( $bp->{ $notification->component_name }->format_notification_function ) && function_exists( $bp->{ $notification->component_name }->format_notification_function ) ) {
    805             $description = call_user_func( $bp->{ $notification->component_name }->format_notification_function, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1 );
    806 
    807         // Allow non BuddyPress components to hook in.
    808         } else {
    809 
    810             /** This filter is documented in bp-notifications/bp-notifications-functions.php */
    811             $description = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', array( $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1 ) );
    812         }
    813 
    814         /**
    815          * Filters the full-text description for a specific notification.
    816          *
    817          * @since 1.9.0
    818          * @since 2.3.0 Added the `$notification` parameter.
    819          *
    820          * @param string $description  Full-text description for a specific notification.
    821          * @param object $notification Notification object.
    822          */
    823         return apply_filters( 'bp_get_the_notification_description', $description, $notification );
    824     }
    825 
    826 /**
    827  * Output the mark read link for the current notification.
    828  *
    829  * @since 1.9.0
    830  *
    831  * @uses bp_get_the_notification_mark_read_link()
    832  */
    833 function bp_the_notification_mark_read_link() {
    834     echo bp_get_the_notification_mark_read_link();
    835 }
    836     /**
    837      * Return the mark read link for the current notification.
    838      *
    839      * @since 1.9.0
    840      *
    841      * @return string
    842      */
    843     function bp_get_the_notification_mark_read_link() {
    844 
    845         // Start the output buffer.
    846         ob_start(); ?>
    847 
    848         <a href="<?php bp_the_notification_mark_read_url(); ?>" class="mark-read primary"><?php _e( 'Read', 'buddypress' ); ?></a>
    849 
    850         <?php $retval = ob_get_clean();
    851 
    852         /**
    853          * Filters the mark read link for the current notification.
    854          *
    855          * @since 1.9.0
    856          *
    857          * @param string $retval HTML for the mark read link for the current notification.
    858          */
    859         return apply_filters( 'bp_get_the_notification_mark_read_link', $retval );
    860     }
    861 
    862 /**
    863  * Output the URL used for marking a single notification as read.
    864  *
    865  * Since this function directly outputs a URL, it is escaped.
    866  *
    867  * @since 2.1.0
    868  *
    869  * @uses bp_get_the_notification_mark_read_url()
    870  */
    871 function bp_the_notification_mark_read_url() {
    872     echo esc_url( bp_get_the_notification_mark_read_url() );
    873 }
    874     /**
    875      * Return the URL used for marking a single notification as read.
    876      *
    877      * @since 2.1.0
    878      *
    879      * @return string
    880      */
    881     function bp_get_the_notification_mark_read_url() {
    882 
    883         // Get the notification ID.
    884         $id   = bp_get_the_notification_id();
    885 
    886         // Get the args to add to the URL.
    887         $args = array(
    888             'action'          => 'read',
    889             'notification_id' => $id
    890         );
    891 
    892         // Add the args to the URL.
    893         $url = add_query_arg( $args, bp_get_notifications_unread_permalink() );
    894 
    895         // Add the nonce.
    896         $url = wp_nonce_url( $url, 'bp_notification_mark_read_' . $id );
    897 
    898         /**
    899          * Filters the URL used for marking a single notification as read.
    900          *
    901          * @since 2.1.0
    902          *
    903          * @param string $url URL to use for marking the single notification as read.
    904          */
    905         return apply_filters( 'bp_get_the_notification_mark_read_url', $url );
    906     }
    907 
    908 /**
    909  * Output the mark unread link for the current notification.
    910  *
    911  * @since 1.9.0
    912  *
    913  * @uses bp_get_the_notification_mark_unread_link()
    914  */
    915 function bp_the_notification_mark_unread_link() {
    916     echo bp_get_the_notification_mark_unread_link();
    917 }
    918     /**
    919      * Return the mark unread link for the current notification.
    920      *
    921      * @since 1.9.0
    922      *
    923      * @return string
    924      */
    925     function bp_get_the_notification_mark_unread_link() {
    926 
    927         // Start the output buffer.
    928         ob_start(); ?>
    929 
    930         <a href="<?php bp_the_notification_mark_unread_url(); ?>" class="mark-unread primary"><?php _ex( 'Unread',  'Notification screen action', 'buddypress' ); ?></a>
    931 
    932         <?php $retval = ob_get_clean();
    933 
    934         /**
    935          * Filters the link used for marking a single notification as unread.
    936          *
    937          * @since 1.9.0
    938          *
    939          * @param string $retval HTML for the mark unread link for the current notification.
    940          */
    941         return apply_filters( 'bp_get_the_notification_mark_unread_link', $retval );
    942     }
    943 
    944 /**
    945  * Output the URL used for marking a single notification as unread.
    946  *
    947  * Since this function directly outputs a URL, it is escaped.
    948  *
    949  * @since 2.1.0
    950  *
    951  * @uses bp_get_the_notification_mark_unread_url()
    952  */
    953 function bp_the_notification_mark_unread_url() {
    954     echo esc_url( bp_get_the_notification_mark_unread_url() );
    955 }
    956     /**
    957      * Return the URL used for marking a single notification as unread.
    958      *
    959      * @since 2.1.0
    960      *
    961      * @return string
    962      */
    963     function bp_get_the_notification_mark_unread_url() {
    964 
    965         // Get the notification ID.
    966         $id   = bp_get_the_notification_id();
    967 
    968         // Get the args to add to the URL.
    969         $args = array(
    970             'action'          => 'unread',
    971             'notification_id' => $id
    972         );
    973 
    974         // Add the args to the URL.
    975         $url = add_query_arg( $args, bp_get_notifications_read_permalink() );
    976 
    977         // Add the nonce.
    978         $url = wp_nonce_url( $url, 'bp_notification_mark_unread_' . $id );
    979 
    980         /**
    981          * Filters the URL used for marking a single notification as unread.
    982          *
    983          * @since 2.1.0
    984          *
    985          * @param string $url URL to use for marking the single notification as unread.
    986          */
    987         return apply_filters( 'bp_get_the_notification_mark_unread_url', $url );
    988     }
    989 
    990 /**
    991  * Output the mark link for the current notification.
    992  *
    993  * @since 1.9.0
    994  *
    995  * @uses bp_get_the_notification_mark_unread_link()
    996  */
    997 function bp_the_notification_mark_link() {
    998     echo bp_get_the_notification_mark_link();
    999 }
    1000     /**
    1001      * Return the mark link for the current notification.
    1002      *
    1003      * @since 1.9.0
    1004      *
    1005      * @return string
    1006      */
    1007     function bp_get_the_notification_mark_link() {
    1008 
    1009         if ( bp_is_current_action( 'read' ) ) {
    1010             $retval = bp_get_the_notification_mark_unread_link();
    1011         } else {
    1012             $retval = bp_get_the_notification_mark_read_link();
    1013         }
    1014 
    1015         /**
    1016          * Filters the mark link for the current notification.
    1017          *
    1018          * @since 1.9.0
    1019          *
    1020          * @param string $retval The mark link for the current notification.
    1021          */
    1022         return apply_filters( 'bp_get_the_notification_mark_link', $retval );
    1023     }
    1024 
    1025 /**
    1026  * Output the delete link for the current notification.
    1027  *
    1028  * @since 1.9.0
    1029  *
    1030  * @uses bp_get_the_notification_delete_link()
    1031  */
    1032 function bp_the_notification_delete_link() {
    1033     echo bp_get_the_notification_delete_link();
    1034 }
    1035     /**
    1036      * Return the delete link for the current notification.
    1037      *
    1038      * @since 1.9.0
    1039      *
    1040      * @return string
    1041      */
    1042     function bp_get_the_notification_delete_link() {
    1043 
    1044         // Start the output buffer.
    1045         ob_start(); ?>
    1046 
    1047         <a href="<?php bp_the_notification_delete_url(); ?>" class="delete secondary confirm"><?php _e( 'Delete', 'buddypress' ); ?></a>
    1048 
    1049         <?php $retval = ob_get_clean();
    1050 
    1051         /**
    1052          * Filters the delete link for the current notification.
    1053          *
    1054          * @since 1.9.0
    1055          *
    1056          * @param string $retval HTML for the delete link for the current notification.
    1057          */
    1058         return apply_filters( 'bp_get_the_notification_delete_link', $retval );
    1059     }
    1060 
    1061 /**
    1062  * Output the URL used for deleting a single notification.
    1063  *
    1064  * Since this function directly outputs a URL, it is escaped.
    1065  *
    1066  * @since 2.1.0
    1067  *
    1068  * @uses esc_url()
    1069  * @uses bp_get_the_notification_delete_url()
    1070  */
    1071 function bp_the_notification_delete_url() {
    1072     echo esc_url( bp_get_the_notification_delete_url() );
    1073 }
    1074     /**
    1075      * Return the URL used for deleting a single notification.
    1076      *
    1077      * @since 2.1.0
    1078      *
    1079      * @return string
    1080      */
    1081     function bp_get_the_notification_delete_url() {
    1082 
    1083         // URL to add nonce to.
    1084         if ( bp_is_current_action( 'unread' ) ) {
    1085             $link = bp_get_notifications_unread_permalink();
    1086         } elseif ( bp_is_current_action( 'read' ) ) {
    1087             $link = bp_get_notifications_read_permalink();
    1088         }
    1089 
    1090         // Get the ID.
    1091         $id = bp_get_the_notification_id();
    1092 
    1093         // Get the args to add to the URL.
    1094         $args = array(
    1095             'action'          => 'delete',
    1096             'notification_id' => $id
    1097         );
    1098 
    1099         // Add the args.
    1100         $url = add_query_arg( $args, $link );
    1101 
    1102         // Add the nonce.
    1103         $url = wp_nonce_url( $url, 'bp_notification_delete_' . $id );
    1104 
    1105         /**
    1106          * Filters the URL used for deleting a single notification.
    1107          *
    1108          * @since 2.1.0
    1109          *
    1110          * @param string $url URL used for deleting a single notification.
    1111          */
    1112         return apply_filters( 'bp_get_the_notification_delete_url', $url );
    1113     }
    1114 
    1115 /**
    1116  * Output the action links for the current notification.
    1117  *
    1118  * @since 1.9.0
    1119  *
    1120  * @param array|string $args Array of arguments.
    1121  */
    1122 function bp_the_notification_action_links( $args = '' ) {
    1123     echo bp_get_the_notification_action_links( $args );
    1124 }
    1125     /**
    1126      * Return the action links for the current notification.
    1127      *
    1128      * @since 1.9.0
    1129      *
    1130      * @param array|string $args {
    1131      *     @type string $before HTML before the links.
    1132      *     @type string $after  HTML after the links.
    1133      *     @type string $sep    HTML between the links.
    1134      *     @type array  $links  Array of links to implode by 'sep'.
    1135      * }
    1136      * @return string HTML links for actions to take on single notifications.
    1137      */
    1138     function bp_get_the_notification_action_links( $args = '' ) {
    1139 
    1140         // Parse.
    1141         $r = wp_parse_args( $args, array(
    1142             'before' => '',
    1143             'after'  => '',
    1144             'sep'    => ' | ',
    1145             'links'  => array(
    1146                 bp_get_the_notification_mark_link(),
    1147                 bp_get_the_notification_delete_link()
    1148             )
    1149         ) );
    1150 
    1151         // Build the links.
    1152         $retval = $r['before'] . implode( $r['links'], $r['sep'] ) . $r['after'];
    1153 
    1154         /**
    1155          * Filters the action links for the current notification.
    1156          *
    1157          * @since 1.9.0
    1158          *
    1159          * @param string $retval HTML links for actions to take on single notifications.
    1160          */
    1161         return apply_filters( 'bp_get_the_notification_action_links', $retval );
    1162     }
    1163 
    1164 /**
    1165  * Output the pagination count for the current notification loop.
    1166  *
    1167  * @since 1.9.0
    1168  */
    1169 function bp_notifications_pagination_count() {
    1170     echo bp_get_notifications_pagination_count();
    1171 }
    1172     /**
    1173      * Return the pagination count for the current notification loop.
    1174      *
    1175      * @since 1.9.0
    1176      *
    1177      * @return string HTML for the pagination count.
    1178      */
    1179     function bp_get_notifications_pagination_count() {
    1180         $query_loop = buddypress()->notifications->query_loop;
    1181         $start_num  = intval( ( $query_loop->pag_page - 1 ) * $query_loop->pag_num ) + 1;
    1182         $from_num   = bp_core_number_format( $start_num );
    1183         $to_num     = bp_core_number_format( ( $start_num + ( $query_loop->pag_num - 1 ) > $query_loop->total_notification_count ) ? $query_loop->total_notification_count : $start_num + ( $query_loop->pag_num - 1 ) );
    1184         $total      = bp_core_number_format( $query_loop->total_notification_count );
    1185 
    1186         if ( 1 == $query_loop->total_notification_count ) {
    1187             $pag = __( 'Viewing 1 notification', 'buddypress' );
    1188         } else {
    1189             $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s notification', 'Viewing %1$s - %2$s of %3$s notifications', $query_loop->total_notification_count, 'buddypress' ), $from_num, $to_num, $total );
    1190         }
    1191 
    1192         /**
    1193          * Filters the pagination count for the current notification loop.
    1194          *
    1195          * @since 1.9.0
    1196          *
    1197          * @param string $pag HTML for the pagination count.
    1198          */
    1199         return apply_filters( 'bp_notifications_pagination_count', $pag );
    1200     }
    1201 
    1202 /**
    1203  * Output the pagination links for the current notification loop.
    1204  *
    1205  * @since 1.9.0
    1206  */
    1207 function bp_notifications_pagination_links() {
    1208     echo bp_get_notifications_pagination_links();
    1209 }
    1210     /**
    1211      * Return the pagination links for the current notification loop.
    1212      *
    1213      * @since 1.9.0
    1214      *
    1215      * @return string HTML for the pagination links.
    1216      */
    1217     function bp_get_notifications_pagination_links() {
    1218 
    1219         /**
    1220          * Filters the pagination links for the current notification loop.
    1221          *
    1222          * @since 1.9.0
    1223          *
    1224          * @param string $pag_links HTML for the pagination links.
    1225          */
    1226         return apply_filters( 'bp_get_notifications_pagination_links', buddypress()->notifications->query_loop->pag_links );
    1227     }
    1228 
    1229 /** Form Helpers **************************************************************/
    1230 
    1231 /**
    1232  * Output the form for changing the sort order of notifications.
    1233  *
    1234  * @since 1.9.0
    1235  */
    1236 function bp_notifications_sort_order_form() {
    1237 
    1238     // Setup local variables.
    1239     $orders   = array( 'DESC', 'ASC' );
    1240     $selected = 'DESC';
    1241 
    1242     // Check for a custom sort_order.
    1243     if ( !empty( $_REQUEST['sort_order'] ) ) {
    1244         if ( in_array( $_REQUEST['sort_order'], $orders ) ) {
    1245             $selected = $_REQUEST['sort_order'];
    1246         }
    1247     } ?>
    1248 
    1249     <form action="" method="get" id="notifications-sort-order">
    1250         <label for="notifications-sort-order-list"><?php esc_html_e( 'Order By:', 'buddypress' ); ?></label>
    1251 
    1252         <select id="notifications-sort-order-list" name="sort_order" onchange="this.form.submit();">
    1253             <option value="DESC" <?php selected( $selected, 'DESC' ); ?>><?php _e( 'Newest First', 'buddypress' ); ?></option>
    1254             <option value="ASC"  <?php selected( $selected, 'ASC'  ); ?>><?php _e( 'Oldest First', 'buddypress' ); ?></option>
    1255         </select>
    1256 
    1257         <noscript>
    1258             <input id="submit" type="submit" name="form-submit" class="submit" value="<?php esc_attr_e( 'Go', 'buddypress' ); ?>" />
    1259         </noscript>
    1260     </form>
    1261 
    1262 <?php
    1263 }
    1264 
    1265 /**
    1266  * Output the dropdown for bulk management of notifications.
    1267  *
    1268  * @since 2.2.0
    1269  */
    1270 function bp_notifications_bulk_management_dropdown() {
    1271     ?>
    1272     <label class="bp-screen-reader-text" for="notification-select"><?php _e( 'Select Bulk Action', 'buddypress' ); ?></label>
    1273     <select name="notification_bulk_action" id="notification-select">
    1274         <option value="" selected="selected"><?php _e( 'Bulk Actions', 'buddypress' ); ?></option>
    1275 
    1276         <?php if ( bp_is_current_action( 'unread' ) ) : ?>
    1277             <option value="read"><?php _e( 'Mark read', 'buddypress' ); ?></option>
    1278         <?php elseif ( bp_is_current_action( 'read' ) ) : ?>
    1279             <option value="unread"><?php _e( 'Mark unread', 'buddypress' ); ?></option>
    1280         <?php endif; ?>
    1281         <option value="delete"><?php _e( 'Delete', 'buddypress' ); ?></option>
    1282     </select>
    1283     <input type="submit" id="notification-bulk-manage" class="button action" value="<?php esc_attr_e( 'Apply', 'buddypress' ); ?>">
    1284     <?php
    1285 }
Note: See TracChangeset for help on using the changeset viewer.