| 1276 | /** |
| 1277 | * Output the Add new post button to blog. |
| 1278 | * |
| 1279 | * @since BuddyPress (2.2.0) |
| 1280 | */ |
| 1281 | function bp_blog_new_post_button() { |
| 1282 | echo bp_get_blog_new_post_button(); |
| 1283 | } |
| 1284 | /** |
| 1285 | * Get the Add new post to blog button. |
| 1286 | * |
| 1287 | * @since BuddyPress (2.2.0) |
| 1288 | * |
| 1289 | * @see BP_Button for a complete description of arguments and return |
| 1290 | * value. |
| 1291 | * |
| 1292 | * @param array $args { |
| 1293 | * Arguments are listed below, with their default values. For a |
| 1294 | * complete description of arguments, see {@link BP_Button}. |
| 1295 | * @type string $id Default: 'add_blog_post'. |
| 1296 | * @type string $component Default: 'blogs'. |
| 1297 | * @type bool $must_be_logged_in Default: true. |
| 1298 | * @type bool $block_self Default: false. |
| 1299 | * @type string $wrapper_class Default: 'blog-button add-post'. |
| 1300 | * @type string $link_href Permalink of the wp-admin/post-new.php current blog in the loop. |
| 1301 | * @type string $link_class Default: 'blog-button add-post'. |
| 1302 | * @type string $link_text Default: 'New post'. |
| 1303 | * @type string $link_title Default: 'Add post to site'. |
| 1304 | * } |
| 1305 | * @return string The HTML for the Visit button. |
| 1306 | */ |
| 1307 | function bp_get_blog_new_post_button() { |
| 1308 | if ( ! is_user_logged_in() ) { |
| 1309 | return false; |
| 1310 | } |
| 1311 | $blog_id = bp_get_blog_id(); |
| 1312 | if ( ! is_super_admin() ) { |
| 1313 | $blogs = wp_cache_get( 'bp_blog_ids_of_user_' . bp_loggedin_user_id() . '_inc_hidden', 'bp' ); |
| 1314 | if ( empty( $blogs ) ) { |
| 1315 | $blogs = BP_Blogs_Blog::get_blog_ids_for_user( bp_loggedin_user_id() ); |
| 1316 | wp_cache_set( 'bp_blog_ids_of_user_' . bp_loggedin_user_id() . '_inc_hidden', $blogs, 'bp' ); |
| 1317 | } |
| 1318 | if ( ! in_array( $blog_id, $blogs ) ) { |
| 1319 | return false; |
| 1320 | } |
| 1321 | if ( ! bp_current_user_can( 'edit_posts', $blog_id ) ) { |
| 1322 | return false; |
| 1323 | } |
| 1324 | } |
| 1325 | $button_args = array( |
| 1326 | 'id' => 'add_blog_post', |
| 1327 | 'component' => 'blogs', |
| 1328 | 'must_be_logged_in' => true, |
| 1329 | 'block_self' => false, |
| 1330 | 'link_text' => __( 'New post', 'buddypress' ), |
| 1331 | 'link_title' => __( 'Add post to site', 'buddypress' ), |
| 1332 | 'link_class' => 'blog-button add-post', |
| 1333 | 'link_href' => bp_get_blog_permalink() . 'wp-admin/post-new.php', |
| 1334 | 'wrapper_class' => 'blog-button add-post', |
| 1335 | ); |
| 1336 | return bp_get_button( apply_filters( 'bp_get_blog_new_post_button', $button_args ) ); |
| 1337 | } |
| 1338 | |
| 1339 | |