| @@ -1,0 +1,72 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Earners Meta Boxes | |
| 4 | + * | |
| 5 | + * @package GamiPress\Admin\Meta_Boxes\Earners | |
| 6 | + * @author GamiPress <[email protected]>, Ruben Garcia <[email protected]> | |
| 7 | + * @since 1.8.7 | |
| 8 | + */ | |
| 9 | +// Exit if accessed directly | |
| 10 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Add earners meta boxes | |
| 14 | + * | |
| 15 | + * @since 1.8.7 | |
| 16 | + * | |
| 17 | + * @return void | |
| 18 | + */ | |
| 19 | +function gamipress_add_earners_meta_box() { | |
| 20 | + | |
| 21 | + // Steps | |
| 22 | + foreach ( gamipress_get_achievement_types_slugs() as $achievement_type ) { | |
| 23 | + add_meta_box( 'gamipress-earners', __( 'Earners', 'gamipress' ), 'gamipress_earners_meta_box', $achievement_type, 'advanced', 'default' ); | |
| 24 | + } | |
| 25 | + | |
| 26 | + // Rank Requirements | |
| 27 | + foreach ( gamipress_get_rank_types_slugs() as $rank_type ) { | |
| 28 | + add_meta_box( 'gamipress-earners', __( 'Earners', 'gamipress' ), 'gamipress_earners_meta_box', $rank_type, 'advanced', 'default' ); | |
| 29 | + } | |
| 30 | + | |
| 31 | +} | |
| 32 | +add_action( 'add_meta_boxes', 'gamipress_add_earners_meta_box' ); | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Renders the HTML for meta box, refreshes whenever a new point award is added | |
| 36 | + * | |
| 37 | + * @since 1.0.5 | |
| 38 | + * @updated 1.3.7 Added $metabox | |
| 39 | + * | |
| 40 | + * @param WP_Post $post The current post object. | |
| 41 | + * @param array $metabox With metabox id, title, callback, and args elements. | |
| 42 | + * | |
| 43 | + * @return void | |
| 44 | + */ | |
| 45 | +function gamipress_earners_meta_box( $post = null, $metabox = array() ) { | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Filter to allow set the number of user earnings to show on the earners meta box | |
| 49 | + * | |
| 50 | + * @since 1.8.7 | |
| 51 | + * | |
| 52 | + * @param int $items_per_page | |
| 53 | + * @param WP_Post $post The current post object. | |
| 54 | + * @param array $metabox With metabox id, title, callback, and args elements. | |
| 55 | + * | |
| 56 | + * @return int | |
| 57 | + */ | |
| 58 | + $items_per_page = apply_filters( 'gamipress_earners_meta_box_items_per_page', 10, $post, $metabox ); | |
| 59 | + | |
| 60 | + ct_render_ajax_list_table( 'gamipress_user_earnings', | |
| 61 | + array( | |
| 62 | + 'post_id' => $post->ID, | |
| 63 | + 'items_per_page' => $items_per_page, | |
| 64 | + 'is_earners_box' => 1, | |
| 65 | + ), | |
| 66 | + array( | |
| 67 | + 'views' => false, | |
| 68 | + 'search_box' => false | |
| 69 | + ) | |
| 70 | + ); | |
| 71 | + | |
| 72 | +} | |