admin_url( 'admin-ajax.php' ), 'ajaxnonce' => wp_create_nonce( 'merchant_admin_options' ), 'product_delete_confirmation_message' => esc_html__( 'Are you sure you want to remove this product?', 'merchant' ), ) ); wp_enqueue_style('date-picker', MERCHANT_URI . 'assets/vendor/air-datepicker/air-datepicker.css', array(), MERCHANT_VERSION, 'all' ); wp_enqueue_script('date-picker', MERCHANT_URI . 'assets/vendor/air-datepicker/air-datepicker.js', array( 'jquery' ), MERCHANT_VERSION, true ); wp_localize_script( 'date-picker', 'merchant_datepicker_locale', array( wp_json_encode( array( 'days' => array( esc_html__( 'Sunday', 'merchant' ), esc_html__( 'Monday', 'merchant' ), esc_html__( 'Tuesday', 'merchant' ), esc_html__( 'Wednesday', 'merchant' ), esc_html__( 'Thursday', 'merchant' ), esc_html__( 'Friday', 'merchant' ), esc_html__( 'Saturday', 'merchant' ), ), 'daysShort' => array( esc_html__( 'Sun', 'merchant' ), esc_html__( 'Mon', 'merchant' ), esc_html__( 'Tue', 'merchant' ), esc_html__( 'Wed', 'merchant' ), esc_html__( 'Thu', 'merchant' ), esc_html__( 'Fri', 'merchant' ), esc_html__( 'Sat', 'merchant' ), ), 'daysMin' => array( esc_html__( 'Su', 'merchant' ), esc_html__( 'Mo', 'merchant' ), esc_html__( 'Tu', 'merchant' ), esc_html__( 'We', 'merchant' ), esc_html__( 'Th', 'merchant' ), esc_html__( 'Fr', 'merchant' ), esc_html__( 'Sa', 'merchant' ), ), 'months' => array( esc_html__( 'January', 'merchant' ), esc_html__( 'February', 'merchant' ), esc_html__( 'March', 'merchant' ), esc_html__( 'April', 'merchant' ), esc_html__( 'May', 'merchant' ), esc_html__( 'June', 'merchant' ), esc_html__( 'July', 'merchant' ), esc_html__( 'August', 'merchant' ), esc_html__( 'September', 'merchant' ), esc_html__( 'October', 'merchant' ), esc_html__( 'November', 'merchant' ), esc_html__( 'December', 'merchant' ), ), 'monthsShort' => array( esc_html__( 'Jan', 'merchant' ), esc_html__( 'Feb', 'merchant' ), esc_html__( 'Mar', 'merchant' ), esc_html__( 'Apr', 'merchant' ), esc_html__( 'May', 'merchant' ), esc_html__( 'Jun', 'merchant' ), esc_html__( 'Jul', 'merchant' ), esc_html__( 'Aug', 'merchant' ), esc_html__( 'Sep', 'merchant' ), esc_html__( 'Oct', 'merchant' ), esc_html__( 'Nov', 'merchant' ), esc_html__( 'Dec', 'merchant' ), ), 'clear' => esc_html__( 'Clear', 'merchant' ), ) ), ) ); } } /** * Ajax callbacks. */ public function create_page_control_ajax_callback() { check_ajax_referer( 'customize-create-page-control-nonce', 'nonce' ); // Check current user capabilities if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'You are not allowed to do this.' ); } $page_title = isset( $_POST['page_title'] ) ? sanitize_text_field( $_POST['page_title'] ) : ''; $page_meta_key = isset( $_POST['page_meta_key'] ) ? sanitize_text_field( $_POST['page_meta_key'] ) : ''; $page_meta_value = isset( $_POST['page_meta_value'] ) ? sanitize_text_field( $_POST['page_meta_value'] ) : ''; $option_name = isset( $_POST['option_name'] ) ? sanitize_text_field( $_POST['option_name'] ) : ''; $meta_input = array(); if ( $page_meta_key && $page_meta_value ) { $meta_input = array( $page_meta_key => $page_meta_value, ); } $postarr = array( 'post_type' => 'page', 'post_status' => 'publish', 'post_title' => $page_title, 'post_content' => '', 'meta_input' => $meta_input, ); $page_id = wp_insert_post( $postarr ); if ( ! is_wp_error( $page_id ) ) { if ( $option_name ) { update_option( $option_name, $page_id ); } wp_send_json( array( 'status' => 'success', 'page_id' => $page_id, ) ); } else { wp_send_json( array( 'status' => 'error', ) ); } } /** * Select content ajax callback. * */ public function select_content_ajax() { $term = ( isset( $_GET['term'] ) ) ? sanitize_text_field( wp_unslash( $_GET['term'] ) ) : ''; $nonce = ( isset( $_GET['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_GET['nonce'] ) ) : ''; $source = ( isset( $_GET['source'] ) ) ? sanitize_text_field( wp_unslash( $_GET['source'] ) ) : ''; // Check current user capabilities if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'You are not allowed to do this.' ); } if ( ! empty( $term ) && ! empty( $source ) && ! empty( $nonce ) && wp_verify_nonce( $nonce, 'merchant_admin_options' ) ) { $options = array(); switch ( $source ) { case 'post': case 'product': $query = new WP_Query( array( 's' => $term, 'post_type' => $source, 'post_status' => 'publish', 'posts_per_page' => 25, 'order' => 'DESC', ) ); if ( ! empty( $query->posts ) ) { foreach ( $query->posts as $post ) { $options[] = array( 'id' => $post->ID, 'text' => $post->post_title, ); } } break; case 'user': $query = new WP_User_Query( array( 'search' => '*' . $term . '*', 'search_columns' => array( 'user_login', 'user_nicename', 'user_email', 'user_url' ), 'number' => 25, ) ); if ( ! empty( $query->results ) ) { foreach ( $query->results as $user ) { $options[] = array( 'id' => $user->ID, 'text' => $user->display_name, ); } } break; } wp_send_json_success( $options ); } else { wp_send_json_error(); } } /** * Get option. */ public static function get( $module, $setting, $default_val ) { $options = get_option( 'merchant', array() ); $value = $default_val; if ( isset( $options[ $module ][ $setting ] ) ) { $value = $options[ $module ][ $setting ]; } /** * Hook: merchant_get_option filter. * Fires after getting module option. * * @param mixed $value Option value. * @param string $module Module ID. * @param string $setting Setting ID. * @param mixed $default_val Default value. * * @since 1.9.3 */ return apply_filters( 'merchant_get_option', $value, $module, $setting, $default_val ); } /** * Set option. */ public static function set( $module, $setting, $value ) { $options = get_option( 'merchant', array() ); $options[ $module ][ $setting ] = $value; update_option( 'merchant', $options ); } /** * Delete option. */ public static function delete( $module, $setting ) { $options = get_option( 'merchant', array() ); unset( $options[ $module ][ $setting ] ); update_option( 'merchant', $options ); } /** * Get all options. */ public static function get_all( $module ) { $options = get_option( 'merchant', array() ); $value = array(); if ( isset( $options[ $module ] ) ) { $value = $options[ $module ]; } return $value; } /** * Create options. */ public static function create( $settings ) { $module_id = ( isset( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended /** * Hook: merchant_module_settings * * @param array $settings Module settings. * @param string $module_id Module ID. * * @since 1.0 */ $settings = apply_filters( 'merchant_module_settings', $settings, $module_id ); self::save_options( $settings ); $options = get_option( 'merchant', array() ); ?>
$val ) { if ( $key === 'hook_name' ) { $value[ $key ] = in_array( $val, array_keys( $field['options'] ), true ) ? sanitize_key( $val ) : ''; } else { $value[ $key ] = (int) $val; } } break; case 'code-editor': $value = wp_kses_post( $value ); break; case 'sortable': $values = json_decode( $value ); $value = array(); foreach ( $values as $val ) { if ( in_array( $val, array_keys( $field['options'] ), true ) ) { $value[] = sanitize_key( $val ); } } break; case 'dimensions': $values = is_array( $value ) ? $value : array(); foreach ( $values as $key => $val ) { if ( $key === 'unit' ) { $value[ $key ] = sanitize_key( $value[ $key ] ); } else { $value[ $key ] = absint( $value[ $key ] ); } } break; case 'responsive_dimensions': $values = is_array( $value ) ? $value : array(); foreach ( $values as $device => $device_fields ) { foreach ( $device_fields as $device_field => $device_field_val ) { if ( $device_field === 'unit' ) { $value[ $device ][ $device_field ] = sanitize_key( $device_field_val ); } else { $value[ $device ][ $device_field ] = absint( $device_field_val ); } } } break; case 'sortable_repeater': $values = json_decode( $value ); $value = array_map( 'sanitize_text_field', $values ); break; case 'flexible_content': $value = ! is_array( $value ) || empty( $value ) ? array() : $value; $value = array_map( function ( $sub_fields ) use ( $field ) { foreach ( $sub_fields as $sub_field => $value ) { if ( $sub_field === 'layout' ) { $sub_fields[ $sub_field ] = sanitize_text_field( $value ); } else { $layout_field = array_filter( $field['layouts'][ $sub_fields['layout'] ]['fields'], function ( $layout_field ) use ( $sub_field ) { return $layout_field['id'] === $sub_field; } ); $sub_fields[ $sub_field ] = self::sanitize( reset( $layout_field ), $value ); } } return $sub_fields; }, $value ); break; } return $value; } /** * Field */ public static function field( $settings, $value, $module_id = '') { if ( ! empty( $settings['type'] ) ) { $type = $settings['type']; $id = ( ! empty( $settings['id'] ) ) ? $settings['id'] : ''; $class = ( ! empty( $settings['class'] ) ) ? ' ' . $settings['class'] : ''; $condition = ( ! empty( $settings['condition'] ) ) ? $settings['condition'] : array(); $conditions = ( ! empty( $settings['conditions'] ) ) ? $settings['conditions'] : ''; //Docs here: https://github.com/athemes/Merchant/pull/133 $default = ( ! empty( $settings['default'] ) ) ? $settings['default'] : null; $is_upsell = ! merchant_is_pro_active() && isset( $settings['pro'] ) && $settings['pro'] === true; if ( ! $value && ( 0 !== $value && '0' !== $value ) ) { if ( $type === 'checkbox_multiple' ) { $value = is_array( $value ) ? $value : (array) $default; } elseif ( $type === 'text' && ! empty( $module_id ) ) { $value = Merchant_Option::get( $module_id, $id ); } else { $value = $default; } } $wrapper_classes = array( 'merchant-module-page-setting-field' ); $wrapper_classes[] = 'merchant-module-page-setting-field-' . $type; if ( ! empty( $class ) ) { $wrapper_classes[] = $class; } /** * Hook 'merchant_admin_module_field_wrapper_classes' * * @since 1.9.3 */ $wrapper_classes = apply_filters( 'merchant_admin_module_field_wrapper_classes', $wrapper_classes, $settings, $value, $module_id ); echo '
'; if ( ! empty( $settings['title'] ) ) { ?>
'; if ( method_exists( 'Merchant_Admin_Options', $type ) ) { call_user_func( array( 'Merchant_Admin_Options', $type ), $settings, $value, $module_id ); } else { esc_html_e( 'Field not found!', 'merchant' ); } echo '
'; $hidden_desc = $settings['hidden_desc'] ?? ''; /** * Hook 'merchant_admin_module_field_hidden_description' * * @since 1.9.3 */ $hidden_desc = apply_filters( 'merchant_admin_module_field_hidden_description', $hidden_desc, $settings, $value, $module_id ); $desc = ( ! empty( $settings['desc'] ) ) ? $settings['desc'] : ''; /** * Hook 'merchant_admin_module_field_description' * * @since 1.9.3 */ $desc = apply_filters( 'merchant_admin_module_field_description', $desc, $settings, $value, $module_id ); if ( ! empty( $desc ) ) { $hidden_desc_html = ''; if ( ! empty( $hidden_desc ) ) { $hidden_desc_html = '
' . esc_html__( 'Show more', 'merchant' ) . ''; $hidden_desc_html .= 'Merchant'; $hidden_desc_html .= '
'; } printf( '
%s%s
', wp_kses_post( $desc ), wp_kses_post( $hidden_desc_html ) ); } if ( ! empty( $hidden_desc ) ) { printf( '
%s
', wp_kses_post( nl2br( $hidden_desc ) ) ); } echo ''; } } /** * Disabled field * * @param array $settings * @param mixed $value * * @return void */ public static function disabled_field( $settings, $value, $module_id = '') { static::replace_field( $settings, $value, array( ' placeholder=""/>
$option ) : ?>
class="toggle-switch-checkbox"/>
$option ) : ?>
$option ) : ?>
$option ) : ?>

