Skip to content

Commit

Permalink
fix: backward compatibility for banner and store time (#611)
Browse files Browse the repository at this point in the history
* fix: backward compatibility for banner and store time

* fix: unset unnecessary data
  • Loading branch information
saimonh3 authored and Sabbir Ahmed committed Apr 25, 2019
1 parent 555fc3d commit 3eb1740
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 12 deletions.
12 changes: 11 additions & 1 deletion includes/class-vendor.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,13 @@ public function get_banner() {
$banner_id = $this->get_banner_id();

if ( ! $banner_id ) {
return false;
$banner = $this->get_info_part( 'banner' );

if ( $banner ) {
$banner_id = $banner;
} else {
return false;
}
}

return wp_get_attachment_url( $banner_id );
Expand Down Expand Up @@ -434,6 +440,10 @@ public function get_banner_id() {
public function get_avatar() {
$avatar_id = $this->get_avatar_id();

if ( ! $avatar_id ) {
$avatar_id = $this->get_info_part( 'gravatar' );
}

if ( ! $avatar_id && ! empty( $this->data->user_email ) ) {
return get_avatar_url( $this->data->user_email, 96 );
}
Expand Down
6 changes: 4 additions & 2 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,8 @@ function dokan_get_avatar_url( $url, $id_or_email, $args ) {

// see if there is a user_avatar meta field
$user_avatar = get_user_meta( $user->ID, 'dokan_profile_settings', true );
$gravatar_id = isset( $user_avatar['gravatar'] ) ? $user_avatar['gravatar'] : 0;
$gravatar_id = isset( $user_avatar['gravatar_id'] ) ? $user_avatar['gravatar_id'] : 0;
$gravatar_id = isset( $user_avatar['gravatar'] ) ? $user_avatar['gravatar'] : $gravatar_id;

if ( empty( $gravatar_id ) ) {
return $url;
Expand Down Expand Up @@ -3158,8 +3159,9 @@ function dokan_is_store_open( $user_id ) {
}

$schedule = $open_days[ $today ];
$status = isset( $schedule['open'] ) ? $schedule['open'] : $schedule['status'];

if ( 'open' === $schedule['status'] ) {
if ( 'open' === $status ) {
if ( empty( $schedule['opening_time'] ) || empty( $schedule['closing_time'] ) ) {
return true;
}
Expand Down
37 changes: 37 additions & 0 deletions includes/wc-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,40 @@ function dokan_add_privacy_policy() {
}

add_action( 'dokan_contact_form', 'dokan_add_privacy_policy' );

/**
* Unset unnecessary data
*
* @since 2.9.14
*/
add_action( 'dokan_store_profile_saved', function( $store_id, $settings ) {
$store_info = dokan_get_store_info( $store_id );
$banner = isset( $store_info['banner'] ) ? true : false;
$gravatar = isset( $store_info['gravatar'] ) ? true : false;
$all_times = isset( $store_info['dokan_store_time'] ) ? $store_info['dokan_store_time'] : false;
$days = [ 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday' ];
$is_status_unsated = false;

if ( $banner ) {
unset( $store_info['banner'] );
}

if ( $gravatar ) {
unset( $store_info['gravatar'] );
}

if ( $all_times ) {
foreach ( $days as $day => $value ) {
if ( isset( $all_times[$day]['open'] ) ) {
$is_status_unsated = true;

unset( $all_times[$day]['open'] );
}
}
}

if ( $banner || $gravatar || $is_status_unsated ) {
update_user_meta( $store_id, 'dokan_profile_settings', $store_info );
}

}, 99, 2 );
15 changes: 9 additions & 6 deletions templates/settings/store-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*/
?>
<?php
$gravatar_id = isset( $profile_info['gravatar_id'] ) ? $profile_info['gravatar_id'] : 0;
$banner_id = isset( $profile_info['banner_id'] ) ? $profile_info['banner_id'] : 0;
$gravatar_id = ! empty( $profile_info['gravatar_id'] ) ? $profile_info['gravatar_id'] : 0;
$gravatar_id = ! empty( $profile_info['gravatar'] ) ? $profile_info['gravatar'] : $gravatar_id;
$banner_id = ! empty( $profile_info['banner_id'] ) ? $profile_info['banner_id'] : 0;
$banner_id = ! empty( $profile_info['banner'] ) ? $profile_info['banner'] : $banner_id;
$storename = isset( $profile_info['store_name'] ) ? $profile_info['store_name'] : '';
$store_ppp = isset( $profile_info['store_ppp'] ) ? $profile_info['store_ppp'] : '';
$phone = isset( $profile_info['phone'] ) ? $profile_info['phone'] : '';
Expand Down Expand Up @@ -248,24 +250,25 @@
<label class="dokan-w3 control-label"></label>
<div class="dokan-w6" style="width: auto">
<?php foreach ( $dokan_days as $key => $day ) : ?>
<?php $status = isset( $all_times[$day]['open'] ) ? $all_times[$day]['open'] : $all_times[$day]['status']; ?>
<div class="dokan-form-group">
<label class="day control-label" for="<?php echo esc_attr( $day ) ?>-opening-time">
<?php echo esc_html( dokan_get_translated_days( $day ) ); ?>
</label>
<label for="">
<select name="<?php echo esc_attr( $day ) ?>_on_off" class="dokan-on-off dokan-form-control">
<option value="close" <?php ! empty( $all_times[$day]['status'] ) ? selected( $all_times[$day]['status'], 'close' ) : '' ?> >
<option value="close" <?php ! empty( $status ) ? selected( $status, 'close' ) : '' ?> >
<?php esc_html_e( 'Close', 'dokan-lite' ); ?>
</option>
<option value="open" <?php ! empty( $all_times[$day]['status'] ) ? selected( $all_times[$day]['status'], 'open' ) : '' ?> >
<option value="open" <?php ! empty( $status ) ? selected( $status, 'open' ) : '' ?> >
<?php esc_html_e( 'Open', 'dokan-lite' ); ?>
</option>
</select>
</label>
<label for="opening-time" class="time" style="visibility: <?php echo isset( $all_times[$day]['status'] ) && $all_times[$day]['status'] == 'open' ? 'visible' : 'hidden' ?>" >
<label for="opening-time" class="time" style="visibility: <?php echo isset( $status ) && $status == 'open' ? 'visible' : 'hidden' ?>" >
<input type="text" class="dokan-form-control" name="<?php echo esc_attr( strtolower( $day ) ); ?>_opening_time" id="<?php echo esc_attr( $day ) ?>-opening-time" placeholder="<?php echo date_i18n( get_option( 'time_format', 'g:i a' ), current_time( 'timestamp' ) ); ?>" value="<?php echo isset( $all_times[$day]['opening_time'] ) ? esc_attr( $all_times[$day]['opening_time'] ) : '' ?>" >
</label>
<label for="closing-time" class="time" style="visibility: <?php echo isset( $all_times[$day]['status'] ) && $all_times[$day]['status'] == 'open' ? 'visible' : 'hidden' ?>" >
<label for="closing-time" class="time" style="visibility: <?php echo isset( $status ) && $status == 'open' ? 'visible' : 'hidden' ?>" >
<input type="text" class="dokan-form-control" name="<?php echo esc_attr( $day ) ?>_closing_time" id="<?php echo esc_attr( $day ) ?>-closing-time" placeholder="<?php echo date_i18n( get_option( 'time_format', 'g:i a' ), current_time( 'timestamp' ) ); ?>" value="<?php echo isset( $all_times[$day]['closing_time'] ) ? esc_attr( $all_times[$day]['closing_time'] ) : '' ?>">
</label>
</div>
Expand Down
3 changes: 2 additions & 1 deletion templates/store-lists-loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<?php
foreach ( $sellers['users'] as $seller ) {
$store_info = dokan_get_store_info( $seller->ID );
$banner_id = isset( $store_info['banner'] ) ? $store_info['banner'] : 0;
$banner_id = ! empty( $store_info['banner_id'] ) ? $store_info['banner_id'] : 0;
$banner_id = ! empty( $store_info['banner'] ) ? $store_info['banner'] : $banner_id;
$store_name = isset( $store_info['store_name'] ) ? esc_html( $store_info['store_name'] ) : __( 'N/A', 'dokan-lite' );
$store_url = dokan_get_store_url( $seller->ID );
$store_address = dokan_get_seller_short_address( $seller->ID );
Expand Down
5 changes: 3 additions & 2 deletions templates/widgets/store-open-close.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
<div class="dokan-store-open-close">
<?php foreach( $dokan_store_time as $day => $value ) : ?>
<?php
$to = ! empty( dokan_get_translated_days( $value['status'] ) ) ? dokan_get_translated_days( $value['status'] ) : '-';
$is_open = $value['status'] == 'open' ? true : false;
$status = isset( $value['open'] ) ? $value['open'] : $value['status'];
$to = ! empty( dokan_get_translated_days( $status ) ) ? dokan_get_translated_days( $status ) : '-';
$is_open = $status == 'open' ? true : false;
?>
<div class="open-close-day <?php echo esc_attr( $day ) . '-time' ?>">
<label for=""><?php echo esc_attr( dokan_get_translated_days( $day ) ); ?></label>:
Expand Down

0 comments on commit 3eb1740

Please sign in to comment.