| 1 |
<?php |
| 2 |
|
| 3 |
namespace SpringDevs\Subscription\Illuminate; |
| 4 |
|
| 5 |
/** |
| 6 |
* Post class - managing `subscrpt_order` post. |
| 7 |
*/ |
| 8 |
class Post { |
| 9 |
|
| 10 |
/** |
| 11 |
* Initialize the class. |
| 12 |
*/ |
| 13 |
public function __construct() { |
| 14 |
add_action( 'init', array( $this, 'create_post_type' ) ); |
| 15 |
add_filter( 'post_updated_messages', array( $this, 'update_post_labels' ) ); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Add post labels on `subscrpt_order`. |
| 20 |
* |
| 21 |
* @param array $messages Messages. |
| 22 |
* |
| 23 |
* @return array |
| 24 |
*/ |
| 25 |
public function update_post_labels( $messages ) { |
| 26 |
$messages['subscrpt_order'] = array( |
| 27 |
__( 'Subscription updated.', 'subscription' ), |
| 28 |
__( 'Subscription updated.', 'subscription' ), |
| 29 |
'Custom field updated.', |
| 30 |
'Custom field deleted.', |
| 31 |
__( 'Subscription updated.', 'subscription' ), |
| 32 |
false, |
| 33 |
__( 'Subscription published.', 'subscription' ), |
| 34 |
__( 'Subscription saved.', 'subscription' ), |
| 35 |
__( 'Subscription submitted.', 'subscription' ), |
| 36 |
false, |
| 37 |
__( 'Subscription draft updated.', 'subscription' ), |
| 38 |
); |
| 39 |
return $messages; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Register `subscrpt_order` post type and statuses. |
| 44 |
* |
| 45 |
* @return void |
| 46 |
*/ |
| 47 |
public function create_post_type() { |
| 48 |
$this->register_subscription_post_type(); |
| 49 |
$this->register_subscription_item_post_type(); |
| 50 |
$this->register_post_status(); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Register ``subscrpt_order`` post type |
| 55 |
*/ |
| 56 |
public function register_subscription_post_type() { |
| 57 |
$labels = array( |
| 58 |
'name' => __( 'Subscriptions', 'subscription' ), |
| 59 |
'singular_name' => __( 'Subscription', 'subscription' ), |
| 60 |
'name_admin_bar' => __( 'Subscription\'s', 'subscription' ), |
| 61 |
'archives' => __( 'Item Archives', 'subscription' ), |
| 62 |
'attributes' => __( 'Item Attributes', 'subscription' ), |
| 63 |
'parent_item_colon' => __( 'Parent :', 'subscription' ), |
| 64 |
'all_items' => __( 'Subscriptions', 'subscription' ), |
| 65 |
'add_new_item' => __( 'Add New Subscription', 'subscription' ), |
| 66 |
'add_new' => __( 'Add Subscription', 'subscription' ), |
| 67 |
'new_item' => __( 'New Subscription', 'subscription' ), |
| 68 |
'edit_item' => __( 'Edit Subscription', 'subscription' ), |
| 69 |
'update_item' => __( 'Update Subscription', 'subscription' ), |
| 70 |
'view_item' => __( 'View Subscription', 'subscription' ), |
| 71 |
'view_items' => __( 'View Subscription', 'subscription' ), |
| 72 |
'search_items' => __( 'Search Subscription', 'subscription' ), |
| 73 |
'not_found' => __( 'No subscriptions found.', 'subscription' ), |
| 74 |
'item_updated' => __( 'Subscription updated.', 'subscription' ), |
| 75 |
); |
| 76 |
|
| 77 |
$args = array( |
| 78 |
'label' => __( 'Subscriptions', 'subscription' ), |
| 79 |
'labels' => $labels, |
| 80 |
'description' => '', |
| 81 |
'public' => false, |
| 82 |
'publicly_queryable' => false, |
| 83 |
'show_ui' => true, |
| 84 |
'delete_with_user' => false, |
| 85 |
'show_in_rest' => true, |
| 86 |
'rest_base' => '', |
| 87 |
'rest_controller_class' => 'WP_REST_Posts_Controller', |
| 88 |
'has_archive' => false, |
| 89 |
'show_in_menu' => false, |
| 90 |
'show_in_nav_menus' => false, |
| 91 |
'exclude_from_search' => false, |
| 92 |
'capability_type' => 'post', |
| 93 |
'map_meta_cap' => true, |
| 94 |
'capabilities' => array( |
| 95 |
'create_posts' => false, |
| 96 |
), |
| 97 |
'hierarchical' => false, |
| 98 |
'rewrite' => array( |
| 99 |
'slug' => 'subscrpt_order', |
| 100 |
'with_front' => true, |
| 101 |
), |
| 102 |
'query_var' => true, |
| 103 |
'supports' => false, |
| 104 |
); |
| 105 |
|
| 106 |
$args = apply_filters( 'subscrpt_order_post_args', $args ); |
| 107 |
|
| 108 |
register_post_type( 'subscrpt_order', $args ); |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Register ``subscrpt_order_item`` post type |
| 113 |
*/ |
| 114 |
public function register_subscription_item_post_type() { |
| 115 |
$args = array( |
| 116 |
'label' => __( 'Subscription Items', 'subscription' ), |
| 117 |
// 'labels' => , |
| 118 |
'description' => '', |
| 119 |
'public' => false, |
| 120 |
'publicly_queryable' => false, |
| 121 |
'show_ui' => false, |
| 122 |
'delete_with_user' => false, |
| 123 |
'show_in_rest' => true, |
| 124 |
'rest_base' => '', |
| 125 |
'rest_controller_class' => 'WP_REST_Posts_Controller', |
| 126 |
'has_archive' => false, |
| 127 |
'show_in_menu' => false, |
| 128 |
'show_in_nav_menus' => false, |
| 129 |
'exclude_from_search' => false, |
| 130 |
'capability_type' => 'post', |
| 131 |
'map_meta_cap' => true, |
| 132 |
'capabilities' => array( |
| 133 |
'create_posts' => false, |
| 134 |
), |
| 135 |
'hierarchical' => false, |
| 136 |
'rewrite' => array( |
| 137 |
'slug' => 'subscription_item', |
| 138 |
'with_front' => false, |
| 139 |
), |
| 140 |
'query_var' => true, |
| 141 |
'supports' => false, |
| 142 |
); |
| 143 |
|
| 144 |
$args = apply_filters( 'subscrpt_order_item_post_args', $args ); |
| 145 |
|
| 146 |
register_post_type( 'subscrpt_order_item', $args ); |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* Register custom post status. |
| 151 |
* |
| 152 |
* @return void |
| 153 |
*/ |
| 154 |
public function register_post_status() { |
| 155 |
register_post_status( |
| 156 |
'pending', |
| 157 |
array( |
| 158 |
'label' => _x( 'Pending', 'post status label', 'subscription' ), |
| 159 |
'public' => true, |
| 160 |
// translators: pending posts count. |
| 161 |
'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'subscription' ), |
| 162 |
'post_type' => array( 'subscrpt_order' ), |
| 163 |
'show_in_admin_all_list' => true, |
| 164 |
'show_in_admin_status_list' => true, |
| 165 |
'show_in_metabox_dropdown' => true, |
| 166 |
'show_in_inline_dropdown' => true, |
| 167 |
'dashicon' => '', |
| 168 |
) |
| 169 |
); |
| 170 |
|
| 171 |
register_post_status( |
| 172 |
'active', |
| 173 |
array( |
| 174 |
'label' => _x( 'Active', 'post status label', 'subscription' ), |
| 175 |
'public' => true, |
| 176 |
// translators: active posts count. |
| 177 |
'label_count' => _n_noop( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', 'subscription' ), |
| 178 |
'post_type' => array( 'subscrpt_order' ), |
| 179 |
'show_in_admin_all_list' => true, |
| 180 |
'show_in_admin_status_list' => true, |
| 181 |
'show_in_metabox_dropdown' => true, |
| 182 |
'show_in_inline_dropdown' => true, |
| 183 |
'dashicon' => '', |
| 184 |
) |
| 185 |
); |
| 186 |
|
| 187 |
register_post_status( |
| 188 |
'on_hold', |
| 189 |
array( |
| 190 |
'label' => _x( 'On Hold', 'post status label', 'subscription' ), |
| 191 |
'public' => true, |
| 192 |
// translators: on-hold posts count. |
| 193 |
'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'subscription' ), |
| 194 |
'post_type' => array( 'subscrpt_order' ), |
| 195 |
'show_in_admin_all_list' => true, |
| 196 |
'show_in_admin_status_list' => true, |
| 197 |
'show_in_metabox_dropdown' => true, |
| 198 |
'show_in_inline_dropdown' => true, |
| 199 |
'dashicon' => '', |
| 200 |
) |
| 201 |
); |
| 202 |
|
| 203 |
register_post_status( |
| 204 |
'cancelled', |
| 205 |
array( |
| 206 |
'label' => _x( 'Cancelled', 'post status label', 'subscription' ), |
| 207 |
'public' => true, |
| 208 |
// translators: cancelled posts count. |
| 209 |
'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'subscription' ), |
| 210 |
'post_type' => array( 'subscrpt_order' ), |
| 211 |
'show_in_admin_all_list' => true, |
| 212 |
'show_in_admin_status_list' => true, |
| 213 |
'show_in_metabox_dropdown' => true, |
| 214 |
'show_in_inline_dropdown' => true, |
| 215 |
'dashicon' => '', |
| 216 |
) |
| 217 |
); |
| 218 |
|
| 219 |
register_post_status( |
| 220 |
'expired', |
| 221 |
array( |
| 222 |
'label' => _x( 'Expired', 'post status label', 'subscription' ), |
| 223 |
'public' => true, |
| 224 |
// translators: expired posts count. |
| 225 |
'label_count' => _n_noop( 'Expired <span class="count">(%s)</span>', 'Expired <span class="count">(%s)</span>', 'subscription' ), |
| 226 |
'post_type' => array( 'subscrpt_order' ), |
| 227 |
'show_in_admin_all_list' => true, |
| 228 |
'show_in_admin_status_list' => true, |
| 229 |
'show_in_metabox_dropdown' => true, |
| 230 |
'show_in_inline_dropdown' => true, |
| 231 |
'dashicon' => '', |
| 232 |
) |
| 233 |
); |
| 234 |
|
| 235 |
register_post_status( |
| 236 |
'completed', |
| 237 |
array( |
| 238 |
'label' => _x( 'Completed', 'post status label', 'subscription' ), |
| 239 |
'public' => true, |
| 240 |
// translators: completed posts count. |
| 241 |
'label_count' => _n_noop( 'Completed <span class="count">(%s)</span>', 'Completed <span class="count">(%s)</span>', 'subscription' ), |
| 242 |
'post_type' => array( 'subscrpt_order' ), |
| 243 |
'show_in_admin_all_list' => true, |
| 244 |
'show_in_admin_status_list' => true, |
| 245 |
'show_in_metabox_dropdown' => true, |
| 246 |
'show_in_inline_dropdown' => true, |
| 247 |
'dashicon' => '', |
| 248 |
) |
| 249 |
); |
| 250 |
|
| 251 |
register_post_status( |
| 252 |
'pe_cancelled', |
| 253 |
array( |
| 254 |
'label' => _x( 'Pending Cancellation', 'post status label', 'subscription' ), |
| 255 |
'public' => true, |
| 256 |
// translators: pending cancellation posts count. |
| 257 |
'label_count' => _n_noop( 'Pending Cancellation <span class="count">(%s)</span>', 'Pending Cancellation <span class="count">(%s)</span>', 'subscription' ), |
| 258 |
'post_type' => array( 'subscrpt_order' ), |
| 259 |
'show_in_admin_all_list' => true, |
| 260 |
'show_in_admin_status_list' => true, |
| 261 |
'show_in_metabox_dropdown' => true, |
| 262 |
'show_in_inline_dropdown' => true, |
| 263 |
'dashicon' => '', |
| 264 |
) |
| 265 |
); |
| 266 |
} |
| 267 |
} |
| 268 |
|