getCustomFields();
if ( is_array( $customFields ) ) {
foreach ( $customFields as $field ) {
if ( ! empty( $field['file_path'] ) && file_exists( $field['file_path'] ) ) {
unlink( $field['file_path'] );
}
}
}
}
public function registerPostType() {
$labels = array(
'name' => _x( 'Quote Requests', 'post type general name', 'tier-pricing-table' ),
'singular_name' => _x( 'Quote Request', 'post type singular name', 'tier-pricing-table' ),
'menu_name' => _x( 'Quote Requests', 'admin menu', 'tier-pricing-table' ),
'name_admin_bar' => _x( 'Quote Request', 'add new on admin bar', 'tier-pricing-table' ),
'add_new' => _x( 'Add New', 'quote request', 'tier-pricing-table' ),
'add_new_item' => __( 'Add New Quote Request', 'tier-pricing-table' ),
'new_item' => __( 'New Quote Request', 'tier-pricing-table' ),
'edit_item' => __( 'Edit Quote Request', 'tier-pricing-table' ),
'view_item' => __( 'View Quote Request', 'tier-pricing-table' ),
'all_items' => __( 'All Quote Requests', 'tier-pricing-table' ),
'search_items' => __( 'Search Quote Requests', 'tier-pricing-table' ),
'not_found' => __( 'No quote requests found.', 'tier-pricing-table' ),
'not_found_in_trash' => __( 'No quote requests found in Trash.', 'tier-pricing-table' ),
);
$args = array(
'labels' => $labels,
'description' => __( 'Quote Requests.', 'tier-pricing-table' ),
'public' => false,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => false, // We will add it manually as a WooCommerce submenu
'query_var' => true,
'rewrite' => array( 'slug' => 'tpt-quote-request' ),
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'custom-fields' ),
);
register_post_type( self::POST_TYPE, $args );
$this->registerPostStatuses();
// Add this CPT to WC Navigation
if ( class_exists( PageController::class ) ) {
PageController::get_instance()->connect_page(
array(
'id' => 'tpt-quote-request',
'title' => __( 'Quote Requests', 'tier-pricing-table' ),
'screen_id' => 'edit-tpt-quote-request',
'path' => 'edit.php?post_type=' . self::POST_TYPE,
)
);
}
}
private function registerPostStatuses() {
register_post_status( 'unread', array(
'label' => _x( 'Unread', 'quote request status', 'tier-pricing-table' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
// translators: %s: number of requests.
'label_count' => _n_noop( 'Unread (%s)', 'Unread (%s)', 'tier-pricing-table' ),
) );
register_post_status( 'read', array(
'label' => _x( 'Read', 'quote request status', 'tier-pricing-table' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
// translators: %s: number of requests.
'label_count' => _n_noop( 'Read (%s)', 'Read (%s)', 'tier-pricing-table' ),
) );
register_post_status( 'converted', array(
'label' => _x( 'Converted', 'quote request status', 'tier-pricing-table' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
// translators: %s: number of requests.
'label_count' => _n_noop( 'Converted (%s)', 'Converted (%s)', 'tier-pricing-table' ),
) );
register_post_status( 'rejected', array(
'label' => _x( 'Rejected', 'quote request status', 'tier-pricing-table' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
// translators: %s: number of requests.
'label_count' => _n_noop( 'Rejected (%s)', 'Rejected (%s)', 'tier-pricing-table' ),
) );
}
public function addAdminMenu() {
$unreadCount = wp_count_posts( self::POST_TYPE )->unread ?? 0;
$menuTitle = __( 'Quote Requests', 'tier-pricing-table' );
if ( $unreadCount > 0 ) {
// translators: %s: number of unread requests.
$menuTitle .= ' ' . number_format_i18n( $unreadCount ) . '' . sprintf( _n( '%s unread request', '%s unread requests', $unreadCount, 'tier-pricing-table' ), number_format_i18n( $unreadCount ) ) . '';
}
add_submenu_page(
'woocommerce',
__( 'Quote Requests', 'tier-pricing-table' ),
$menuTitle,
'manage_woocommerce',
'edit.php?post_type=' . self::POST_TYPE
);
}
}