/**
 * Add plugin core settings.
 * 
 * @param  (array) $def Array of existing settings
 * @return (array)      Updated settings
 */
function wpas_core_settings_general($def)
{
    $user_registration = boolval(get_option('users_can_register'));
    $registration_lbl = true === $user_registration ? _x('allowed', 'User registration is allowed', 'wpas') : _x('not allowed', 'User registration is not allowed', 'wpas');
    $settings = array('general' => array('name' => __('General', 'wpas'), 'options' => array(array('name' => __('Multiple Products', 'wpas'), 'id' => 'support_products', 'type' => 'checkbox', 'desc' => __('If you need to provide support for multiple products, please enable this option. You will then be able to add your products.', 'wpas'), 'default' => false), array('name' => __('Default Assignee', 'wpas'), 'id' => 'assignee_default', 'type' => 'select', 'desc' => __('Who to assign tickets to by default (if auto-assignment is enabled, this will only be used in case an assignment rule is incorrect).', 'wpas'), 'options' => isset($_GET['post_type']) && 'ticket' === $_GET['post_type'] && isset($_GET['page']) && 'settings' === $_GET['page'] ? wpas_list_users('edit_ticket') : array(), 'default' => ''), array('name' => __('Allow Registrations', 'wpas'), 'id' => 'allow_registrations', 'type' => 'checkbox', 'desc' => sprintf(__('Allow users to register on the support. This setting can be enabled even though the WordPress setting is disabled. Currently, registrations are %s by WordPress.', 'wpas'), "<strong>{$registration_lbl}</strong>"), 'default' => true), array('name' => __('Replies Order', 'wpas'), 'id' => 'replies_order', 'type' => 'radio', 'desc' => __('In which order should the replies be displayed (for both client and admin side)?', 'wpas'), 'options' => array('ASC' => __('Old to New', 'wpas'), 'DESC' => __('New to Old', 'wpas')), 'default' => 'ASC'), array('name' => __('Hide Closed', 'wpas'), 'id' => 'hide_closed', 'type' => 'checkbox', 'desc' => __('Only show open tickets when clicking the "All Tickets" link.', 'wpas'), 'default' => true), array('name' => __('Show Count', 'wpas'), 'id' => 'show_count', 'type' => 'checkbox', 'desc' => __('Display the number of open tickets in the admin menu.', 'wpas'), 'default' => true), array('name' => __('Old Tickets', 'wpas'), 'id' => 'old_ticket', 'type' => 'text', 'default' => 10, 'desc' => __('After how many days should a ticket be considered &laquo;old&raquo;?', 'wpas')), array('name' => __('Plugin Pages', 'wpas'), 'type' => 'heading'), array('name' => __('Ticket Submission', 'wpas'), 'id' => 'ticket_submit', 'type' => 'select', 'desc' => sprintf(__('The page used for ticket submission. This page should contain the shortcode %s', 'wpas'), '<code>[ticket-submit]</code>'), 'options' => wpas_list_pages(), 'default' => ''), array('name' => __('Tickets List', 'wpas'), 'id' => 'ticket_list', 'type' => 'select', 'desc' => sprintf(__('The page that will list all tickets for a client. This page should contain the shortcode %s', 'wpas'), '<code>[tickets]</code>'), 'options' => wpas_list_pages(), 'default' => ''), array('name' => __('Terms & Conditions', 'wpas'), 'type' => 'heading'), array('name' => __('Content', 'wpas'), 'id' => 'terms_conditions', 'type' => 'editor', 'default' => '', 'desc' => __('Terms & conditions are not mandatory. If you add terms, a mendatory checkbox will be added in the registration form. Users won\'t be able to register if they don\'t accept your terms', 'wpas'), 'settings' => array('quicktags' => true, 'textarea_rows' => 7)), array('name' => __('Credit', 'wpas'), 'type' => 'heading'), array('name' => __('Show Credit', 'wpas'), 'id' => 'credit_link', 'type' => 'checkbox', 'desc' => __('You like the plugin? Please help us spread the word by displaying a credit link at the bottom of your ticket submission page.', 'wpas'), 'default' => false))));
    return array_merge($def, $settings);
}
/**
 * Prepare the available options for the products
 *
 * @since 3.3
 * @return array
 */
