Last active
June 2, 2021 05:51
-
-
Save wbcomdev/99a602a04204db1f1b4dccee69a82946 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Create admin product tab at single groups page. | |
| * | |
| * @return void | |
| */ | |
| function wbcom_add_admin_product_nav_at_single_group_page() { | |
| global $bp; | |
| /* Add some group subnav items */ | |
| $user_access = false; | |
| $group_link = ''; | |
| $user_id = get_current_user_id(); | |
| $group_id = $bp->groups->current_group->id; | |
| $user_admin = groups_is_user_admin( $user_id, $group_id ); | |
| if ( $user_admin ) { | |
| if ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) ) { | |
| $group_link = $bp->root_domain . '/' . bp_get_groups_root_slug() . '/' . $bp->groups->current_group->slug . '/'; | |
| $user_access = $bp->groups->current_group->user_has_access; | |
| bp_core_new_subnav_item( | |
| array( | |
| 'name' => __( 'Admin Products', 'Admin Products' ), | |
| 'slug' => 'admin-products', | |
| 'parent_url' => $group_link, | |
| 'parent_slug' => $bp->groups->current_group->slug, | |
| 'screen_function' => 'wbcom_display_admin_product_screen', | |
| 'position' => 50, | |
| 'user_has_access' => $user_access, | |
| 'item_css_id' => 'admin-products', | |
| ) | |
| ); | |
| } | |
| } | |
| } | |
| add_action( 'bp_init', 'wbcom_add_admin_product_nav_at_single_group_page' ); | |
| /** | |
| * Admin Prodcuct tab screens content. | |
| */ | |
| function wbcom_display_admin_product_screen() { | |
| add_action( 'bp_template_title', 'wbcom_admin_product_show_screen_title' ); | |
| add_action( 'bp_template_content', 'wbcom_admin_show_screen_content' ); | |
| $templates = array( 'groups/single/plugins.php', 'plugin-template.php' ); | |
| if ( strstr( locate_template( $templates ), 'groups/single/plugins.php' ) ) { | |
| bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'groups/single/plugins' ) ); | |
| } else { | |
| bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'plugin-template' ) ); | |
| } | |
| } | |
| /** | |
| * Admin Prodcuct tab title. | |
| */ | |
| function wbcom_admin_product_show_screen_title() { | |
| echo 'Admins Product'; | |
| } | |
| /** | |
| * Admin Prodcuct tab content. | |
| */ | |
| function wbcom_admin_show_screen_content() { | |
| global $bp; | |
| $group_id = bp_get_group_id(); | |
| $group_admins = groups_get_group_admins( $group_id ); | |
| $admin_id = $group_admins[0]->user_id; | |
| $args = array( | |
| 'post_type' => 'product', | |
| 'post_status' => 'publish', | |
| 'posts_per_page' => 12, | |
| 'author' => $admin_id, | |
| ); | |
| $loop = new WP_Query( $args ); | |
| ?> | |
| <div class="author_products"> | |
| <?php if ( $loop->have_posts() ) { ?> | |
| <ul class="author_pubproducts"> | |
| <?php | |
| while ( $loop->have_posts() ) : | |
| $loop->the_post(); | |
| woocommerce_get_template_part( 'content', 'product' ); | |
| endwhile; | |
| ?> | |
| </ul> | |
| <?php | |
| } else { | |
| echo esc_html_e( 'No products found', 'wbcom-woocommerce' ); | |
| } | |
| wp_reset_postdata(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment