| 1 |
<?php |
| 2 |
/** |
| 3 |
* Post Types |
| 4 |
* |
| 5 |
* @package GamiPress\Post_Types |
| 6 |
* @author GamiPress <contact@gamipress.com>, Ruben Garcia <rubengcdev@gmail.com> |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Register all GamiPress types |
| 14 |
* |
| 15 |
* @since 1.8.9.1 |
| 16 |
*/ |
| 17 |
function gamipress_register_types() { |
| 18 |
|
| 19 |
// Requirement types |
| 20 |
gamipress_register_requirement_type( 'Points Award', 'Points Awards', 'points-award' ); |
| 21 |
gamipress_register_requirement_type( 'Points Deduction', 'Points Deductions', 'points-deduct' ); |
| 22 |
gamipress_register_requirement_type( 'Step', 'Steps', 'step' ); |
| 23 |
gamipress_register_requirement_type( 'Rank Requirement', 'Rank Requirements', 'rank-requirement' ); |
| 24 |
|
| 25 |
// Points types |
| 26 |
gamipress_register_points_types(); |
| 27 |
|
| 28 |
// Achievement types |
| 29 |
gamipress_register_achievement_types(); |
| 30 |
|
| 31 |
// Rank types |
| 32 |
gamipress_register_rank_types(); |
| 33 |
|
| 34 |
} |
| 35 |
add_action( 'gamipress_init', 'gamipress_register_types' ); |
| 36 |
|
| 37 |
/** |
| 38 |
* Register our various points types for use in the rules engine |
| 39 |
* |
| 40 |
* @since 1.0.0 |
| 41 |
* |
| 42 |
* @param integer $points_type_id Post id of the points type |
| 43 |
* @param string $points_name_singular The singular name |
| 44 |
* @param string $points_name_plural The plural name |
| 45 |
* @param string $slug If null or empty, slug will be auto-generated from singular name |
| 46 |
*/ |
| 47 |
function gamipress_register_points_type( $points_type_id = 0, $points_name_singular = '', $points_name_plural = '', $slug = null ) { |
| 48 |
|
| 49 |
if( $slug === null || empty( $slug ) ) { |
| 50 |
$slug = sanitize_title( strtolower( $points_name_singular ) ); |
| 51 |
} |
| 52 |
|
| 53 |
GamiPress()->points_types[sanitize_key( $slug )] = array( |
| 54 |
'ID' => $points_type_id, |
| 55 |
'singular_name' => $points_name_singular, |
| 56 |
'plural_name' => $points_name_plural, |
| 57 |
); |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Register each of our Points Types as WordPress post type |
| 63 |
* |
| 64 |
* @since 1.0.0 |
| 65 |
*/ |
| 66 |
function gamipress_register_points_types() { |
| 67 |
|
| 68 |
global $wpdb; |
| 69 |
|
| 70 |
$cache = gamipress_get_cache( 'gamipress_points_types', false, false ); |
| 71 |
|
| 72 |
// If result already cached, return it |
| 73 |
if( is_array( $cache ) ) { |
| 74 |
$points_types = $cache; |
| 75 |
} else { |
| 76 |
|
| 77 |
$posts = GamiPress()->db->posts; |
| 78 |
|
| 79 |
// Grab all points type posts |
| 80 |
$points_types = $wpdb->get_results( "SELECT * FROM {$posts} WHERE post_type = 'points-type' AND post_status = 'publish' ORDER BY post_title ASC" ); |
| 81 |
|
| 82 |
gamipress_set_cache( 'gamipress_points_types', $points_types ); |
| 83 |
} |
| 84 |
|
| 85 |
// Loop through each points type post and register it as a CPT |
| 86 |
foreach ( $points_types as $points_type ) { |
| 87 |
|
| 88 |
// Grab our points name |
| 89 |
$points_slug = $points_type->post_name; |
| 90 |
|
| 91 |
if( empty( $points_slug ) ) { |
| 92 |
continue; |
| 93 |
} |
| 94 |
|
| 95 |
// Update our post meta to use the points name, if it's empty |
| 96 |
if ( ! gamipress_get_post_meta( $points_type->ID, '_gamipress_plural_name' ) ) { |
| 97 |
update_post_meta( $points_type->ID, '_gamipress_plural_name', $points_slug ); |
| 98 |
} |
| 99 |
|
| 100 |
// Setup our singular and plural versions to use the corresponding meta |
| 101 |
$points_name_singular = $points_type->post_title; |
| 102 |
$points_name_plural = gamipress_get_post_meta( $points_type->ID, '_gamipress_plural_name' ); |
| 103 |
|
| 104 |
// Register the Achievement type |
| 105 |
gamipress_register_points_type( $points_type->ID, $points_name_singular, $points_name_plural, $points_slug ); |
| 106 |
} |
| 107 |
|
| 108 |
} |
| 109 |
add_action( 'init', 'gamipress_register_points_types', 6 ); |
| 110 |
|
| 111 |
/** |
| 112 |
* Register our various achievement types for use in the rules engine |
| 113 |
* |
| 114 |
* @since 1.0.0 |
| 115 |
* |
| 116 |
* @param integer $achievement_type_id Post id of the achievement type |
| 117 |
* @param string $achievement_name_singular The singular name |
| 118 |
* @param string $achievement_name_plural The plural name |
| 119 |
* @param string $slug If null or empty, slug will be auto-generated from singular name |
| 120 |
*/ |
| 121 |
function gamipress_register_achievement_type( $achievement_type_id = 0, $achievement_name_singular = '', $achievement_name_plural = '', $slug = null ) { |
| 122 |
|
| 123 |
if( $slug === null || empty( $slug ) ) { |
| 124 |
$slug = sanitize_title( strtolower( $achievement_name_singular ) ); |
| 125 |
} |
| 126 |
|
| 127 |
GamiPress()->achievement_types[sanitize_key( $slug )] = array( |
| 128 |
'ID' => $achievement_type_id, |
| 129 |
'singular_name' => $achievement_name_singular, |
| 130 |
'plural_name' => $achievement_name_plural, |
| 131 |
); |
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Register each of our Achievement Types as WordPress post type |
| 137 |
* |
| 138 |
* @since 1.0.0 |
| 139 |
*/ |
| 140 |
function gamipress_register_achievement_types() { |
| 141 |
|
| 142 |
global $wpdb; |
| 143 |
|
| 144 |
$cache = gamipress_get_cache( 'gamipress_achievement_types', false, false ); |
| 145 |
|
| 146 |
// If result already cached, return it |
| 147 |
if( is_array( $cache ) ) { |
| 148 |
$achievement_types = $cache; |
| 149 |
} else { |
| 150 |
$posts = GamiPress()->db->posts; |
| 151 |
|
| 152 |
// Grab all achievement type posts |
| 153 |
$achievement_types = $wpdb->get_results( "SELECT * FROM {$posts} WHERE post_type = 'achievement-type' AND post_status = 'publish' ORDER BY post_title ASC" ); |
| 154 |
|
| 155 |
gamipress_set_cache( 'gamipress_achievement_types', $achievement_types ); |
| 156 |
} |
| 157 |
|
| 158 |
// Loop through each achievement type post and register it as a CPT |
| 159 |
foreach ( $achievement_types as $achievement_type ) { |
| 160 |
|
| 161 |
// Grab our achievement name |
| 162 |
$achievement_slug = $achievement_type->post_name; |
| 163 |
|
| 164 |
if( empty( $achievement_slug ) ) { |
| 165 |
continue; |
| 166 |
} |
| 167 |
|
| 168 |
// Update our post meta to use the achievement name, if it's empty |
| 169 |
if ( ! gamipress_get_post_meta( $achievement_type->ID, '_gamipress_plural_name' ) ) { |
| 170 |
update_post_meta( $achievement_type->ID, '_gamipress_plural_name', $achievement_slug ); |
| 171 |
} |
| 172 |
|
| 173 |
// Setup our singular and plural versions to use the corresponding meta |
| 174 |
$achievement_name_singular = $achievement_type->post_title; |
| 175 |
$achievement_name_plural = gamipress_get_post_meta( $achievement_type->ID, '_gamipress_plural_name' ); |
| 176 |
|
| 177 |
// Register the Achievement type |
| 178 |
gamipress_register_achievement_type( $achievement_type->ID, $achievement_name_singular, $achievement_name_plural, $achievement_slug ); |
| 179 |
|
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* Register a requirement type |
| 185 |
* |
| 186 |
* @since 1.0.5 |
| 187 |
* |
| 188 |
* @param string $singular_name The singular name |
| 189 |
* @param string $plural_name The plural name |
| 190 |
* @param string $slug The slug |
| 191 |
*/ |
| 192 |
function gamipress_register_requirement_type( $singular_name = '', $plural_name = '', $slug = '' ) { |
| 193 |
|
| 194 |
if( empty( $slug ) ) { |
| 195 |
$slug = sanitize_key( sanitize_title( strtolower( $singular_name ) ) ); |
| 196 |
} |
| 197 |
|
| 198 |
GamiPress()->requirement_types[$slug] = array( |
| 199 |
'singular_name' => $singular_name, |
| 200 |
'plural_name' => $plural_name, |
| 201 |
); |
| 202 |
|
| 203 |
} |
| 204 |
|
| 205 |
/** |
| 206 |
* Register each of our Rank Types as WordPress post type |
| 207 |
* |
| 208 |
* @since 1.3.1 |
| 209 |
*/ |
| 210 |
function gamipress_register_rank_types() { |
| 211 |
|
| 212 |
global $wpdb; |
| 213 |
|
| 214 |
$cache = gamipress_get_cache( 'gamipress_rank_types', false, false ); |
| 215 |
|
| 216 |
// If result already cached, return it |
| 217 |
if( is_array( $cache ) ) { |
| 218 |
$rank_types = $cache; |
| 219 |
} else { |
| 220 |
$posts = GamiPress()->db->posts; |
| 221 |
|
| 222 |
// Grab all rank type posts |
| 223 |
$rank_types = $wpdb->get_results( "SELECT * FROM {$posts} WHERE post_type = 'rank-type' AND post_status = 'publish' ORDER BY post_title ASC" ); |
| 224 |
|
| 225 |
gamipress_set_cache( 'gamipress_rank_types', $rank_types ); |
| 226 |
} |
| 227 |
|
| 228 |
// Loop through each rank type post and register it as a CPT |
| 229 |
foreach ( $rank_types as $rank_type ) { |
| 230 |
|
| 231 |
// Grab our rank name |
| 232 |
$rank_slug = $rank_type->post_name; |
| 233 |
|
| 234 |
if( empty( $rank_slug ) ) { |
| 235 |
continue; |
| 236 |
} |
| 237 |
|
| 238 |
// Update our post meta to use the rank name, if it's empty |
| 239 |
if ( ! gamipress_get_post_meta( $rank_type->ID, '_gamipress_plural_name' ) ) { |
| 240 |
update_post_meta( $rank_type->ID, '_gamipress_plural_name', $rank_slug ); |
| 241 |
} |
| 242 |
|
| 243 |
// Setup our singular and plural versions to use the corresponding meta |
| 244 |
$rank_name_singular = $rank_type->post_title; |
| 245 |
$rank_name_plural = gamipress_get_post_meta( $rank_type->ID, '_gamipress_plural_name' ); |
| 246 |
|
| 247 |
// Register the rank type |
| 248 |
gamipress_register_rank_type( $rank_type->ID, $rank_name_singular, $rank_name_plural, $rank_slug ); |
| 249 |
|
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
/** |
| 254 |
* Register our various rank types for use in the rules engine |
| 255 |
* |
| 256 |
* @since 1.3.1 |
| 257 |
* |
| 258 |
* @param integer $rank_type_id Post id of the rank type |
| 259 |
* @param string $rank_name_singular The singular name |
| 260 |
* @param string $rank_name_plural The plural name |
| 261 |
* @param string $slug If null or empty, slug will be auto-generated from singular name |
| 262 |
*/ |
| 263 |
function gamipress_register_rank_type( $rank_type_id = 0, $rank_name_singular = '', $rank_name_plural = '', $slug = null ) { |
| 264 |
|
| 265 |
if( $slug === null || empty( $slug ) ) { |
| 266 |
$slug = sanitize_title( strtolower( $rank_name_singular ) ); |
| 267 |
} |
| 268 |
|
| 269 |
GamiPress()->rank_types[sanitize_key( $slug )] = array( |
| 270 |
'ID' => $rank_type_id, |
| 271 |
'singular_name' => $rank_name_singular, |
| 272 |
'plural_name' => $rank_name_plural, |
| 273 |
); |
| 274 |
|
| 275 |
} |
| 276 |
|
| 277 |
/** |
| 278 |
* Register WordPress post types |
| 279 |
* |
| 280 |
* @since 1.0.0 |
| 281 |
*/ |
| 282 |
function gamipress_register_post_types() { |
| 283 |
|
| 284 |
// Requirement types with a translatable name (due to WP change to move translations to init) |
| 285 |
gamipress_register_requirement_type( __( 'Points Award', 'gamipress' ), __( 'Points Awards', 'gamipress' ), 'points-award' ); |
| 286 |
gamipress_register_requirement_type( __( 'Points Deduction', 'gamipress' ), __( 'Points Deductions', 'gamipress' ), 'points-deduct' ); |
| 287 |
gamipress_register_requirement_type( __( 'Step', 'gamipress' ), __( 'Steps', 'gamipress' ), 'step' ); |
| 288 |
gamipress_register_requirement_type( __( 'Rank Requirement', 'gamipress' ), __( 'Rank Requirements', 'gamipress' ), 'rank-requirement' ); |
| 289 |
|
| 290 |
// Register Points Type |
| 291 |
register_post_type( 'points-type', array( |
| 292 |
'labels' => array( |
| 293 |
'name' => __( 'Points Types', 'gamipress' ), |
| 294 |
'singular_name' => __( 'Points Type', 'gamipress' ), |
| 295 |
'add_new' => __( 'Add New', 'gamipress' ), |
| 296 |
'add_new_item' => __( 'Add New Points Type', 'gamipress' ), |
| 297 |
'edit_item' => __( 'Edit Points Type', 'gamipress' ), |
| 298 |
'new_item' => __( 'New Points Type', 'gamipress' ), |
| 299 |
'all_items' => __( 'Points Types', 'gamipress' ), |
| 300 |
'view_item' => __( 'View Points Type', 'gamipress' ), |
| 301 |
'search_items' => __( 'Search Points Types', 'gamipress' ), |
| 302 |
'not_found' => __( 'No points types found', 'gamipress' ), |
| 303 |
'not_found_in_trash' => __( 'No points types found in Trash', 'gamipress' ), |
| 304 |
'parent_item_colon' => '', |
| 305 |
'menu_name' => __( 'Points Types', 'gamipress' ), |
| 306 |
'featured_image' => __( 'Points Type Image', 'gamipress' ), |
| 307 |
'set_featured_image' => __( 'Set points type image', 'gamipress' ), |
| 308 |
'remove_featured_image' => __( 'Remove points type image', 'gamipress' ), |
| 309 |
'use_featured_image' => __( 'Use points type image', 'gamipress' ), |
| 310 |
), |
| 311 |
'public' => false, |
| 312 |
'publicly_queryable' => false, |
| 313 |
'show_ui' => current_user_can( gamipress_get_manager_capability() ), |
| 314 |
'show_in_menu' => 'gamipress', |
| 315 |
'show_in_rest' => apply_filters( 'gamipress_show_points_types_in_rest', true ), |
| 316 |
'query_var' => false, |
| 317 |
'rewrite' => false, |
| 318 |
'capability_type' => 'post', |
| 319 |
'has_archive' => false, |
| 320 |
'hierarchical' => false, |
| 321 |
'menu_position' => null, |
| 322 |
'supports' => array( 'title', 'thumbnail' ), |
| 323 |
) ); |
| 324 |
|
| 325 |
// Register Points Award |
| 326 |
$public_points_awards = apply_filters( 'gamipress_public_points_awards', false ); |
| 327 |
|
| 328 |
register_post_type( 'points-award', array( |
| 329 |
'labels' => array( |
| 330 |
'name' => __( 'Points Awards', 'gamipress' ), |
| 331 |
'singular_name' => __( 'Points Award', 'gamipress' ), |
| 332 |
'add_new' => __( 'Add New', 'gamipress' ), |
| 333 |
'add_new_item' => __( 'Add New Points Award', 'gamipress' ), |
| 334 |
'edit_item' => __( 'Edit Points Award', 'gamipress' ), |
| 335 |
'new_item' => __( 'New Points Award', 'gamipress' ), |
| 336 |
'all_items' => __( 'Points Awards', 'gamipress' ), |
| 337 |
'view_item' => __( 'View Points Award', 'gamipress' ), |
| 338 |
'search_items' => __( 'Search Points Awards', 'gamipress' ), |
| 339 |
'not_found' => __( 'No points awards found', 'gamipress' ), |
| 340 |
'not_found_in_trash' => __( 'No points awards found in Trash', 'gamipress' ), |
| 341 |
'parent_item_colon' => '', |
| 342 |
'menu_name' => __( 'Points Awards', 'gamipress' ) |
| 343 |
), |
| 344 |
'public' => $public_points_awards, |
| 345 |
'publicly_queryable' => $public_points_awards, |
| 346 |
'show_ui' => current_user_can( gamipress_get_manager_capability() ), |
| 347 |
'show_in_menu' => ( ( $public_points_awards || gamipress_is_debug_mode() ) ? 'gamipress' : false ), |
| 348 |
'show_in_rest' => apply_filters( 'gamipress_show_points_awards_in_rest', true ), |
| 349 |
'query_var' => false, |
| 350 |
'rewrite' => false, |
| 351 |
'capability_type' => 'post', |
| 352 |
'has_archive' => $public_points_awards, |
| 353 |
'hierarchical' => true, |
| 354 |
'menu_position' => null, |
| 355 |
'supports' => array( 'title' ), |
| 356 |
|
| 357 |
) ); |
| 358 |
|
| 359 |
// Register Points Deduction |
| 360 |
$public_points_deducts = apply_filters( 'gamipress_public_points_deducts', false ); |
| 361 |
|
| 362 |
register_post_type( 'points-deduct', array( |
| 363 |
'labels' => array( |
| 364 |
'name' => __( 'Points Deductions', 'gamipress' ), |
| 365 |
'singular_name' => __( 'Points Deduction', 'gamipress' ), |
| 366 |
'add_new' => __( 'Add New', 'gamipress' ), |
| 367 |
'add_new_item' => __( 'Add New Points Deduction', 'gamipress' ), |
| 368 |
'edit_item' => __( 'Edit Points Deduction', 'gamipress' ), |
| 369 |
'new_item' => __( 'New Points Deduction', 'gamipress' ), |
| 370 |
'all_items' => __( 'Points Deductions', 'gamipress' ), |
| 371 |
'view_item' => __( 'View Points Deduction', 'gamipress' ), |
| 372 |
'search_items' => __( 'Search Points Deductions', 'gamipress' ), |
| 373 |
'not_found' => __( 'No points deductions found', 'gamipress' ), |
| 374 |
'not_found_in_trash' => __( 'No points deductions found in Trash', 'gamipress' ), |
| 375 |
'parent_item_colon' => '', |
| 376 |
'menu_name' => __( 'Points Deductions', 'gamipress' ) |
| 377 |
), |
| 378 |
'public' => $public_points_deducts, |
| 379 |
'publicly_queryable' => $public_points_deducts, |
| 380 |
'show_ui' => current_user_can( gamipress_get_manager_capability() ), |
| 381 |
'show_in_menu' => ( ( $public_points_deducts || gamipress_is_debug_mode() ) ? 'gamipress' : false ), |
| 382 |
'show_in_rest' => apply_filters( 'gamipress_show_points_deducts_in_rest', true ), |
| 383 |
'query_var' => false, |
| 384 |
'rewrite' => false, |
| 385 |
'capability_type' => 'post', |
| 386 |
'has_archive' => $public_points_deducts, |
| 387 |
'hierarchical' => true, |
| 388 |
'menu_position' => null, |
| 389 |
'supports' => array( 'title' ), |
| 390 |
|
| 391 |
) ); |
| 392 |
|
| 393 |
// Register Achievement Type |
| 394 |
register_post_type( 'achievement-type', array( |
| 395 |
'labels' => array( |
| 396 |
'name' => __( 'Achievement Types', 'gamipress' ), |
| 397 |
'singular_name' => __( 'Achievement Type', 'gamipress' ), |
| 398 |
'add_new' => __( 'Add New', 'gamipress' ), |
| 399 |
'add_new_item' => __( 'Add New Achievement Type', 'gamipress' ), |
| 400 |
'edit_item' => __( 'Edit Achievement Type', 'gamipress' ), |
| 401 |
'new_item' => __( 'New Achievement Type', 'gamipress' ), |
| 402 |
'all_items' => __( 'Achievement Types', 'gamipress' ), |
| 403 |
'view_item' => __( 'View Achievement Type', 'gamipress' ), |
| 404 |
'search_items' => __( 'Search Achievement Types', 'gamipress' ), |
| 405 |
'not_found' => __( 'No achievement types found', 'gamipress' ), |
| 406 |
'not_found_in_trash' => __( 'No achievement types found in Trash', 'gamipress' ), |
| 407 |
'parent_item_colon' => '', |
| 408 |
'menu_name' => __( 'Achievement Types', 'gamipress' ), |
| 409 |
'featured_image' => __( 'Default Achievement Image', 'gamipress' ), |
| 410 |
'set_featured_image' => __( 'Set default achievement image', 'gamipress' ), |
| 411 |
'remove_featured_image' => __( 'Remove default achievement image', 'gamipress' ), |
| 412 |
'use_featured_image' => __( 'Use default achievement image', 'gamipress' ), |
| 413 |
), |
| 414 |
'public' => false, |
| 415 |
'publicly_queryable' => false, |
| 416 |
'show_ui' => current_user_can( gamipress_get_manager_capability() ), |
| 417 |
'show_in_menu' => 'gamipress', |
| 418 |
'show_in_rest' => apply_filters( 'gamipress_show_achievement_types_in_rest', true ), |
| 419 |
'query_var' => false, |
| 420 |
'rewrite' => false, |
| 421 |
'capability_type' => 'post', |
| 422 |
'has_archive' => false, |
| 423 |
'hierarchical' => false, |
| 424 |
'menu_position' => null, |
| 425 |
'supports' => array( 'thumbnail' ), |
| 426 |
) ); |
| 427 |
|
| 428 |
// Register Step |
| 429 |
$public_steps = apply_filters( 'gamipress_public_steps', false ); |
| 430 |
|
| 431 |
register_post_type( 'step', array( |
| 432 |
'labels' => array( |
| 433 |
'name' => __( 'Steps', 'gamipress' ), |
| 434 |
'singular_name' => __( 'Step', 'gamipress' ), |
| 435 |
'add_new' => __( 'Add New', 'gamipress' ), |
| 436 |
'add_new_item' => __( 'Add New Step', 'gamipress' ), |
| 437 |
'edit_item' => __( 'Edit Step', 'gamipress' ), |
| 438 |
'new_item' => __( 'New Step', 'gamipress' ), |
| 439 |
'all_items' => __( 'Steps', 'gamipress' ), |
| 440 |
'view_item' => __( 'View Step', 'gamipress' ), |
| 441 |
'search_items' => __( 'Search Steps', 'gamipress' ), |
| 442 |
'not_found' => __( 'No steps found', 'gamipress' ), |
| 443 |
'not_found_in_trash' => __( 'No steps found in Trash', 'gamipress' ), |
| 444 |
'parent_item_colon' => '', |
| 445 |
'menu_name' => __( 'Steps', 'gamipress' ) |
| 446 |
), |
| 447 |
'public' => $public_steps, |
| 448 |
'publicly_queryable' => $public_steps, |
| 449 |
'show_ui' => current_user_can( gamipress_get_manager_capability() ), |
| 450 |
'show_in_menu' => ( ( $public_steps || gamipress_is_debug_mode() ) ? 'gamipress' : false ), |
| 451 |
'show_in_rest' => apply_filters( 'gamipress_show_steps_in_rest', true ), |
| 452 |
'query_var' => false, |
| 453 |
'rewrite' => false, |
| 454 |
'capability_type' => 'post', |
| 455 |
'has_archive' => $public_steps, |
| 456 |
'hierarchical' => true, |
| 457 |
'menu_position' => null, |
| 458 |
'supports' => array( 'title' ), |
| 459 |
|
| 460 |
) ); |
| 461 |
|
| 462 |
// Register Rank Type |
| 463 |
register_post_type( 'rank-type', array( |
| 464 |
'labels' => array( |
| 465 |
'name' => __( 'Rank Types', 'gamipress' ), |
| 466 |
'singular_name' => __( 'Rank Type', 'gamipress' ), |
| 467 |
'add_new' => __( 'Add New', 'gamipress' ), |
| 468 |
'add_new_item' => __( 'Add New Rank Type', 'gamipress' ), |
| 469 |
'edit_item' => __( 'Edit Rank Type', 'gamipress' ), |
| 470 |
'new_item' => __( 'New Rank Type', 'gamipress' ), |
| 471 |
'all_items' => __( 'Rank Types', 'gamipress' ), |
| 472 |
'view_item' => __( 'View Rank Type', 'gamipress' ), |
| 473 |
'search_items' => __( 'Search Rank Types', 'gamipress' ), |
| 474 |
'not_found' => __( 'No rank types found', 'gamipress' ), |
| 475 |
'not_found_in_trash' => __( 'No rank types found in Trash', 'gamipress' ), |
| 476 |
'parent_item_colon' => '', |
| 477 |
'menu_name' => __( 'Rank Types', 'gamipress' ), |
| 478 |
'featured_image' => __( 'Default Rank Image', 'gamipress' ), |
| 479 |
'set_featured_image' => __( 'Set default rank image', 'gamipress' ), |
| 480 |
'remove_featured_image' => __( 'Remove default rank image', 'gamipress' ), |
| 481 |
'use_featured_image' => __( 'Use default rank image', 'gamipress' ), |
| 482 |
), |
| 483 |
'public' => false, |
| 484 |
'publicly_queryable' => false, |
| 485 |
'show_ui' => current_user_can( gamipress_get_manager_capability() ), |
| 486 |
'show_in_menu' => 'gamipress', |
| 487 |
'show_in_rest' => apply_filters( 'gamipress_show_rank_types_in_rest', true ), |
| 488 |
'query_var' => false, |
| 489 |
'rewrite' => false, |
| 490 |
'capability_type' => 'post', |
| 491 |
'has_archive' => false, |
| 492 |
'hierarchical' => false, |
| 493 |
'menu_position' => null, |
| 494 |
'supports' => array( 'thumbnail' ), |
| 495 |
) ); |
| 496 |
|
| 497 |
// Register Rank Requirement |
| 498 |
$public_rank_requirements = apply_filters( 'gamipress_public_rank_requirements', false ); |
| 499 |
|
| 500 |
register_post_type( 'rank-requirement', array( |
| 501 |
'labels' => array( |
| 502 |
'name' => __( 'Rank Requirements', 'gamipress' ), |
| 503 |
'singular_name' => __( 'Rank Requirement', 'gamipress' ), |
| 504 |
'add_new' => __( 'Add New', 'gamipress' ), |
| 505 |
'add_new_item' => __( 'Add New Rank Requirement', 'gamipress' ), |
| 506 |
'edit_item' => __( 'Edit Rank Requirement', 'gamipress' ), |
| 507 |
'new_item' => __( 'New Rank Requirement', 'gamipress' ), |
| 508 |
'all_items' => __( 'Rank Requirements', 'gamipress' ), |
| 509 |
'view_item' => __( 'View Rank Requirement', 'gamipress' ), |
| 510 |
'search_items' => __( 'Search Rank Requirements', 'gamipress' ), |
| 511 |
'not_found' => __( 'No rank requirements found', 'gamipress' ), |
| 512 |
'not_found_in_trash' => __( 'No rank requirements found in Trash', 'gamipress' ), |
| 513 |
'parent_item_colon' => '', |
| 514 |
'menu_name' => __( 'Rank Requirements', 'gamipress' ) |
| 515 |
), |
| 516 |
'public' => $public_rank_requirements, |
| 517 |
'publicly_queryable' => $public_rank_requirements, |
| 518 |
'show_ui' => current_user_can( gamipress_get_manager_capability() ), |
| 519 |
'show_in_menu' => ( ( $public_rank_requirements || gamipress_is_debug_mode() ) ? 'gamipress' : false ), |
| 520 |
'show_in_rest' => apply_filters( 'gamipress_show_rank_requirements_in_rest', true ), |
| 521 |
'query_var' => false, |
| 522 |
'rewrite' => false, |
| 523 |
'capability_type' => 'post', |
| 524 |
'has_archive' => $public_rank_requirements, |
| 525 |
'hierarchical' => true, |
| 526 |
'menu_position' => null, |
| 527 |
'supports' => array( 'title' ), |
| 528 |
|
| 529 |
) ); |
| 530 |
|
| 531 |
// Achievement Types |
| 532 |
// Loop through each achievement type post and register it as a CPT |
| 533 |
foreach ( gamipress_get_achievement_types() as $achievement_type => $data ) { |
| 534 |
|
| 535 |
// Setup our singular and plural versions to use the corresponding meta |
| 536 |
$achievement_name_singular = $data['singular_name']; |
| 537 |
$achievement_name_plural = $data['plural_name']; |
| 538 |
|
| 539 |
/** |
| 540 |
* Available filter to make a desired achievement type not public |
| 541 |
* |
| 542 |
* @since 1.4.6 |
| 543 |
* |
| 544 |
* @param bool $return |
| 545 |
*/ |
| 546 |
$public = apply_filters( "gamipress_public_achievement_{$achievement_type}", true ); |
| 547 |
|
| 548 |
$post_type_args = array( |
| 549 |
'labels' => array( |
| 550 |
'name' => $achievement_name_plural, |
| 551 |
'singular_name' => $achievement_name_singular, |
| 552 |
'add_new' => __( 'Add New', 'gamipress' ), |
| 553 |
'add_new_item' => sprintf( __( 'Add New %s', 'gamipress' ), $achievement_name_singular ), |
| 554 |
'edit_item' => sprintf( __( 'Edit %s', 'gamipress' ), $achievement_name_singular ), |
| 555 |
'new_item' => sprintf( __( 'New %s', 'gamipress' ), $achievement_name_singular ), |
| 556 |
'all_items' => $achievement_name_plural, |
| 557 |
'view_item' => sprintf( __( 'View %s', 'gamipress' ), $achievement_name_singular ), |
| 558 |
'search_items' => sprintf( __( 'Search %s', 'gamipress' ), $achievement_name_plural ), |
| 559 |
'not_found' => sprintf( __( 'No %s found', 'gamipress' ), strtolower( $achievement_name_plural ) ), |
| 560 |
'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'gamipress' ), strtolower( $achievement_name_plural ) ), |
| 561 |
'parent_item_colon' => '', |
| 562 |
'menu_name' => $achievement_name_plural, |
| 563 |
'featured_image' => sprintf( __( '%s Image', 'gamipress' ), $achievement_name_singular ), |
| 564 |
'set_featured_image' => sprintf( __( 'Set %s image', 'gamipress' ), strtolower( $achievement_name_singular ) ), |
| 565 |
'remove_featured_image' => sprintf( __( 'Remove %s image', 'gamipress' ), strtolower( $achievement_name_singular ) ), |
| 566 |
'use_featured_image' => sprintf( __( 'Use %s image', 'gamipress' ), strtolower( $achievement_name_singular ) ), |
| 567 |
), |
| 568 |
'public' => $public, |
| 569 |
'publicly_queryable' => $public, |
| 570 |
'show_ui' => current_user_can( gamipress_get_manager_capability() ), |
| 571 |
'show_in_menu' => 'gamipress_achievements', |
| 572 |
'show_in_rest' => apply_filters( "gamipress_show_achievement_{$achievement_type}_in_rest", true ), |
| 573 |
'query_var' => true, |
| 574 |
'rewrite' => array( 'slug' => $achievement_type ), |
| 575 |
'capability_type' => 'post', |
| 576 |
'has_archive' => $public, |
| 577 |
'hierarchical' => true, |
| 578 |
'menu_position' => null, |
| 579 |
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'page-attributes' ) |
| 580 |
); |
| 581 |
|
| 582 |
/** |
| 583 |
* Available filter to override any achievement type post type args |
| 584 |
* |
| 585 |
* @since 1.4.6 |
| 586 |
* |
| 587 |
* @param array $post_type_args |
| 588 |
* @param string $achievement_type |
| 589 |
*/ |
| 590 |
$post_type_args = apply_filters( 'gamipress_achievement_post_type_args', $post_type_args, $achievement_type ); |
| 591 |
|
| 592 |
/** |
| 593 |
* Available filter to override a desired achievement type post type args |
| 594 |
* |
| 595 |
* @since 1.4.6 |
| 596 |
* |
| 597 |
* @param array $post_type_args |
| 598 |
*/ |
| 599 |
$post_type_args = apply_filters( "gamipress_achievement_{$achievement_type}_post_type_args", $post_type_args ); |
| 600 |
|
| 601 |
// Register the post type |
| 602 |
register_post_type( $achievement_type, $post_type_args ); |
| 603 |
|
| 604 |
} |
| 605 |
|
| 606 |
// Rank Types |
| 607 |
// Loop through each rank type post and register it as a CPT |
| 608 |
foreach ( gamipress_get_rank_types() as $rank_type => $data ) { |
| 609 |
|
| 610 |
// Setup our singular and plural versions to use the corresponding meta |
| 611 |
$rank_name_singular = $data['singular_name']; |
| 612 |
$rank_name_plural = $data['plural_name']; |
| 613 |
|
| 614 |
/** |
| 615 |
* Available filter to make a desired rank type not public |
| 616 |
* |
| 617 |
* @since 1.4.6 |
| 618 |
* |
| 619 |
* @param bool $return |
| 620 |
*/ |
| 621 |
$public = apply_filters( "gamipress_public_rank_{$rank_type}", true ); |
| 622 |
|
| 623 |
$post_type_args = array( |
| 624 |
'labels' => array( |
| 625 |
'name' => $rank_name_plural, |
| 626 |
'singular_name' => $rank_name_singular, |
| 627 |
'add_new' => __( 'Add New', 'gamipress' ), |
| 628 |
'add_new_item' => sprintf( __( 'Add New %s', 'gamipress' ), $rank_name_singular ), |
| 629 |
'edit_item' => sprintf( __( 'Edit %s', 'gamipress' ), $rank_name_singular ), |
| 630 |
'new_item' => sprintf( __( 'New %s', 'gamipress' ), $rank_name_singular ), |
| 631 |
'all_items' => $rank_name_plural, |
| 632 |
'view_item' => sprintf( __( 'View %s', 'gamipress' ), $rank_name_singular ), |
| 633 |
'search_items' => sprintf( __( 'Search %s', 'gamipress' ), $rank_name_plural ), |
| 634 |
'not_found' => sprintf( __( 'No %s found', 'gamipress' ), strtolower( $rank_name_plural ) ), |
| 635 |
'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'gamipress' ), strtolower( $rank_name_plural ) ), |
| 636 |
'parent_item_colon' => '', |
| 637 |
'menu_name' => $rank_name_plural, |
| 638 |
'featured_image' => sprintf( __( '%s Image', 'gamipress' ), $rank_name_singular ), |
| 639 |
'set_featured_image' => sprintf( __( 'Set %s image', 'gamipress' ), strtolower( $rank_name_singular ) ), |
| 640 |
'remove_featured_image' => sprintf( __( 'Remove %s image', 'gamipress' ), strtolower( $rank_name_singular ) ), |
| 641 |
'use_featured_image' => sprintf( __( 'Use %s image', 'gamipress' ), strtolower( $rank_name_singular ) ), |
| 642 |
), |
| 643 |
'public' => $public, |
| 644 |
'publicly_queryable' => $public, |
| 645 |
'show_ui' => current_user_can( gamipress_get_manager_capability() ), |
| 646 |
'show_in_menu' => 'gamipress_ranks', |
| 647 |
'show_in_rest' => apply_filters( "gamipress_show_rank_{$rank_type}_in_rest", true ), |
| 648 |
'query_var' => true, |
| 649 |
'rewrite' => array( 'slug' => $rank_type ), |
| 650 |
'capability_type' => 'post', |
| 651 |
'has_archive' => $public, |
| 652 |
'hierarchical' => true, |
| 653 |
'menu_position' => null, |
| 654 |
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail' ) |
| 655 |
); |
| 656 |
|
| 657 |
/** |
| 658 |
* Available filter to override any rank type post type args |
| 659 |
* |
| 660 |
* @since 1.4.6 |
| 661 |
* |
| 662 |
* @param array $post_type_args |
| 663 |
* @param string $rank_type |
| 664 |
*/ |
| 665 |
$post_type_args = apply_filters( 'gamipress_rank_post_type_args', $post_type_args, $rank_type ); |
| 666 |
|
| 667 |
/** |
| 668 |
* Available filter to override a desired rank type post type args |
| 669 |
* |
| 670 |
* @since 1.4.6 |
| 671 |
* |
| 672 |
* @param array $post_type_args |
| 673 |
*/ |
| 674 |
$post_type_args = apply_filters( "gamipress_rank_{$rank_type}_post_type_args", $post_type_args ); |
| 675 |
|
| 676 |
// Register the post type |
| 677 |
register_post_type( $rank_type, $post_type_args ); |
| 678 |
|
| 679 |
} |
| 680 |
|
| 681 |
} |
| 682 |
add_action( 'init', 'gamipress_register_post_types' ); |
| 683 |
|