| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handle custom post type registration |
| 4 |
* |
| 5 |
* @package UpStream |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
|
| 14 |
/** |
| 15 |
* Registers and sets up the Downloads custom post type |
| 16 |
* |
| 17 |
* @return void |
| 18 |
* @since 1.0 |
| 19 |
*/ |
| 20 |
function upstream_setup_post_types() { |
| 21 |
up_debug(); |
| 22 |
|
| 23 |
$project_base = upstream_get_project_base(); |
| 24 |
$client_base = upstream_get_client_base(); |
| 25 |
|
| 26 |
$project_labels = apply_filters( |
| 27 |
'upstream_project_labels', |
| 28 |
array( |
| 29 |
'name' => '%2$s', |
| 30 |
'singular_name' => '%1$s', |
| 31 |
// translators: %1s: project singular name. |
| 32 |
'add_new' => __( 'New %1s', 'upstream' ), |
| 33 |
// translators: %1s: project singular name. |
| 34 |
'add_new_item' => __( 'Add New %1$s', 'upstream' ), |
| 35 |
// translators: %1s: project singular name. |
| 36 |
'edit_item' => __( 'Edit %1$s', 'upstream' ), |
| 37 |
// translators: %1s: project singular name. |
| 38 |
'new_item' => __( 'New %1$s', 'upstream' ), |
| 39 |
'all_items' => '%2$s', |
| 40 |
// translators: %1s: project singular name. |
| 41 |
'view_item' => __( 'View %1$s', 'upstream' ), |
| 42 |
// translators: %2$s: project plural name. |
| 43 |
'search_items' => __( 'Search %2$s', 'upstream' ), |
| 44 |
// translators: %2$s: project plural name. |
| 45 |
'not_found' => __( 'No %2$s found', 'upstream' ), |
| 46 |
// translators: %2$s: project plural name. |
| 47 |
'not_found_in_trash' => __( 'No %2$s found in Trash', 'upstream' ), |
| 48 |
'parent_item_colon' => '', |
| 49 |
'menu_name' => '%2$s', |
| 50 |
// translators: %1s: project singular name. |
| 51 |
'featured_image' => __( '%1$s Image', 'upstream' ), |
| 52 |
// translators: %1s: project singular name. |
| 53 |
'set_featured_image' => __( 'Set %1$s Image', 'upstream' ), |
| 54 |
// translators: %1s: project singular name. |
| 55 |
'remove_featured_image' => __( 'Remove %1$s Image', 'upstream' ), |
| 56 |
// translators: %1s: project singular name. |
| 57 |
'use_featured_image' => __( 'Use as %1$s Image', 'upstream' ), |
| 58 |
// translators: %2$s: project plural name. |
| 59 |
'filter_items_list' => __( 'Filter %2$s list', 'upstream' ), |
| 60 |
// translators: %2$s: project plural name. |
| 61 |
'items_list_navigation' => __( '%2$s list navigation', 'upstream' ), |
| 62 |
// translators: %2$s: project plural name. |
| 63 |
'items_list' => __( '%2$s list', 'upstream' ), |
| 64 |
) |
| 65 |
); |
| 66 |
|
| 67 |
foreach ( $project_labels as $key => $value ) { |
| 68 |
$project_labels[ $key ] = sprintf( $value, upstream_project_label(), upstream_project_label_plural() ); |
| 69 |
} |
| 70 |
|
| 71 |
$project_args = array( |
| 72 |
'labels' => $project_labels, |
| 73 |
'public' => true, |
| 74 |
'publicly_queryable' => true, |
| 75 |
'show_ui' => true, |
| 76 |
'show_in_menu' => true, |
| 77 |
'menu_icon' => 'dashicons-arrow-up-alt', |
| 78 |
'menu_position' => is_plugin_active( 'woocommerce-product-vendors/woocommerce-product-vendors.php' ) ? 993 : 56, |
| 79 |
'query_var' => true, |
| 80 |
'rewrite' => array( |
| 81 |
'slug' => $project_base, |
| 82 |
'with_front' => false, |
| 83 |
), |
| 84 |
'capability_type' => 'project', |
| 85 |
'map_meta_cap' => true, |
| 86 |
'has_archive' => $project_base, |
| 87 |
'hierarchical' => false, |
| 88 |
'supports' => apply_filters( 'upstream_project_supports', array( 'title', 'revisions', 'author' ) ), |
| 89 |
); |
| 90 |
register_post_type( 'project', apply_filters( 'upstream_project_post_type_args', $project_args ) ); |
| 91 |
|
| 92 |
if ( upstream_is_clients_disabled() ) { |
| 93 |
return; |
| 94 |
} |
| 95 |
|
| 96 |
/* Client Post Type */ |
| 97 |
$client_labels = apply_filters( |
| 98 |
'upstream_client_labels', |
| 99 |
array( |
| 100 |
'name' => '%2$s', |
| 101 |
'singular_name' => '%1$s', |
| 102 |
// translators: %1s: client singular name. |
| 103 |
'add_new' => __( 'New %1s', 'upstream' ), |
| 104 |
// translators: %1s: client singular name. |
| 105 |
'add_new_item' => __( 'Add New %1$s', 'upstream' ), |
| 106 |
// translators: %1s: client singular name. |
| 107 |
'edit_item' => __( 'Edit %1$s', 'upstream' ), |
| 108 |
// translators: %1s: client singular name. |
| 109 |
'new_item' => __( 'New %1$s', 'upstream' ), |
| 110 |
'all_items' => '%2$s', |
| 111 |
// translators: %1s: client singular name. |
| 112 |
'view_item' => __( 'View %1$s', 'upstream' ), |
| 113 |
// translators: %2s: client singular name. |
| 114 |
'search_items' => __( 'Search %2$s', 'upstream' ), |
| 115 |
// translators: %2s: client singular name. |
| 116 |
'not_found' => __( 'No %2$s found', 'upstream' ), |
| 117 |
// translators: %2s: client singular name. |
| 118 |
'not_found_in_trash' => __( 'No %2$s found in Trash', 'upstream' ), |
| 119 |
'parent_item_colon' => '', |
| 120 |
'menu_name' => '%2$s', |
| 121 |
// translators: %1s: client singular name. |
| 122 |
'featured_image' => __( '%1$s Image', 'upstream' ), |
| 123 |
// translators: %1s: client singular name. |
| 124 |
'set_featured_image' => __( 'Set %1$s Image', 'upstream' ), |
| 125 |
// translators: %1s: client singular name. |
| 126 |
'remove_featured_image' => __( 'Remove %1$s Image', 'upstream' ), |
| 127 |
// translators: %1s: client singular name. |
| 128 |
'use_featured_image' => __( 'Use as %1$s Image', 'upstream' ), |
| 129 |
// translators: %2s: client singular name. |
| 130 |
'filter_items_list' => __( 'Filter %2$s list', 'upstream' ), |
| 131 |
// translators: %2s: client singular name. |
| 132 |
'items_list_navigation' => __( '%2$s list navigation', 'upstream' ), |
| 133 |
// translators: %2s: client singular name. |
| 134 |
'items_list' => __( '%2$s list', 'upstream' ), |
| 135 |
) |
| 136 |
); |
| 137 |
|
| 138 |
foreach ( $client_labels as $key => $value ) { |
| 139 |
$client_labels[ $key ] = sprintf( $value, upstream_client_label(), upstream_client_label_plural() ); |
| 140 |
} |
| 141 |
|
| 142 |
$client_args = array( |
| 143 |
'labels' => $client_labels, |
| 144 |
'public' => false, |
| 145 |
'publicly_queryable' => false, |
| 146 |
'show_ui' => true, |
| 147 |
'show_in_menu' => false, |
| 148 |
'query_var' => true, |
| 149 |
'rewrite' => array( |
| 150 |
'slug' => $client_base, |
| 151 |
'with_front' => false, |
| 152 |
), |
| 153 |
'capability_type' => 'client', |
| 154 |
'map_meta_cap' => true, |
| 155 |
'has_archive' => false, |
| 156 |
'hierarchical' => false, |
| 157 |
'supports' => apply_filters( 'upstream_client_supports', array( 'title', 'revisions' ) ), |
| 158 |
); |
| 159 |
register_post_type( 'client', apply_filters( 'upstream_client_post_type_args', $client_args ) ); |
| 160 |
|
| 161 |
\UpStream\Milestones::getInstance()->create_post_type(); |
| 162 |
} |
| 163 |
|
| 164 |
add_action( 'init', 'upstream_setup_post_types', 1 ); |
| 165 |
|
| 166 |
/** |
| 167 |
* Registers the custom taxonomies for the projects custom post type |
| 168 |
* |
| 169 |
* @return void |
| 170 |
* @since 1.0 |
| 171 |
*/ |
| 172 |
function upstream_setup_taxonomies() { |
| 173 |
if ( ! upstream_is_project_categorization_disabled() ) { |
| 174 |
|
| 175 |
$slug = defined( 'UPSTREAM_CAT_SLUG' ) ? UPSTREAM_CAT_SLUG : 'projects'; |
| 176 |
|
| 177 |
/** Categories */ |
| 178 |
$category_labels = array( |
| 179 |
'name' => _x( 'Category', 'taxonomy general name', 'upstream' ), |
| 180 |
'singular_name' => _x( 'Category', 'taxonomy singular name', 'upstream' ), |
| 181 |
'search_items' => sprintf( |
| 182 |
// translators: %s: upstream project label. |
| 183 |
__( 'Search %s Categories', 'upstream' ), |
| 184 |
upstream_project_label() |
| 185 |
), |
| 186 |
'all_items' => sprintf( |
| 187 |
// translators: %s: upstream project label. |
| 188 |
__( 'All %s Categories', 'upstream' ), |
| 189 |
upstream_project_label() |
| 190 |
), |
| 191 |
'parent_item' => sprintf( |
| 192 |
// translators: %s: upstream project label. |
| 193 |
__( 'Parent %s Category', 'upstream' ), |
| 194 |
upstream_project_label() |
| 195 |
), |
| 196 |
'parent_item_colon' => sprintf( |
| 197 |
// translators: %s: upstream project label. |
| 198 |
__( 'Parent %s Category:', 'upstream' ), |
| 199 |
upstream_project_label() |
| 200 |
), |
| 201 |
'edit_item' => sprintf( |
| 202 |
// translators: %s: upstream project label. |
| 203 |
__( 'Edit %s Category', 'upstream' ), |
| 204 |
upstream_project_label() |
| 205 |
), |
| 206 |
'update_item' => sprintf( |
| 207 |
// translators: %s: upstream project label. |
| 208 |
__( 'Update %s Category', 'upstream' ), |
| 209 |
upstream_project_label() |
| 210 |
), |
| 211 |
'add_new_item' => sprintf( |
| 212 |
// translators: %s: upstream project label. |
| 213 |
__( 'Add New %s Category', 'upstream' ), |
| 214 |
upstream_project_label() |
| 215 |
), |
| 216 |
'new_item_name' => sprintf( |
| 217 |
// translators: %s: upstream project label. |
| 218 |
__( 'New %s Category Name', 'upstream' ), |
| 219 |
upstream_project_label() |
| 220 |
), |
| 221 |
'menu_name' => __( 'Categories', 'upstream' ), |
| 222 |
); |
| 223 |
|
| 224 |
$category_args = apply_filters( |
| 225 |
'upstream_project_category_args', |
| 226 |
array( |
| 227 |
'hierarchical' => true, |
| 228 |
'labels' => apply_filters( '_upstream_project_category_labels', $category_labels ), |
| 229 |
'show_ui' => true, |
| 230 |
'show_in_rest' => true, |
| 231 |
'show_admin_column' => true, |
| 232 |
'query_var' => 'project_category', |
| 233 |
'rewrite' => array( |
| 234 |
'slug' => $slug . '/category', |
| 235 |
'with_front' => false, |
| 236 |
'hierarchical' => true, |
| 237 |
), |
| 238 |
'capabilities' => array( |
| 239 |
'manage_terms' => 'manage_project_terms', |
| 240 |
'edit_terms' => 'edit_project_terms', |
| 241 |
'assign_terms' => 'assign_project_terms', |
| 242 |
'delete_terms' => 'delete_project_terms', |
| 243 |
), |
| 244 |
) |
| 245 |
); |
| 246 |
|
| 247 |
register_taxonomy( 'project_category', array( 'project' ), $category_args ); |
| 248 |
register_taxonomy_for_object_type( 'project_category', 'project' ); |
| 249 |
|
| 250 |
/** Tags */ |
| 251 |
$tags_labels = array( |
| 252 |
'name' => _x( 'Tags', 'taxonomy (tag) general name', 'upstream' ), |
| 253 |
'singular_name' => _x( 'Tag', 'taxonomy (tag) singular name', 'upstream' ), |
| 254 |
'search_items' => __( 'Search Tags', 'upstream' ), |
| 255 |
'popular_items' => __( 'Popular Tags' ), |
| 256 |
'all_items' => __( 'All Tags', 'upstream' ), |
| 257 |
'parent_item' => null, |
| 258 |
'parent_item_colon' => null, |
| 259 |
'edit_item' => __( 'Edit Tag', 'upstream' ), |
| 260 |
'update_item' => __( 'Update Tag', 'upstream' ), |
| 261 |
'add_new_item' => __( 'Add New Tag', 'upstream' ), |
| 262 |
'new_item_name' => __( 'New Tag Name', 'upstream' ), |
| 263 |
'add_or_remove_items' => __( 'Add or remove tags' ), |
| 264 |
'separate_items_with_commas' => __( 'Separate tags with commas' ), |
| 265 |
'choose_from_most_used' => __( 'Choose from the most used tags' ), |
| 266 |
'menu_name' => __( 'Tags', 'upstream' ), |
| 267 |
); |
| 268 |
|
| 269 |
$args = array( |
| 270 |
'hierarchical' => false, |
| 271 |
'labels' => apply_filters( '_upstream_project_tags_labels', $tags_labels ), |
| 272 |
'show_ui' => true, |
| 273 |
'show_in_rest' => true, |
| 274 |
'show_admin_column' => true, |
| 275 |
'query_var' => 'upstream_tag', |
| 276 |
'rewrite' => array( |
| 277 |
'slug' => 'upstream/tag', |
| 278 |
'with_front' => false, |
| 279 |
'hierarchical' => false, |
| 280 |
), |
| 281 |
'capabilities' => array( |
| 282 |
'manage_terms' => 'manage_project_terms', |
| 283 |
'edit_terms' => 'edit_project_terms', |
| 284 |
'assign_terms' => 'assign_project_terms', |
| 285 |
'delete_terms' => 'delete_project_terms', |
| 286 |
), |
| 287 |
); |
| 288 |
|
| 289 |
register_taxonomy( 'upstream_tag', array( 'project' ), $args ); |
| 290 |
register_taxonomy_for_object_type( 'upstream_tag', 'project' ); |
| 291 |
|
| 292 |
} |
| 293 |
|
| 294 |
/** Milestone Categories */ |
| 295 |
$tags_labels = array( |
| 296 |
'name' => upstream_milestone_category_label_plural(), |
| 297 |
'singular_name' => upstream_milestone_category_label(), |
| 298 |
'search_items' => sprintf( |
| 299 |
// translators: %s: upstream_milestone_category_label_plural. |
| 300 |
__( 'Search %s', 'upstream' ), |
| 301 |
upstream_milestone_category_label_plural() |
| 302 |
), |
| 303 |
'popular_items' => sprintf( |
| 304 |
// translators: %s: upstream_milestone_category_label_plural. |
| 305 |
__( 'Popular %s' ), |
| 306 |
upstream_milestone_category_label_plural() |
| 307 |
), |
| 308 |
'all_items' => sprintf( |
| 309 |
// translators: %s: upstream_milestone_category_label_plural. |
| 310 |
__( 'All %s', 'upstream' ), |
| 311 |
upstream_milestone_category_label_plural() |
| 312 |
), |
| 313 |
'parent_item' => null, |
| 314 |
'parent_item_colon' => null, |
| 315 |
'edit_item' => sprintf( |
| 316 |
// translators: %s: upstream_milestone_category_label. |
| 317 |
__( 'Edit %s', 'upstream' ), |
| 318 |
upstream_milestone_category_label() |
| 319 |
), |
| 320 |
'update_item' => sprintf( |
| 321 |
// translators: %s: upstream_milestone_category_label. |
| 322 |
__( 'Update %s', 'upstream' ), |
| 323 |
upstream_milestone_category_label() |
| 324 |
), |
| 325 |
'add_new_item' => sprintf( |
| 326 |
// translators: %s: upstream_milestone_category_label. |
| 327 |
__( 'Add New %s', 'upstream' ), |
| 328 |
upstream_milestone_category_label() |
| 329 |
), |
| 330 |
'new_item_name' => sprintf( |
| 331 |
// translators: %s: upstream_milestone_category_label. |
| 332 |
__( 'New %s Name', 'upstream' ), |
| 333 |
upstream_milestone_category_label() |
| 334 |
), |
| 335 |
'add_or_remove_items' => sprintf( |
| 336 |
// translators: %s: upstream_milestone_category_label_plural. |
| 337 |
__( 'Add or remove %s' ), |
| 338 |
upstream_milestone_category_label_plural() |
| 339 |
), |
| 340 |
'separate_items_with_commas' => sprintf( |
| 341 |
// translators: %s: upstream_milestone_category_label. |
| 342 |
__( 'Separate %s with commas' ), |
| 343 |
upstream_milestone_category_label() |
| 344 |
), |
| 345 |
'choose_from_most_used' => sprintf( |
| 346 |
// translators: %s: upstream_milestone_category_label. |
| 347 |
__( 'Choose from the most used %s' ), |
| 348 |
upstream_milestone_category_label() |
| 349 |
), |
| 350 |
'menu_name' => upstream_milestone_category_label(), |
| 351 |
); |
| 352 |
|
| 353 |
if ( ! upstream_disable_milestone_categories() ) { |
| 354 |
$args = array( |
| 355 |
'hierarchical' => true, |
| 356 |
'labels' => apply_filters( '_upstream_milestone_categories_labels', $tags_labels ), |
| 357 |
'show_ui' => true, |
| 358 |
'show_in_rest' => true, |
| 359 |
'show_admin_column' => true, |
| 360 |
'query_var' => 'upstream_milestone_category', |
| 361 |
'rewrite' => array( |
| 362 |
'slug' => 'upstream/milestone_category', |
| 363 |
'with_front' => false, |
| 364 |
'hierarchical' => false, |
| 365 |
), |
| 366 |
'capabilities' => array( |
| 367 |
'manage_terms' => 'manage_project_terms', |
| 368 |
'edit_terms' => 'edit_project_terms', |
| 369 |
'assign_terms' => 'assign_project_terms', |
| 370 |
'delete_terms' => 'delete_project_terms', |
| 371 |
), |
| 372 |
); |
| 373 |
|
| 374 |
register_taxonomy( 'upst_milestone_category', array( 'upst_milestone' ), $args ); |
| 375 |
register_taxonomy_for_object_type( 'upst_milestone_category', 'upst_milestone' ); |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
add_action( 'init', 'upstream_setup_taxonomies', 1 ); |
| 380 |
|
| 381 |
/** |
| 382 |
* Milestone taxonomies custom fields. |
| 383 |
* |
| 384 |
* @param WP_Tax $taxonomy Taxonomy object. |
| 385 |
*/ |
| 386 |
function upstream_milestone_category_form_fields( $taxonomy ) { |
| 387 |
$value = ''; |
| 388 |
if ( is_object( $taxonomy ) ) { |
| 389 |
$value = get_term_meta( $taxonomy->term_id, 'color', true ); |
| 390 |
} |
| 391 |
|
| 392 |
wp_nonce_field( 'upstream_admin_milestone_category_form', 'upstream_admin_milestone_category_form_nonce' ); |
| 393 |
|
| 394 |
?> |
| 395 |
<tr class="form-field"> |
| 396 |
<th scope="row" valign="top"> |
| 397 |
<label for="term_color"><?php esc_html_e( 'Default color', 'upstream' ); ?></label> |
| 398 |
</th> |
| 399 |
<td> |
| 400 |
<input type="text" name="color" class="color-field" id="term_color" value="<?php echo esc_attr( $value ); ?>" /> |
| 401 |
<p class="description">Select a default color for milestones related to this category.</p> |
| 402 |
</td> |
| 403 |
</tr> |
| 404 |
<br> |
| 405 |
<?php |
| 406 |
} |
| 407 |
|
| 408 |
/** |
| 409 |
* Milestone taxonomies custom fields. |
| 410 |
* |
| 411 |
* @param int $term_id Term id. |
| 412 |
*/ |
| 413 |
function upstream_save_milestone_category_form_fields( $term_id ) { |
| 414 |
$post_data = isset( $_POST ) ? wp_unslash( $_POST ) : array(); |
| 415 |
$nonce = isset( $post_data['upstream_admin_milestone_category_form_nonce'] ) ? $post_data['upstream_admin_milestone_category_form_nonce'] : null; |
| 416 |
|
| 417 |
if ( ! wp_verify_nonce( $nonce, 'upstream_admin_milestone_category_form' ) ) { |
| 418 |
return; |
| 419 |
} |
| 420 |
|
| 421 |
if ( isset( $post_data['color'] ) ) { |
| 422 |
update_term_meta( $term_id, 'color', sanitize_hex_color( $post_data['color'] ) ); |
| 423 |
} |
| 424 |
} |
| 425 |
|
| 426 |
if ( ! upstream_is_project_categorization_disabled() ) { |
| 427 |
add_action( 'upst_milestone_category_add_form_fields', 'upstream_milestone_category_form_fields' ); |
| 428 |
add_action( 'upst_milestone_category_edit_form_fields', 'upstream_milestone_category_form_fields' ); |
| 429 |
add_action( 'edit_terms', 'upstream_save_milestone_category_form_fields' ); |
| 430 |
add_action( 'create_term', 'upstream_save_milestone_category_form_fields' ); |
| 431 |
} |
| 432 |
|