admin_url( 'admin-ajax.php' ),
'ajaxnonce' => wp_create_nonce( 'merchant_admin_options' ),
) );
}
}
/**
* 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;
}
wp_send_json_success( $options );
} else {
wp_send_json_error();
}
}
/**
* Get option.
*/
public static function get( $module, $setting, $default ) {
$options = get_option( 'merchant', array() );
$value = $default;
if ( isset( $options[ $module ] ) && isset( $options[ $module ][ $setting ] ) ) {
$value = $options[ $module ][ $setting ];
}
return $value;
}
/**
* 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 ) {
/**
* Hook: merchant_module_settings
*
* @since 1.0
*/
$settings = apply_filters( 'merchant_module_settings', $settings );
self::save_options( $settings );
$options = get_option( 'merchant', array() );
?>
$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 ) {
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();
echo '';
if ( ! empty( $settings['title'] ) ) {
echo sprintf( '
%s
', esc_html( $settings['title'] ) );
}
echo '
';
if ( method_exists( 'Merchant_Admin_Options', $type ) ) {
call_user_func( array( 'Merchant_Admin_Options', $type ), $settings, $value );
} else {
esc_html_e( 'Field not found!', 'merchant' );
}
echo '
';
if ( ! empty( $settings['desc'] ) ) {
echo sprintf( '
%s
', wp_kses_post( $settings['desc'] ) );
}
echo '
';
}
}
/**
* Disabled field
*
* @param array $settings
* @param mixed $value
*
* @return void
*/
public static function disabled_field( $settings, $value ) {
static::replace_field(
$settings,
$value,
array(
'
class="toggle-switch-checkbox"/>
$option ) : ?>
$option ) : ?>
'post',
) );
$ids = ( is_array( $value ) && ! empty( $value ) ) ? $value : (array) $value;
if ( isset( $settings['multiple'] ) ) {
$multiple = $settings['multiple'] === true ? 'multiple' : '';
} else {
$multiple = 'multiple';
}
?>
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 ) : ?>
'',
'max' => '',
'step' => '',
'unit' => '',
) );
?>
'#212121',
) );
?>
esc_html__( 'Select Images', 'merchant' ),
) );
$images = ( ! empty( $value ) ) ? explode( ',', $value ) : array();
echo '';
if ( ! empty( $images ) ) :
foreach ( $images as $image_id ) :
$image = wp_get_attachment_image_src( $image_id, 'thumbnail' );
if ( ! empty( $image ) && ! empty( $image[0] ) ) :
echo sprintf( '
', esc_attr( $image_id ) );
echo '
';
echo sprintf( '

', esc_url( $image[0] ) );
echo '
';
endif;
endforeach;
endif;
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 '
';
echo sprintf( '

', esc_url( $image[0] ) );
echo '
';
endif;
endif;
echo '
';
?>
-
$option_val ) :
if ( ! in_array( $option_key, $value ) ) :
$invisible = ! in_array( $option_key, $value ) ? ' invisible' : '';
?>
-
false,
'style' => 'default'
) );
$classes = array(
'merchant-flexible-content-control',
"{$settings['style']}-style"
);
if ( $settings['sorting'] === false ) {
$classes[] = 'disable-sorting';
}
?>
';
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: link to edit page */
__( '
Page created with success!
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=&action=edit',
get_admin_url() . 'nav-menus.php'
)
);
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 ) {
$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 );
?>