$option ) : ?>
'post', ) ); $ids = ( is_array( $value ) && ! empty( $value ) ) ? $value : (array) $value; if ( isset( $settings['multiple'] ) ) { $multiple = $settings['multiple'] === true ? 'multiple' : ''; } else { $multiple = 'multiple'; } $placeholder = $settings['placeholder'] ?? ''; ?>

%s', esc_url( $settings['button_link'] ), esc_html( $settings['button_text'] ) ); } ?>

' . esc_html__( 'WooCommerce is not installed or activated.', 'merchant' ) . '

'; return; } $ids = $value ? explode( ',', $value ) : array(); if ( isset( $settings['multiple'] ) ) { $multiple = $settings['multiple'] === true ? 'multiple' : 'false'; } else { $multiple = 'multiple'; } if ( ! isset( $settings['allowed_types'] ) ) { $settings['allowed_types'] = array( 'all' ); } ?>
<?php esc_attr_e( 'Search icon', 'merchant' ); ?>
get_id(); $product_sku = $product->get_sku(); $product_name = $product->get_name(); $edit_link = get_edit_post_link( $product_id ); if ( $product->is_type( 'variation' ) ) { $edit_link = get_edit_post_link( $product->get_parent_id() ); } /** * Filter product image. * * @since 1.9.1 */ $product_image = apply_filters( 'merchant_product_item_product_image', '' . $product->get_image( array( 30, 30 ) ) . '', $product ); $price = $product->get_price(); $key = $product_id . '_' . $product_sku; /** * Filter the product bundle item product info. * * @param string $product_info The product bundle item product info. * @param WC_Product $product The product object. * * @since 1.9.0 */ $product_info = apply_filters( 'merchant_pro_product_bundle_item_product_info', $product->get_type() . '
#' . $product_id, $product ); if ( $search ) { $remove_btn = '+'; } else { $remove_btn = '×'; } $item_class = 'product-item'; if( $hierarchy && $product->is_type( 'variation' ) ) { $item_class .= ' hierarchy-style'; } echo '
  • ' . wp_kses( $product_image, array( 'span' => array( 'class' => true, ), 'img' => array( 'src' => true, 'alt' => true, 'decoding' => true, 'srcset' => true, 'loading' => true, 'sizes' => true, 'class' => true, 'width' => true, 'height' => true, ), ) ) . '' . '' . esc_html( $product_name ) . '' . wp_kses( $product->get_price_html(), array( 'span' => array( 'class' => true, ), 'del' => array( 'aria-hidden' => true, ), 'ins' => array(), 'bdi' => array(), ) ) . ' ' . ( $product->is_sold_individually() ? '' . esc_html__( 'sold individually', 'merchant' ) . ' ' : '' ) . '' . '' . wp_kses_post( $product_info ) . ' ' . wp_kses( $remove_btn, array( 'span' => array( 'class' => true, 'aria-label' => true, ), ) ); echo '
  • '; } public function products_search() { check_ajax_referer( 'merchant_admin_options', 'nonce' ); if ( ! isset( $_POST['keyword'] ) || empty( $_POST['keyword'] ) ) { exit(); } $types = array( 'simple', 'variable' ); // limit search to product types if ( isset( $_POST['product_types'] ) || ! empty( $_POST['product_types'] ) ) { $types = explode( ',', sanitize_text_field( $_POST['product_types'] ) ); } $hierarchy = false; if ( in_array( 'all', $types, true ) || ( in_array( 'variation', $types, true ) && in_array( 'variable', $types, true ) ) ) { $hierarchy = true; } $added_ids = isset( $_POST['ids'] ) ? explode( ',', sanitize_text_field( $_POST['ids'] ) ) : array(); $keyword = sanitize_text_field( $_POST['keyword'] ); if ( is_numeric( $keyword ) ) { // search by id $query_args = array( 'p' => absint( $keyword ), 'post_type' => 'product', ); } else { $query_args = array( 'post_type' => 'product', 'post_status' => array( 'publish', 'private' ), 's' => $keyword, 'posts_per_page' => 10, ); if ( ! empty( $types ) && ! in_array( 'all', $types, true ) ) { $product_types = $types; if ( in_array( 'variation', $types, true ) ) { $product_types[] = 'variable'; } // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query $query_args['tax_query'] = array( array( 'taxonomy' => 'product_type', 'field' => 'slug', 'terms' => $product_types, ), ); } $query_args['post__not_in'] = array_map( 'absint', $added_ids ); } // Filter by category slugs. $categories = array_map( 'sanitize_text_field', $_POST['categories'] ?? array() ); if ( is_array( $categories ) && ! empty( $categories ) ) { $query_args['tax_query'][] = array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $categories, 'operator' => 'IN', ); } $query = new WP_Query( $query_args ); if ( $query->have_posts() ) { echo ''; wp_reset_postdata(); } else { // translators: %s is the search keyword echo wp_kses( '', array( 'ul' => array(), 'span' => array(), ) ); } exit; } /** * Check if all variation attributes are set. * * @param $variation WC_Product_Variation variation product object * * @return bool */ public function are_variation_attributes_set( $variation ) { // Check if the product is a variation and has attributes if ( $variation && $variation->is_type( 'variation' ) ) { // Get the variation attributes $variation_attributes = $variation->get_variation_attributes(); // Check if all variation attributes are set foreach ( $variation_attributes as $attribute => $value ) { if ( empty( $value ) ) { return false; // At least one attribute is not set } } return true; // All variation attributes are set } return false; // Not a valid variation product } /** * Field: Select Size Chart */ public static function select_size_chart( $settings, $value, $module_id = '' ) { $options = array( '' => esc_html__( 'Default', 'merchant' ), ); $posts = get_posts( array( 'post_type' => 'merchant_size_chart', 'posts_per_page' => - 1, 'post_status' => 'publish', ) ); if ( ! is_wp_error( $posts ) && ! empty( $posts ) ) { foreach ( $posts as $_post ) { $options[ $_post->ID ] = $_post->post_title; } } ?>
    $option ) : ?>
    $option ) : ?>
    $option ) : ?>
    '', 'max' => '', 'step' => '', 'unit' => '', ) ); ?>
    '#212121', ) ); ?>
    esc_html__( 'Select Images', 'merchant' ), ) ); $images = ( ! empty( $value ) ) ? explode( ',', $value ) : array(); echo ''; ?> esc_html__( 'Select Image', 'merchant' ), ) ); echo '
    '; if ( ! empty( $value ) ) : $image = wp_get_attachment_image_src( $value, 'thumbnail' ); if ( ! empty( $image ) && ! empty( $image[0] ) ) : echo '
    '; echo ''; printf( '', esc_url( $image[0] ) ); echo '
    '; endif; endif; echo '
    '; $drag_drop = $settings['drag_drop'] ?? false; ?>
    <?php echo esc_attr__( 'Upload image', 'merchant' ); ?>
    - 1, 'orderby' => 'title', 'order' => 'asc', 'post_type' => 'shop_coupon', 'post_status' => 'publish', ) ); if ( $coupons ) { ?>
    '; echo ''; foreach ( $coupons as $coupon ) { $coupon_code = strtolower( $coupon->post_title ); echo ''; } echo ''; echo '' . esc_html__( 'Manage coupons', 'merchant' ) . ''; ?>
    '; echo wp_kses_post( sprintf( /* Translators: 1. Coupon admin url 2. Link target attribute value */ __( 'No coupons found! Create a new coupon', 'merchant' ), admin_url( 'post-new.php?post_type=shop_coupon' ), '_blank' ) ); echo ''; echo ''; } } /** * Field: Date Time. * * @param $settings array field settings. * @param $value string field value. * @param $module_id string module id. * * @return void */ public static function date_time( $settings, $value, $module_id = '' ) { // All options are documented here: https://air-datepicker.com/docs $options = array( 'dateFormat' => 'MM-dd-yyyy', 'timepicker' => true, 'timeFormat' => 'hh:mm AA', 'minDate' => 'today', 'timeZone' => wp_timezone_string(), ); if ( isset( $settings['options'] ) ) { $settings['options'] = wp_parse_args( $settings['options'], $options ); } else { $settings['options'] = $options; } ?>
    false, 'style' => 'default', 'accordion' => false, ) ); $classes = array( 'merchant-flexible-content-control', "{$settings['style']}-style", ); $has_sorting = (bool) ( $settings['sorting'] ?? true ); if ( ! $has_sorting ) { $classes[] = 'disable-sorting'; } $has_accordion = (bool) ( $settings['accordion'] ?? false ); if ( $has_accordion ) { $classes[] = 'has-accordion'; } $has_duplicate = (bool) ( $settings['duplicate'] ?? false ); if ( $has_duplicate ) { $classes[] = 'has-duplicate'; } ?>
    $layout ) : ?>
    1
    >
    $settings['id'], 'option_key' => 0, 'value' => $value, ) ); } else { static::replace_field( $sub_field, '', array( "name=\"merchant[{$sub_field['id']}]", 'merchant-module-page-setting-field-upload', 'merchant-module-page-setting-field-select_ajax', ), array( "data-name=\"merchant[{$settings['id']}][0][{$sub_field['id']}]", 'merchant-module-page-setting-field-upload template', 'merchant-module-page-setting-field-select_ajax template', ), $module_id ); } ?>
    $option ) : ?>
    >
    $settings['id'], 'option_key' => $option_key, 'value' => $option, ) ); } else { static::replace_field( $sub_field, $value, "name=\"merchant[{$sub_field['id']}]", "name=\"merchant[{$settings['id']}][{$option_key}][{$sub_field['id']}]", $module_id ); } ?>
    $layout ) : ?>
    %s
    ', esc_html( $settings['title'] ) ); } if ( ! empty( $settings['sub-desc'] ) ) { printf( '
    %s
    ', wp_kses_post( $settings['sub-desc'] ) ); } if ( $accordion ) { ?>
    $settings['id'] . '_status', 'type' => 'select', 'title' => esc_html__( 'Status', 'merchant' ), 'options' => array( 'inactive' => esc_html__( 'Inactive', 'merchant' ), 'active' => esc_html__( 'Active', 'merchant' ), ), 'default' => isset( $settings['default'] ) ? $settings['default'] : 'active', ), $settings, $value, $module_id ); if ( $inside_flexible ) { static::replace_field( $status, isset( $args['value'][$settings['id']][ $status['id'] ] ) ? $args['value'][$settings['id']][ $status['id'] ] : $status['default'] ?? '', "name=\"merchant[{$status['id']}]", "name=\"merchant[{$args['id']}][{$args['option_key']}][{$settings['id']}][{$status['id']}]\" data-name=\"merchant[{$args['id']}][0][{$settings['id']}][{$status['id']}]", $module_id ); } else { static::replace_field( $status, isset( $value[ $status['id'] ] ) ? $value[ $status['id'] ] : '', "name=\"merchant[{$status['id']}]", "name=\"merchant[{$settings['id']}][{$status['id']}]", $module_id ); } } foreach ( $settings['fields'] as $field ) { if ( $inside_flexible ) { static::replace_field( $field, isset( $args['value'][$settings['id']][ $field['id'] ] ) ? $args['value'][$settings['id']][ $field['id'] ] : $field['default'] ?? '', "name=\"merchant[{$field['id']}]", "name=\"merchant[{$args['id']}][{$args['option_key']}][{$settings['id']}][{$field['id']}]\" data-name=\"merchant[{$args['id']}][0][{$settings['id']}][{$field['id']}]", $module_id ); } else { static::replace_field( $field, isset( $value[ $field['id'] ] ) ? $value[ $field['id'] ] : '', "name=\"merchant[{$field['id']}]", "name=\"merchant[{$settings['id']}][{$field['id']}]", $module_id ); } } ?>
    '; if ( $page_id && post_exists( get_the_title( $page_id ) ) && 'publish' === get_post_status( $page_id ) ) { echo wp_kses_post( sprintf( /* translators: 1: link to edit page */ __( '

    Your page is created!

    Click here if you want to edit the page.

    To display the page in your theme header area, assign the page to the primary menu by clicking here

    ', 'merchant' ), get_admin_url() . 'post.php?post=' . $page_id . '&action=edit', get_admin_url() . 'nav-menus.php' ) ); } else { echo '
    '; echo wp_kses_post( '

    '. sprintf( /* translators: 1: page name */ __( 'It looks like you haven\'t created a %1$s page yet. Click the below button to create the page.', 'merchant' ), $settings['page_title'] ). '

    ' ); echo '
    '; echo ''; echo wp_kses_post( sprintf( /* translators: 1: page title, 2: page meta key, 3: page meta value, 4: option name, 5: nonce, 6: loading text, 7: success text */ __( '%1$s', 'merchant' ), __( 'Create Page', 'merchant' ), $settings['page_title'], $settings['page_meta_key'], $settings['page_meta_value'], $settings['option_name'], wp_create_nonce( 'customize-create-page-control-nonce' ), __( 'Creating...', 'merchant' ), __( 'Created!', 'merchant' ) ) ); } echo ''; } public static function dimensions( $settings, $value, $module_id = '' ) { $settings = wp_parse_args( $settings, array( 'units' => array( 'px' => 'px', 'rem' => 'rem', 'em' => 'em', 'vw' => 'vw', 'vh' => 'vh', '%' => '%', ), 'dimensions' => array( 'top', 'right', 'bottom', 'left', ), ) ); $default_value = array( 'unit' => reset( $settings['units'] ), ); foreach ( $settings['dimensions'] as $dimension ) { $default_value[ $dimension ] = 0; } $value = wp_parse_args( $value, $default_value ); ?>
    array( 'px' => 'px', 'rem' => 'rem', 'em' => 'em', 'vw' => 'vw', 'vh' => 'vh', '%' => '%', ), 'dimensions' => array( 'top', 'right', 'bottom', 'left', ), 'devices' => array( 'desktop' => 'dashicons-desktop', 'tablet' => 'dashicons-tablet', 'mobile' => 'dashicons-smartphone', ), ) ); $default_values = array(); foreach ( $settings['devices'] as $device => $icon ) { $default_values[ $device ]['unit'] = reset( $settings['units'] ); foreach ( $settings['dimensions'] as $dimension ) { $default_values[ $device ][ $dimension ] = 0; } } $value = wp_parse_args( $value, $default_values ); ?>
    $icon ) : ?>
    esc_attr( $cat['slug'] ?? '' ), 'text' => esc_html( $indent . ( $cat['name'] ?? '' ) ), ); if ( ! empty( $cat['children'] ) ) { $choices = array_merge( $choices, self::build_category_select2_choices( $cat['children'], $level + 1 ) ); } } return $choices; } /** * Get Tag choices for select2 * * @return array */ public static function get_tag_select2_choices() { $choices = array(); $tags = merchant_get_product_tags(); if ( is_array( $tags ) && ! empty( $tags ) ) { foreach ( $tags as $slug => $name ) { $choices[] = array( 'id' => esc_attr( $slug ), 'text' => esc_html( $name ), ); } } return $choices; } /** * Get User Roles choices for select2 * * @return array */ public static function get_user_roles_select2_choices() { $choices = array(); $user_roles = get_editable_roles(); if ( ! empty( $user_roles ) ) { foreach ( $user_roles as $role_id => $role_data ) { $choices[] = array( 'id' => $role_id, 'text' => $role_data['name'], ); } } return $choices; } /** * Get Customers choices for select2. * * @return array */ public static function get_customers_select2_choices() { $cache_key = 'customers_select2_choices'; $choices = get_transient( $cache_key ); if ( ! empty( $choices ) && is_array( $choices ) ) { return $choices; } // Get users with the 'customer' role $customer_users = get_users( array( 'role' => 'customer', 'fields' => array( 'ID', 'display_name' ), ) ); $choices = array(); if ( ! empty( $customer_users ) ) { foreach ( $customer_users as $user ) { $choices[] = array( 'id' => $user->ID, 'text' => $user->display_name, ); } } // Cache the choices with no expiration. Will be cleared using `clear_customer_choices_cache` set_transient( $cache_key, $choices ); return $choices; } /** * Clear customers cache when a customer is created/deleted/updated. * * @param $user_id * @param $user * * @return void */ public function clear_customer_choices_cache( $user_id, $user ) { $user_roles = $user->roles ?? array(); if ( in_array( 'customer', $user_roles, true ) ) { delete_transient( 'customers_select2_choices' ); } } } Merchant_Admin_Options::instance(); }