| 1 |
<?php |
| 2 |
|
| 3 |
namespace Booktics\Base\Services; |
| 4 |
|
| 5 |
/** |
| 6 |
* Handles registration of all custom post statuses for Booktics. |
| 7 |
*/ |
| 8 |
class Post_Status_Service { |
| 9 |
|
| 10 |
public $post_statuses = array( |
| 11 |
'active', |
| 12 |
'deactive', |
| 13 |
'pending', |
| 14 |
'canceled', |
| 15 |
'approved', |
| 16 |
'completed', |
| 17 |
'not_show', |
| 18 |
); |
| 19 |
|
| 20 |
/** |
| 21 |
* Get translated label for a specific post status. |
| 22 |
* |
| 23 |
* @param string $post_status The post status. |
| 24 |
* @return string The translated label. |
| 25 |
*/ |
| 26 |
private function get_label( $post_status ) { |
| 27 |
switch ( $post_status ) { |
| 28 |
case 'active': |
| 29 |
return __( 'Active', 'booktics' ); |
| 30 |
case 'deactive': |
| 31 |
return __( 'Deactive', 'booktics' ); |
| 32 |
case 'pending': |
| 33 |
return __( 'Pending', 'booktics' ); |
| 34 |
case 'canceled': |
| 35 |
return __( 'Canceled', 'booktics' ); |
| 36 |
case 'approved': |
| 37 |
return __( 'Approved', 'booktics' ); |
| 38 |
case 'completed': |
| 39 |
return __( 'Completed', 'booktics' ); |
| 40 |
case 'not_show': |
| 41 |
return __( 'Not Show', 'booktics' ); |
| 42 |
default: |
| 43 |
return __( 'Status', 'booktics' ); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Get label count for a specific post status. |
| 49 |
* |
| 50 |
* @param string $post_status The post status. |
| 51 |
* @return array The label count array. |
| 52 |
*/ |
| 53 |
private function get_label_count( $post_status ) { |
| 54 |
switch ( $post_status ) { |
| 55 |
case 'active': |
| 56 |
// translators: %s is the count of active items. |
| 57 |
return _n_noop( |
| 58 |
'Active <span class="count">(%s)</span>', |
| 59 |
'Active <span class="count">(%s)</span>', |
| 60 |
'booktics' |
| 61 |
); |
| 62 |
case 'deactive': |
| 63 |
// translators: %s is the count of deactive items. |
| 64 |
return _n_noop( |
| 65 |
'Deactive <span class="count">(%s)</span>', |
| 66 |
'Deactive <span class="count">(%s)</span>', |
| 67 |
'booktics' |
| 68 |
); |
| 69 |
case 'pending': |
| 70 |
// translators: %s is the count of pending items. |
| 71 |
return _n_noop( |
| 72 |
'Pending <span class="count">(%s)</span>', |
| 73 |
'Pending <span class="count">(%s)</span>', |
| 74 |
'booktics' |
| 75 |
); |
| 76 |
case 'canceled': |
| 77 |
// translators: %s is the count of canceled items. |
| 78 |
return _n_noop( |
| 79 |
'Canceled <span class="count">(%s)</span>', |
| 80 |
'Canceled <span class="count">(%s)</span>', |
| 81 |
'booktics' |
| 82 |
); |
| 83 |
case 'approved': |
| 84 |
// translators: %s is the count of approved items. |
| 85 |
return _n_noop( |
| 86 |
'Approved <span class="count">(%s)</span>', |
| 87 |
'Approved <span class="count">(%s)</span>', |
| 88 |
'booktics' |
| 89 |
); |
| 90 |
case 'completed': |
| 91 |
// translators: %s is the count of completed items. |
| 92 |
return _n_noop( |
| 93 |
'Completed <span class="count">(%s)</span>', |
| 94 |
'Completed <span class="count">(%s)</span>', |
| 95 |
'booktics' |
| 96 |
); |
| 97 |
case 'not_show': |
| 98 |
// translators: %s is the count of items not shown. |
| 99 |
return _n_noop( |
| 100 |
'Not Show <span class="count">(%s)</span>', |
| 101 |
'Not Show <span class="count">(%s)</span>', |
| 102 |
'booktics' |
| 103 |
); |
| 104 |
default: |
| 105 |
// translators: %s is the count of items with this status. |
| 106 |
return _n_noop( |
| 107 |
'Status <span class="count">(%s)</span>', |
| 108 |
'Status <span class="count">(%s)</span>', |
| 109 |
'booktics' |
| 110 |
); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Register all custom post statuses. |
| 116 |
*/ |
| 117 |
public function register() { |
| 118 |
foreach ( $this->post_statuses as $post_status ) { |
| 119 |
register_post_status( |
| 120 |
$post_status, array( |
| 121 |
'label' => $this->get_label( $post_status ), |
| 122 |
'public' => true, |
| 123 |
'publicly_queryable' => true, |
| 124 |
'exclude_from_search' => false, |
| 125 |
'show_in_admin_all_list' => true, |
| 126 |
'show_in_admin_status_list' => true, |
| 127 |
'label_count' => $this->get_label_count( $post_status ), |
| 128 |
) |
| 129 |
); |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
|