if (! defined('BDTUSK_CP')) { define('BDTUSK_CP', ''); } //Add prefix for all widgets if (! defined('BDTUSK_NC')) { define('BDTUSK_NC', ''); } // if you have any custom style if (! defined('BDTUSK_SLUG')) { define('BDTUSK_SLUG', 'ultimate-store-kit'); } // set your own alias if (! defined('BDTUSK_VER')) { define('BDTUSK_VER', 'Ultimate Store Kit'); } // Set your own name for plugin if (! defined('BDTUSK_NAME')) { define('BDTUSK_NAME', 'Ultimate Store Kit'); } if (ultimate_store_kit_is_pro_activated()) { if (! defined('BDTUSK_PC')) { define('BDTUSK_PC', ''); } // pro control badge define('BDTUSK_IS_PC', ''); } else { if (! defined('BDTUSK_PC')) { define('BDTUSK_PC', ''); } // pro control badge define('BDTUSK_IS_PC', 'usk-disabled-control'); } /** * Show any alert by this function * * @param mixed $message [description] * @param class prefix $type [description] * @param boolean $close [description] * * @return helper [description] */ function ultimate_store_kit_is_edit() { return Plugin::$instance->editor->is_edit_mode(); } function ultimate_store_kit_is_preview() { return Plugin::$instance->preview->is_preview_mode(); } function ultimate_store_kit_alert($message, $type = 'warning', $close = true) { ?>
'; if ($close) : $output .= ''; endif; $output .= wp_kses_post($message); $output .= ''; return $output; } /** * all array css classes will output as proper space * * @param array $classes shortcode css class as array * * @return proper string */ function ultimate_store_kit_get_post_types($args = []) { $post_type_args = [ 'show_in_nav_menus' => true, ]; if (! empty($args['post_type'])) { $post_type_args['name'] = $args['post_type']; } $_post_types = get_post_types($post_type_args, 'objects'); $post_types = ['0' => esc_html__('Select Type', 'ultimate-store-kit')]; foreach ($_post_types as $post_type => $object) { $post_types[$post_type] = $object->label; } return $post_types; } /** * Add REST API support to an already registered post type. */ // function bdt_custom_post_type_rest_support() { // global $wp_post_types; // $post_types = ultimate_store_kit_get_post_types(); // foreach( $post_types as $post_type ) { // $post_type_name = $post_type; // if( isset( $wp_post_types[ $post_type_name ] ) ) { // $wp_post_types[$post_type_name]->show_in_rest = true; // $wp_post_types[$post_type_name]->rest_base = $post_type_name; // $wp_post_types[$post_type_name]->rest_controller_class = 'WP_REST_Posts_Controller'; // } // } // } // add_action( 'init', 'bdt_custom_post_type_rest_support', 25 ); function ultimate_store_kit_allow_tags($tag = null) { $tag_allowed = wp_kses_allowed_html('post'); $tag_allowed['input'] = [ 'class' => [], 'id' => [], 'name' => [], 'value' => [], 'checked' => [], 'type' => [], ]; $tag_allowed['select'] = [ 'class' => [], 'id' => [], 'name' => [], 'value' => [], 'multiple' => [], 'type' => [], ]; $tag_allowed['option'] = [ 'value' => [], 'selected' => [], ]; $tag_allowed['title'] = [ 'a' => [ 'href' => [], 'title' => [], 'class' => [], ], 'br' => [], 'em' => [], 'strong' => [], 'hr' => [], ]; $tag_allowed['text'] = [ 'a' => [ 'href' => [], 'title' => [], 'class' => [], ], 'br' => [], 'em' => [], 'strong' => [], 'hr' => [], 'i' => [ 'class' => [], ], 'span' => [ 'class' => [], ], ]; $tag_allowed['svg'] = [ 'svg' => [ 'version' => [], 'xmlns' => [], 'viewbox' => [], 'xml:space' => [], 'xmlns:xlink' => [], 'x' => [], 'y' => [], 'style' => [], ], 'g' => [], 'path' => [ 'class' => [], 'd' => [], ], 'ellipse' => [ 'class' => [], 'cx' => [], 'cy' => [], 'rx' => [], 'ry' => [], ], 'circle' => [ 'class' => [], 'cx' => [], 'cy' => [], 'r' => [], ], 'rect' => [ 'x' => [], 'y' => [], 'transform' => [], 'height' => [], 'width' => [], 'class' => [], ], 'line' => [ 'class' => [], 'x1' => [], 'x2' => [], 'y1' => [], 'y2' => [], ], 'style' => [], ]; if ($tag == null) { return $tag_allowed; } elseif (is_array($tag)) { $new_tag_allow = []; foreach ($tag as $_tag) { $new_tag_allow[$_tag] = $tag_allowed[$_tag]; } return $new_tag_allow; } else { return isset($tag_allowed[$tag]) ? $tag_allowed[$tag] : []; } } /** * Build a pagination link for widget grids or standard WordPress queries. * * @param int $page Page number. * @param string $query_arg Optional custom query arg (e.g. product-page). * @param string $current_url Base URL when using a custom query arg. * @return string */ function ultimate_store_kit_get_pagination_link($page, $query_arg = '', $current_url = '') { $page = absint($page); if (! empty($query_arg)) { if ($page <= 1) { return remove_query_arg($query_arg, $current_url); } return add_query_arg($query_arg, $page, $current_url); } return get_pagenum_link($page); } /** * Whether pagination should use the product-page query arg. * * WooCommerce product grids read the page from ?product-page= so widget * pagination does not conflict with WordPress paged/page on embedded pages. * * @param WP_Query|object $wp_query Query object. * @return bool */ function ultimate_store_kit_pagination_uses_product_page($wp_query) { if (! $wp_query instanceof \WP_Query) { return false; } $post_type = $wp_query->get('post_type'); if (empty($post_type) && isset($wp_query->query_vars['post_type'])) { $post_type = $wp_query->query_vars['post_type']; } if (is_array($post_type)) { return in_array('product', $post_type, true); } return 'product' === $post_type; } /** * Post pagination. * * Auto-detects WooCommerce product grids and uses the product-page query arg. * EDD grids, product reviews, and other queries use standard WordPress pagination. * * @param WP_Query|object $wp_query Query object with max_num_pages. * @param array $args Optional. 'query_arg' => 'product-page' to force custom arg mode. */ function ultimate_store_kit_post_pagination($wp_query, $args = []) { $args = wp_parse_args($args, [ 'query_arg' => '', ]); if ($wp_query->max_num_pages <= 1) { return; } $query_arg = sanitize_key($args['query_arg']); if ('' === $query_arg && ultimate_store_kit_pagination_uses_product_page($wp_query)) { $query_arg = 'product-page'; } $use_custom_arg = ! empty($query_arg); if ($use_custom_arg) { $page = max(1, absint(get_query_var('paged')), absint(get_query_var('page'))); $custom_page = filter_input(INPUT_GET, $query_arg, FILTER_VALIDATE_INT); if ($custom_page && $custom_page >= 1) { $page = absint($custom_page); } $paged = absint($page); } elseif (is_front_page()) { $paged = absint(get_query_var('page')) ?: 1; } else { $paged = absint(get_query_var('paged')) ?: 1; } $max = absint($wp_query->max_num_pages); $links = []; if ($paged >= 1) { $links[] = $paged; } if ($paged >= 3) { $links[] = $paged - 1; $links[] = $paged - 2; } if (($paged + 2) <= $max) { $links[] = $paged + 2; $links[] = $paged + 1; } $current_url = ''; if ($use_custom_arg) { $current_url = remove_query_arg(['paged', 'page', $query_arg]); if (is_post_type_archive() || is_tax()) { $current_url = remove_query_arg( ['paged', 'page', $query_arg], get_pagenum_link(1, false) ); } } echo '