Skip to content

Commit

Permalink
feat: hide vendor info if admin wants to (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
saimonh3 authored May 11, 2020
1 parent e5b8663 commit ae1462a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
15 changes: 15 additions & 0 deletions includes/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,21 @@ public function get_settings_fields() {
'type' => 'checkbox',
'default' => 'off'
),
'hide_vendor_info' => array(
'name' => 'hide_vendor_info',
'label' => __( 'Hide Vendor Info', 'dokan' ),
'type' => 'multicheck',
'default' => array(
'email' => '',
'phone' => '',
'address' => '',
),
'options' => array(
'email' => __( 'Email Address', 'dokan' ),
'phone' => __( 'Phone Number', 'dokan' ),
'address' => __( 'Store Address', 'dokan' ),
)
),
),
'dokan_privacy' => array(
'enable_privacy' => array(
Expand Down
10 changes: 9 additions & 1 deletion includes/REST/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ public function filter_store_open_close_option( $data ) {
return $data;
}

if ( empty( $data['show_email'] ) ) {
if ( dokan_is_vendor_info_hidden( 'address' ) ) {
unset( $data['address'] );
}

if ( dokan_is_vendor_info_hidden( 'phone' ) ) {
unset( $data['phone'] );
}

if ( dokan_is_vendor_info_hidden( 'email' ) || empty( $data['show_email'] ) ) {
unset( $data['email'] );
}

Expand Down
19 changes: 19 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3830,3 +3830,22 @@ function dokan_clear_product_caches( $product ) {
$method->setAccessible( true );
$method->invokeArgs( $class, [ &$product ] );
}

/**
* Check which vendor info should be hidden
*
* @since DOKAN_LITE_SINCE
*
* @param string $option
*
* @return bool|array if no param is passed
*/
function dokan_is_vendor_info_hidden( $option = null ) {
$options = dokan_get_option( 'hide_vendor_info', 'dokan_appearance' );

if ( is_null( $option ) ) {
return $options;
}

return ! empty( $options[ $option ] );
}
2 changes: 1 addition & 1 deletion templates/global/product-tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<?php printf( '<a href="%s">%s</a>', esc_url( dokan_get_store_url( $author->ID ) ), esc_attr( $author->display_name ) ); ?>
</span>
</li>
<?php if ( !empty( $store_info['address'] ) ) { ?>
<?php if ( ! dokan_is_vendor_info_hidden( 'address' ) && ! empty( $store_info['address'] ) ) { ?>
<li class="store-address">
<span><b><?php esc_html_e( 'Address:', 'dokan-lite' ); ?></b></span>
<span class="details">
Expand Down
6 changes: 3 additions & 3 deletions templates/store-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ class="profile-info-img">
<?php } ?>

<ul class="dokan-store-info">
<?php if ( isset( $store_address ) && !empty( $store_address ) ) { ?>
<?php if ( ! dokan_is_vendor_info_hidden( 'address' ) && isset( $store_address ) && !empty( $store_address ) ) { ?>
<li class="dokan-store-address"><i class="fa fa-map-marker"></i>
<?php echo wp_kses_post( $store_address ); ?>
</li>
<?php } ?>

<?php if ( !empty( $store_user->get_phone() ) ) { ?>
<?php if ( ! dokan_is_vendor_info_hidden( 'phone' ) && ! empty( $store_user->get_phone() ) ) { ?>
<li class="dokan-store-phone">
<i class="fa fa-mobile"></i>
<a href="tel:<?php echo esc_html( $store_user->get_phone() ); ?>"><?php echo esc_html( $store_user->get_phone() ); ?></a>
</li>
<?php } ?>

<?php if ( $store_user->show_email() == 'yes' ) { ?>
<?php if ( ! dokan_is_vendor_info_hidden( 'email' ) && $store_user->show_email() == 'yes' ) { ?>
<li class="dokan-store-email">
<i class="fa fa-envelope-o"></i>
<a href="mailto:<?php echo esc_attr( antispambot( $store_user->get_email() ) ); ?>"><?php echo esc_attr( antispambot( $store_user->get_email() ) ); ?></a>
Expand Down
4 changes: 2 additions & 2 deletions templates/store-lists-loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</div>
<?php endif ?>

<?php if ( $store_address ): ?>
<?php if ( ! dokan_is_vendor_info_hidden( 'address' ) && $store_address ): ?>
<?php
$allowed_tags = array(
'span' => array(
Expand All @@ -60,7 +60,7 @@
<p class="store-address"><?php echo wp_kses( $store_address, $allowed_tags ); ?></p>
<?php endif ?>

<?php if ( $store_phone ) { ?>
<?php if ( ! dokan_is_vendor_info_hidden( 'phone' ) && $store_phone ) { ?>
<p class="store-phone">
<i class="fa fa-phone" aria-hidden="true"></i> <?php echo esc_html( $store_phone ); ?>
</p>
Expand Down

0 comments on commit ae1462a

Please sign in to comment.