[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Blogs Template tags 4 * 5 * @since 3.0.0 6 * @version 6.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Template tag to wrap all Legacy actions that was used 14 * before the blogs directory content 15 * 16 * @since 3.0.0 17 */ 18 function bp_nouveau_before_blogs_directory_content() { 19 /** 20 * Fires at the begining of the templates BP injected content. 21 * 22 * @since 2.3.0 23 */ 24 do_action( 'bp_before_directory_blogs_page' ); 25 26 /** 27 * Fires before the display of the blogs. 28 * 29 * @since 1.5.0 30 */ 31 do_action( 'bp_before_directory_blogs' ); 32 33 /** 34 * Fires before the display of the blogs listing content. 35 * 36 * @since 3.0.0 37 */ 38 do_action( 'bp_before_directory_blogs_content' ); 39 40 /** 41 * Fires before the display of the blogs list tabs. 42 * 43 * @since 2.3.0 44 */ 45 do_action( 'bp_before_directory_blogs_tabs' ); 46 } 47 48 /** 49 * Template tag to wrap all Legacy actions that was used after the blogs directory content 50 * 51 * @since 3.0.0 52 */ 53 function bp_nouveau_after_blogs_directory_content() { 54 /** 55 * Fires inside and displays the blogs content. 56 * 57 * @since 3.0.0 58 */ 59 do_action( 'bp_directory_blogs_content' ); 60 61 /** 62 * Fires after the display of the blogs listing content. 63 * 64 * @since 3.0.0 65 */ 66 do_action( 'bp_after_directory_blogs_content' ); 67 68 /** 69 * Fires at the bottom of the blogs directory template file. 70 * 71 * @since 1.5.0 72 */ 73 do_action( 'bp_after_directory_blogs' ); 74 } 75 76 /** 77 * Fire specific hooks into the blogs create template 78 * 79 * @since 3.0.0 80 * 81 * @param string $when Optional. Either 'before' or 'after'. 82 * @param string $suffix Optional. Use it to add terms at the end of the hook name. 83 */ 84 function bp_nouveau_blogs_create_hook( $when = '', $suffix = '' ) { 85 $hook = array( 'bp' ); 86 87 if ( $when ) { 88 $hook[] = $when; 89 } 90 91 // It's a create a blog hook 92 $hook[] = 'create_blog'; 93 94 if ( $suffix ) { 95 $hook[] = $suffix; 96 } 97 98 bp_nouveau_hook( $hook ); 99 } 100 101 /** 102 * Fire an isolated hook inside the blogs loop 103 * 104 * @since 3.0.0 105 */ 106 function bp_nouveau_blogs_loop_item() { 107 /** 108 * Fires after the listing of a blog item in the blogs loop. 109 * 110 * @since 1.2.0 111 */ 112 do_action( 'bp_directory_blogs_item' ); 113 } 114 115 /** 116 * Output the action buttons inside the blogs loop. 117 * 118 * @since 3.0.0 119 * 120 * @param array $args See bp_nouveau_wrapper() for the description of parameters. 121 */ 122 function bp_nouveau_blogs_loop_buttons( $args = array() ) { 123 if ( empty( $GLOBALS['blogs_template'] ) ) { 124 return; 125 } 126 127 $args['type'] = 'loop'; 128 129 $output = join( ' ', bp_nouveau_get_blogs_buttons( $args ) ); 130 131 ob_start(); 132 /** 133 * Fires inside the blogs action listing area. 134 * 135 * @since 3.0.0 136 */ 137 do_action( 'bp_directory_blogs_actions' ); 138 $output .= ob_get_clean(); 139 140 if ( ! $output ) { 141 return; 142 } 143 144 bp_nouveau_wrapper( array_merge( $args, array( 'output' => $output ) ) ); 145 } 146 147 /** 148 * Get the action buttons for the current blog in the loop. 149 * 150 * @since 3.0.0 151 * 152 * @param string $type Type of Group of buttons to get. 153 * 154 * @return array 155 */ 156 function bp_nouveau_get_blogs_buttons( $args ) { 157 $type = ( ! empty( $args['type'] ) ) ? $args['type'] : 'loop'; 158 159 // @todo Not really sure why BP Legacy needed to do this... 160 if ( 'loop' !== $type && is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { 161 return array(); 162 } 163 164 $buttons = array(); 165 166 if ( isset( $GLOBALS['blogs_template']->blog ) ) { 167 $blog = $GLOBALS['blogs_template']->blog; 168 } 169 170 if ( empty( $blog->blog_id ) ) { 171 return $buttons; 172 } 173 174 /* 175 * If the 'container' is set to 'ul', set a var $parent_element to li, 176 * otherwise simply pass any value found in args or set var false. 177 */ 178 if ( ! empty( $args['container'] ) && 'ul' === $args['container'] ) { 179 $parent_element = 'li'; 180 } elseif ( ! empty( $args['parent_element'] ) ) { 181 $parent_element = $args['parent_element']; 182 } else { 183 $parent_element = false; 184 } 185 186 /* 187 * If we have a arg value for $button_element passed through 188 * use it to default all the $buttons['button_element'] values 189 * otherwise default to 'a' (anchor) 190 * Or override & hardcode the 'element' string on $buttons array. 191 * 192 * Icons sets a class for icon display if not using the button element 193 */ 194 $icons = ''; 195 if ( ! empty( $args['button_element'] ) ) { 196 $button_element = $args['button_element'] ; 197 } else { 198 $button_element = 'a'; 199 $icons = ' icons'; 200 } 201 202 /* 203 * This filter workaround is waiting for a core adaptation 204 * so that we can directly get the groups button arguments 205 * instead of the button. 206 * 207 * See https://buddypress.trac.wordpress.org/ticket/7126 208 */ 209 add_filter( 'bp_get_blogs_visit_blog_button', 'bp_nouveau_blogs_catch_button_args', 100, 1 ); 210 211 bp_get_blogs_visit_blog_button(); 212 213 remove_filter( 'bp_get_blogs_visit_blog_button', 'bp_nouveau_blogs_catch_button_args', 100, 1 ); 214 215 if ( isset( bp_nouveau()->blogs->button_args ) && bp_nouveau()->blogs->button_args ) { 216 $button_args = bp_nouveau()->blogs->button_args ; 217 218 // If we pass through parent classes add them to $button array 219 $parent_class = ''; 220 if ( ! empty( $args['parent_attr']['class'] ) ) { 221 $parent_class = $args['parent_attr']['class']; 222 } 223 224 // Set defaults if not set. 225 $button_args = array_merge( array( 226 'wrapper_id' => '', 227 'link_id' => '', 228 'link_rel' => '' 229 ), $button_args ); 230 231 $buttons['visit_blog'] = array( 232 'id' => 'visit_blog', 233 'position' => 5, 234 'component' => $button_args['component'], 235 'must_be_logged_in' => $button_args['must_be_logged_in'], 236 'block_self' => $button_args['block_self'], 237 'parent_element' => $parent_element, 238 'button_element' => $button_element, 239 'link_text' => $button_args['link_text'], 240 'parent_attr' => array( 241 'id' => $button_args['wrapper_id'], 242 'class' => $parent_class, 243 ), 244 'button_attr' => array( 245 'href' => $button_args['link_href'], 246 'id' => $button_args['link_id'], 247 'class' => $button_args['link_class'] . ' button', 248 'rel' => $button_args['link_rel'], 249 'title' => '', 250 ), 251 ); 252 253 unset( bp_nouveau()->blogs->button_args ); 254 } 255 256 /** 257 * Filter to add your buttons, use the position argument to choose where to insert it. 258 * 259 * @since 3.0.0 260 * 261 * @param array $buttons The list of buttons. 262 * @param object $blog The current blog object. 263 * @param string $type Whether we're displaying a blogs loop or a the blogs single item (in the future!). 264 */ 265 $buttons_group = apply_filters( 'bp_nouveau_get_blogs_buttons', $buttons, $blog, $type ); 266 267 if ( ! $buttons_group ) { 268 return array(); 269 } 270 271 // It's the first entry of the loop, so build the Group and sort it 272 if ( ! isset( bp_nouveau()->blogs->group_buttons ) || ! is_a( bp_nouveau()->blogs->group_buttons, 'BP_Buttons_Group' ) ) { 273 $sort = true; 274 bp_nouveau()->blogs->group_buttons = new BP_Buttons_Group( $buttons_group ); 275 276 // It's not the first entry, the order is set, we simply need to update the Buttons Group 277 } else { 278 $sort = false; 279 bp_nouveau()->blogs->group_buttons->update( $buttons_group ); 280 } 281 282 $return = bp_nouveau()->blogs->group_buttons->get( $sort ); 283 284 if ( ! $return ) { 285 return array(); 286 } 287 288 /** 289 * Leave a chance to adjust the $return 290 * 291 * @since 3.0.0 292 * 293 * @param array $return The list of buttons ordered. 294 * @param object $blog The current blog object. 295 * @param string $type Whether we're displaying a blogs loop or a the blogs single item (in the future!). 296 */ 297 do_action_ref_array( 'bp_nouveau_return_blogs_buttons', array( &$return, $blog, $type ) ); 298 299 return $return; 300 } 301 302 /** 303 * Check if the Sites has a latest post 304 * 305 * @since 3.0.0 306 * 307 * @return bool True if the sites has a latest post. False otherwise. 308 */ 309 function bp_nouveau_blog_has_latest_post() { 310 return (bool) bp_get_blog_latest_post_title(); 311 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 10 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |