| 1 |
<?php |
| 2 |
/** |
| 3 |
* Custom Posts. |
| 4 |
* |
| 5 |
* Register custom posts. |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace Whols\Admin; |
| 11 |
|
| 12 |
/** |
| 13 |
* Cusotm_Posts class. |
| 14 |
*/ |
| 15 |
class Custom_Posts{ |
| 16 |
/** |
| 17 |
* Custom posts constructor. |
| 18 |
* |
| 19 |
* @since 1.0.0 |
| 20 |
*/ |
| 21 |
public function __construct() { |
| 22 |
add_action( 'init', array( $this, 'custom_post_type' ) ); |
| 23 |
|
| 24 |
// Delete request when an user deleted from the database |
| 25 |
add_action( 'delete_user', array( $this, 'delete_request' ), 10, 3 ); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Register User Request Custom Post Type. |
| 30 |
* |
| 31 |
* @since 1.0.0 |
| 32 |
*/ |
| 33 |
function custom_post_type() { |
| 34 |
$labels = array( |
| 35 |
'name' => esc_html_x( 'Wholsaler Requests', 'Post Type General Name', 'whols' ), |
| 36 |
'singular_name' => esc_html_x( 'Wholesaler Request', 'Post Type Singular Name', 'whols' ), |
| 37 |
'menu_name' => esc_html__( 'Wholsaler Requests', 'whols' ), |
| 38 |
'name_admin_bar' => esc_html__( 'Wholsaler Request', 'whols' ), |
| 39 |
'archives' => esc_html__( 'Request Archives', 'whols' ), |
| 40 |
'attributes' => esc_html__( 'Request Attributes', 'whols' ), |
| 41 |
'parent_item_colon' => esc_html__( 'Parent Request:', 'whols' ), |
| 42 |
'all_items' => esc_html__( 'Wholesaler Requests', 'whols' ), |
| 43 |
'add_new_item' => esc_html__( 'Add New Request', 'whols' ), |
| 44 |
'add_new' => esc_html__( 'Add New', 'whols' ), |
| 45 |
'new_item' => esc_html__( 'New Request', 'whols' ), |
| 46 |
'edit_item' => esc_html__( 'Edit Request', 'whols' ), |
| 47 |
'update_item' => esc_html__( 'Update Request', 'whols' ), |
| 48 |
'view_item' => esc_html__( 'View Request', 'whols' ), |
| 49 |
'view_items' => esc_html__( 'View Requests', 'whols' ), |
| 50 |
'search_items' => esc_html__( 'Search Request', 'whols' ), |
| 51 |
'not_found' => esc_html__( 'Not found', 'whols' ), |
| 52 |
'not_found_in_trash' => esc_html__( 'Not found in Trash', 'whols' ), |
| 53 |
'featured_image' => esc_html__( 'Featured Image', 'whols' ), |
| 54 |
'set_featured_image' => esc_html__( 'Set featured image', 'whols' ), |
| 55 |
'remove_featured_image' => esc_html__( 'Remove featured image', 'whols' ), |
| 56 |
'use_featured_image' => esc_html__( 'Use as featured image', 'whols' ), |
| 57 |
'insert_into_item' => esc_html__( 'Insert into request', 'whols' ), |
| 58 |
'uploaded_to_this_item' => esc_html__( 'Uploaded to this request', 'whols' ), |
| 59 |
'items_list' => esc_html__( 'Requests list', 'whols' ), |
| 60 |
'items_list_navigation' => esc_html__( 'Requests list navigation', 'whols' ), |
| 61 |
'filter_items_list' => esc_html__( 'Filter requests list', 'whols' ), |
| 62 |
); |
| 63 |
|
| 64 |
$args = array( |
| 65 |
'label' => esc_html__( 'Wholesaler Request', 'whols' ), |
| 66 |
'description' => esc_html__( 'Wholsaler Requests', 'whols' ), |
| 67 |
'labels' => $labels, |
| 68 |
'supports' => array( 'title' ), |
| 69 |
'hierarchical' => false, |
| 70 |
'public' => false, |
| 71 |
'show_ui' => true, |
| 72 |
'show_in_menu' => 'whols-admin', // set it as a submenu |
| 73 |
'menu_position' => 5, |
| 74 |
'show_in_admin_bar' => true, |
| 75 |
'show_in_nav_menus' => false, |
| 76 |
'can_export' => true, |
| 77 |
'has_archive' => false, |
| 78 |
'exclude_from_search' => true, |
| 79 |
'publicly_queryable' => false, |
| 80 |
'capability_type' => 'product', |
| 81 |
'map_meta_cap' => true |
| 82 |
); |
| 83 |
|
| 84 |
register_post_type( 'whols_user_request', $args ); |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Delete Wholesaler request |
| 90 |
* |
| 91 |
* @since 1.0.0 |
| 92 |
*/ |
| 93 |
public function delete_request($id, $reassign, $user){ |
| 94 |
$request_id = get_user_meta($id, 'whols_request_id', true); |
| 95 |
|
| 96 |
if($request_id){ |
| 97 |
wp_delete_post($request_id); |
| 98 |
} |
| 99 |
} |
| 100 |
} |