function wpas_get_products_options()
{
    $products = array(array('name' => __('Multiple Products', 'awesome-support'), 'id' => 'support_products', 'type' => 'checkbox', 'desc' => __('If you need to provide support for multiple products, please enable this option. You will then be able to add your products.', 'awesome-support'), 'default' => false));
    $ecommerce_synced = WPAS_eCommerce_Integration::get_instance()->plugin;
    if (!is_null($ecommerce_synced)) {
        $plugin_name = ucwords(str_replace(array('-', '_'), ' ', $ecommerce_synced));
        $products[] = array('name' => sprintf(esc_html__('Synchronize %s Products', 'awesome-support'), $plugin_name), 'id' => 'support_products_' . $ecommerce_synced, 'type' => 'checkbox', 'desc' => sprintf(esc_html__('We have detected that you are using the e-commerce plugin %1$s. Would you like to automatically synchronize your e-commerce products with Awesome Support?', 'awesome-support'), $plugin_name), 'default' => true);
        $products[] = array('type' => 'note', 'desc' => wp_kses(sprintf(__('If you just disabled this option and want to remove the previously synchronized products, <a href="%1$s">please use the dedicated option &laquo;Delete Products&raquo;</a>', 'awesome-support'), esc_url(add_query_arg(array('post_type' => 'ticket', 'page' => 'wpas-status', 'tab' => 'tools'), admin_url('edit.php')))), array('a' => array('href' => array(), 'title' => array()))));
        $registered = WPAS_eCommerce_Integration::get_instance()->get_plugins();
        $post_type = $registered[$ecommerce_synced]['post_type'];
        $products[] = array('name' => __('Include Products', 'awesome-support'), 'id' => 'support_products_' . $ecommerce_synced . '_include', 'type' => 'select', 'multiple' => true, 'desc' => esc_html__('Which products do you want to synchronize with Awesome Support (leave blank for all products)', 'awesome-support'), 'options' => wpas_list_pages($post_type), 'default' => '');
        $products[] = array('name' => __('Exclude Products', 'awesome-support'), 'id' => 'support_products_' . $ecommerce_synced . '_exclude', 'type' => 'select', 'multiple' => true, 'desc' => esc_html__('Which products do you want to exclude from synchronization with Awesome Support (leave blank for no exclusion)', 'awesome-support'), 'options' => wpas_list_pages($post_type), 'default' => '');
        $products[] = array('type' => 'note', 'desc' => esc_html__('You cannot use the include and exclude options at the same time. Please use one or the other. You should use the option where you need to select the least amount of products.', 'awesome-support'));
    }
    return $products;
}
/**
 * Add plugin advanced settings.
 * 
 * @param  (array) $def Array of existing settings
 * @return (array)      Updated settings
 */
function wpas_core_settings_advanced($def)
{
    $settings = array('advanced' => array('name' => __('Advanced', 'awesome-support'), 'options' => array(array('name' => __('Custom Login / Registration Page', 'awesome-support'), 'id' => 'login_page', 'type' => 'select', 'desc' => sprintf(__('Only use this option if you know how to create your own registration page, otherwise you might create an infinite redirect. If you need help on creating a registration page you should <a href="%s" target="_blank">start by reading this guide</a>.', 'awesome-support'), esc_url('http://codex.wordpress.org/Customizing_the_Registration_Form')), 'default' => '', 'options' => wpas_list_pages()), array('name' => __('Admins See All', 'awesome-support'), 'id' => 'admin_see_all', 'type' => 'checkbox', 'desc' => __('Administrators can see all tickets in the tickets list. If unchecked admins will only see tickets assigned to them.', 'awesome-support'), 'default' => true), array('name' => __('Agent See All', 'awesome-support'), 'id' => 'agent_see_all', 'type' => 'checkbox', 'desc' => __('Agents can see all tickets in the tickets list. If unchecked agents will only see tickets assigned to them.', 'awesome-support'), 'default' => false), array('name' => __('Danger Zone', 'awesome-support'), 'type' => 'heading'), array('name' => __('Delete Data', 'awesome-support'), 'id' => 'delete_data', 'type' => 'checkbox', 'default' => false, 'desc' => __('Delete ALL plugin data on uninstall? This cannot be undone.', 'awesome-support')))));
    return array_merge($def, $settings);
}