[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Notifications functions 4 * 5 * @since 3.0.0 6 * @version 3.1.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Register Scripts for the Notifications component 14 * 15 * @since 3.0.0 16 * 17 * @param array $scripts The array of scripts to register 18 * @return array The same array with the specific notifications scripts. 19 */ 20 function bp_nouveau_notifications_register_scripts( $scripts = array() ) { 21 22 if ( ! isset( $scripts['bp-nouveau'] ) ) { 23 return $scripts; 24 } 25 26 return array_merge( $scripts, array( 27 'bp-nouveau-notifications' => array( 28 'file' => 'js/buddypress-notifications%s.js', 29 'dependencies' => array( 'bp-nouveau' ), 30 'footer' => true, 31 ), 32 ) ); 33 } 34 35 /** 36 * Enqueue the notifications scripts 37 * 38 * @since 3.0.0 39 */ 40 function bp_nouveau_notifications_enqueue_scripts() { 41 42 if ( ! bp_is_user_notifications() ) { 43 return; 44 } 45 46 wp_enqueue_script( 'bp-nouveau-notifications' ); 47 } 48 49 /** 50 * Init Notifications filters and fire a hook to let 51 * plugins/components register their filters. 52 * 53 * @since 3.0.0 54 */ 55 function bp_nouveau_notifications_init_filters() { 56 if ( ! bp_is_user_notifications() ) { 57 return; 58 } 59 60 bp_nouveau()->notifications->filters = array(); 61 62 /** 63 * Hook here to register your custom notification filters 64 * 65 * @since 3.0.0 66 */ 67 do_action( 'bp_nouveau_notifications_init_filters' ); 68 } 69 70 /** 71 * Register new filters for the notifications screens. 72 * 73 * @since 3.0.0 74 * 75 * @param array $args { 76 * Array of arguments. 77 * 78 * @type string $id The unique string to identify your "component action". Required. 79 * @type string $label The human readable notification type. Required. 80 * @type int $position The position to output your filter. Optional. 81 * } 82 * @return bool True if the filter has been successfully registered. False otherwise. 83 */ 84 function bp_nouveau_notifications_register_filter( $args = array() ) { 85 $bp_nouveau = bp_nouveau(); 86 87 $r = bp_parse_args( 88 $args, 89 array( 90 'id' => '', 91 'label' => '', 92 'position' => 99, 93 ), 94 'nouveau_notifications_register_filter' 95 ); 96 97 if ( empty( $r['id'] ) || empty( $r['label'] ) ) { 98 return false; 99 } 100 101 if ( isset( $bp_nouveau->notifications->filters[ $r['id'] ] ) ) { 102 return false; 103 } 104 105 $bp_nouveau->notifications->filters[ $r['id'] ] = $r; 106 return true; 107 } 108 109 /** 110 * Get one or all notifications filters. 111 * 112 * @since 3.0.0 113 * 114 * @param string $id The notificication component action to get the filter of. 115 * Leave empty to get all notifications filters. 116 * @return array|false All or a specific notifications parameters. False if no match are found. 117 */ 118 function bp_nouveau_notifications_get_filters( $id = '' ) { 119 $bp_nouveau = bp_nouveau(); 120 121 // Get all filters 122 if ( empty( $id ) ) { 123 return $bp_nouveau->notifications->filters; 124 125 // Get a specific filter 126 } elseif ( ! empty( $id ) && isset( $bp_nouveau->notifications->filters[ $id ] ) ) { 127 return $bp_nouveau->notifications->filters[ $id ]; 128 129 } else { 130 return false; 131 } 132 } 133 134 /** 135 * Sort Notifications according to their position arguments. 136 * 137 * @since 3.0.0 138 * 139 * @param array $filters The notifications filters to order. 140 * @return array The sorted filters. 141 */ 142 function bp_nouveau_notifications_sort( $filters = array() ) { 143 $sorted = array(); 144 145 if ( empty( $filters ) || ! is_array( $filters ) ) { 146 return $sorted; 147 } 148 149 foreach ( $filters as $filter ) { 150 $position = 99; 151 152 if ( isset( $filter['position'] ) ) { 153 $position = (int) $filter['position']; 154 } 155 156 // If position is already taken, move to the first next available 157 if ( isset( $sorted[ $position ] ) ) { 158 $sorted_keys = array_keys( $sorted ); 159 160 do { 161 $position += 1; 162 } while ( in_array( $position, $sorted_keys, true ) ); 163 } 164 165 $sorted[ $position ] = $filter; 166 } 167 168 ksort( $sorted ); 169 return $sorted; 170 } 171 172 /** 173 * Add a dashicon to Notifications action links 174 * 175 * @since 3.0.0 176 * 177 * @param string $link The action link. 178 * @param string $bp_tooltip The data-bp-attribute of the link. 179 * @param string $aria_label The aria-label attribute of the link. 180 * @param string $dashicon The dashicon class. 181 * @return string Link Output. 182 */ 183 function bp_nouveau_notifications_dashiconified_link( $link = '', $bp_tooltip = '', $dashicon = '' ) { 184 preg_match( '/<a\s[^>]*>(.*)<\/a>/siU', $link, $match ); 185 186 if ( ! empty( $match[0] ) && ! empty( $match[1] ) && ! empty( $dashicon ) && ! empty( $bp_tooltip ) ) { 187 $link = str_replace( 188 '>' . $match[1] . '<', 189 sprintf( 190 ' class="bp-tooltip" data-bp-tooltip="%1$s"><span class="dashicons %2$s" aria-hidden="true"></span><span class="bp-screen-reader-text">%3$s</span><', 191 esc_attr( $bp_tooltip ), 192 sanitize_html_class( $dashicon ), 193 $match[1] 194 ), 195 $match[0] 196 ); 197 } 198 199 return $link; 200 } 201 202 /** 203 * Edit the Mark Unread action link to include a dashicon 204 * 205 * @since 3.0.0 206 * 207 * @param string $link Optional. The Mark Unread action link. 208 * 209 * @return string Link Output. 210 */ 211 function bp_nouveau_notifications_mark_unread_link( $link = '' ) { 212 return bp_nouveau_notifications_dashiconified_link( 213 $link, 214 _x( 'Mark Unread', 'link', 'buddypress' ), 215 'dashicons-hidden' 216 ); 217 } 218 219 /** 220 * Edit the Mark Read action link to include a dashicon 221 * 222 * @since 3.0.0 223 * 224 * @param string $link Optional. The Mark Read action link. 225 * 226 * @return string Link Output. 227 */ 228 function bp_nouveau_notifications_mark_read_link( $link = '' ) { 229 return bp_nouveau_notifications_dashiconified_link( 230 $link, 231 _x( 'Mark Read', 'link', 'buddypress' ), 232 'dashicons-visibility' 233 ); 234 } 235 236 /** 237 * Edit the Delete action link to include a dashicon 238 * 239 * @since 3.0.0 240 * 241 * @param string $link Optional. The Delete action link. 242 * 243 * @return string Link Output. 244 */ 245 function bp_nouveau_notifications_delete_link( $link = '' ) { 246 return bp_nouveau_notifications_dashiconified_link( 247 $link, 248 _x( 'Delete', 'link', 'buddypress' ), 249 'dashicons-dismiss' 250 ); 251 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |