Example #1
0
/**
 * Search element in database for shortcode insertion interface
 */
function ajax_wpshop_element_search()
{
    check_ajax_referer('wpshop_element_search', 'wpshop_ajax_nonce');
    $wpshop_element_searched = isset($_REQUEST['wpshop_element_searched']) ? wpshop_tools::varSanitizer($_REQUEST['wpshop_element_searched']) : null;
    $wpshop_element_type = isset($_REQUEST['wpshop_element_type']) ? wpshop_tools::varSanitizer($_REQUEST['wpshop_element_type']) : null;
    $wpshop_format_result = isset($_REQUEST['wpshop_format_result']) ? (bool) wpshop_tools::varSanitizer($_REQUEST['wpshop_format_result']) : true;
    switch ($wpshop_element_type) {
        case 'product':
        case WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT:
            $data = wpshop_products::product_list($wpshop_format_result, $wpshop_element_searched);
            break;
        case 'categories':
            $data = wpshop_categories::product_list_cats($wpshop_format_result, $wpshop_element_searched);
            break;
    }
    if ($wpshop_format_result) {
        $data = empty($data) ? __('No match', 'wpshop') : $data;
    } else {
        if (!empty($data)) {
            $temp_data = $data;
            unset($data);
            foreach ($temp_data as $post) {
                $data[$post->ID] = $post->ID . ' - ' . $post->post_title;
            }
        } else {
            $data = array();
        }
    }
    echo json_encode($data);
    die;
}
$type = isset($_GET['type']) ? wpshop_tools::varSanitizer($_GET['type']) : null;
$post_type = isset($_GET['post_type']) ? wpshop_tools::varSanitizer($_GET['post_type']) : null;
$display_option_display_type = true;
$display_option_grouped = true;
$display_search_form = true;
if (!empty($type)) {
    switch ($type) {
        case 'attribute_value':
            $display_option_grouped = false;
            $display_search_form = false;
            $display_option_grouped = false;
            $wpshop_wysiwyg_shortcode_inserter_shortcode_main_identifier = 'wpshop_att_val attid';
            $content = wpshop_attributes::get_attribute_list(null, $type, $post_type);
            break;
        case 'categories':
            $content = wpshop_categories::product_list_cats(true);
            $wpshop_wysiwyg_shortcode_inserter_shortcode_main_identifier = 'wpshop_category cid';
            ob_start();
            ?>
			<p><?php 
            _e('Shortcode options', 'wpshop');
            ?>
</p>
			<div id="wpshop_wysiwyg_shortcode_categorie_options_container" >
				<input type="checkbox" name="wpshop_wysiwyg_shortcode_options[]" id="wpshop_wysiwyg_shortcode_options_categorie_display_product" class="wpshop_wysiwyg_shortcode_options wpshop_wysiwyg_shortcode_options_categories_display_product" value="only_cat" checked ><label for="wpshop_wysiwyg_shortcode_options_categorie_display_product" > <?php 
            _e('Do not display product', 'wpshop');
            ?>
</label>
			</div>
<?php 
            $specific_options = ob_get_contents();