Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🛠️ enhance/default banner and profile picture #1891

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Binary file added assets/images/mystery-person.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion assets/src/less/store.less
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@
height: auto;

&.dummy-image {
background-image: url(../../images/default-store-banner.png);
background-size: 100% 100%;
background-repeat: no-repeat;
}
Expand Down
14 changes: 14 additions & 0 deletions includes/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
* @return void
*/
public function get_settings_value() {
if ( ! current_user_can( 'manage_woocommerce' ) ) {

Check warning on line 93 in includes/Admin/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "manage_woocommerce" in function call to current_user_can(). Please check the spelling of the capability. If this is a custom capability, please verify the capability is registered with WordPress via a call to WP_Role(s)->add_cap(). Custom capabilities can be made known to this sniff by setting the "custom_capabilities" property in the PHPCS ruleset.

Check warning on line 93 in includes/Admin/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "manage_woocommerce" in function call to current_user_can(). Please check the spelling of the capability. If this is a custom capability, please verify the capability is registered with WordPress via a call to WP_Role(s)->add_cap(). Custom capabilities can be made known to this sniff by setting the "custom_capabilities" property in the PHPCS ruleset.
wp_send_json_error( __( 'You have no permission to get settings value', 'dokan-lite' ) );
}

Expand All @@ -116,7 +116,7 @@
*/
public function save_settings_value() {
try {
if ( ! current_user_can( 'manage_woocommerce' ) ) {

Check warning on line 119 in includes/Admin/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "manage_woocommerce" in function call to current_user_can(). Please check the spelling of the capability. If this is a custom capability, please verify the capability is registered with WordPress via a call to WP_Role(s)->add_cap(). Custom capabilities can be made known to this sniff by setting the "custom_capabilities" property in the PHPCS ruleset.

Check warning on line 119 in includes/Admin/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "manage_woocommerce" in function call to current_user_can(). Please check the spelling of the capability. If this is a custom capability, please verify the capability is registered with WordPress via a call to WP_Role(s)->add_cap(). Custom capabilities can be made known to this sniff by setting the "custom_capabilities" property in the PHPCS ruleset.
throw new DokanException( 'dokan_settings_unauthorized_operation', __( 'You are not authorized to perform this action.', 'dokan-lite' ), 401 );
}

Expand Down Expand Up @@ -756,6 +756,20 @@
],
'default' => 'default',
],
'default_store_banner' => [
'name' => 'default_store_banner',
'label' => __( 'Default Store Banner', 'dokan-lite' ),
'type' => 'file',
'default' => DOKAN_PLUGIN_ASSEST . '/images/default-store-banner.png',
'restore' => true

Check failure on line 764 in includes/Admin/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Each array item in a multi-line array declaration must end in a comma

Check failure on line 764 in includes/Admin/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Each array item in a multi-line array declaration must end in a comma
],
'default_store_profile' => [
'name' => 'default_store_profile',
'label' => __( 'Default Store Profile Picture', 'dokan-lite' ),
'type' => 'file',
'default' => DOKAN_PLUGIN_ASSEST . '/images/mystery-person.jpg',
'restore' => true

Check failure on line 771 in includes/Admin/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Each array item in a multi-line array declaration must end in a comma

Check failure on line 771 in includes/Admin/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Each array item in a multi-line array declaration must end in a comma
],
'store_open_close' => [
'name' => 'store_open_close',
'label' => __( 'Store Opening Closing Time Widget', 'dokan-lite' ),
Expand Down
17 changes: 11 additions & 6 deletions includes/Vendor/Vendor.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,17 @@ public function get_location() {
/**
* Get the shop banner
*
* @return string
* @return string|false
*/
public function get_banner() {
$banner_id = $this->get_banner_id();
if ( $this->get_banner_id() ) {
return wp_get_attachment_url( $this->get_banner_id() );
}

// get default banner set from admin settings
$default_store_banner = DOKAN_PLUGIN_ASSEST . '/images/default-store-banner.png';

return $banner_id ? wp_get_attachment_url( $banner_id ) : '';
return dokan_get_option( 'default_store_banner', 'dokan_appearance', $default_store_banner );
}

/**
Expand All @@ -469,11 +474,11 @@ public function get_banner_id() {
public function get_avatar() {
$avatar_id = $this->get_avatar_id();

if ( ! $avatar_id && ! empty( $this->data->user_email ) ) {
return get_avatar_url( $this->data->user_email, 96 );
if ( $avatar_id ) {
return wp_get_attachment_url( $avatar_id );
}

return wp_get_attachment_url( $avatar_id );
return dokan_get_option( 'default_store_profile', 'dokan_appearance', DOKAN_PLUGIN_ASSEST . '/images/mystery-person.jpg' );
}

/**
Expand Down
23 changes: 22 additions & 1 deletion src/admin/components/FieldHeading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
></i>
</span>
</h3>
<p class="field_desc" v-html="fieldData.desc"></p>
<p class="field_desc" v-if="fieldData.desc" v-html="fieldData.desc"></p>
<p class="field_default" v-if="fieldData.type === 'file' && fieldData.restore === true">
<a href="" v-on:click.prevent="restoreDefaultImage()">{{ __( 'Restore Default', 'dokan-lite' ) }}</a>
</p>
</div>
</template>

Expand All @@ -21,5 +24,23 @@
name : 'FieldHeading',

props : ['fieldData'],

methods: {
restoreDefaultImage() {
Swal.fire({
icon : 'warning',
html : this.__( 'Would you like to revert back to the default state?', 'dokan-lite' ),
title : this.__( 'Are you sure?', 'dokan-lite' ),
showCancelButton : true,
cancelButtonText : this.__( 'No, Cancel', 'dokan-lite' ),
confirmButtonText : this.__( 'Yes, Reset', 'dokan-lite' ),
}).then( ( response ) => {
if ( response.isConfirmed ) {
this.$root.$emit( 'dokanRestoreDefault', this.fieldData );
Swal.fire( this.__( 'Success', 'dokan-lite' ), '', 'success' );
}
});
}
}
};
</script>
10 changes: 10 additions & 0 deletions src/admin/components/Fields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,12 @@
this.checked = value;
}
});

this.$root.$on( 'dokanRestoreDefault', ( fieldData ) => {
if ( this.fieldValue[ fieldData.name ] !== fieldData.default ) {
this.fieldValue[ fieldData.name ] = fieldData.default
}
});
},

computed: {
Expand Down Expand Up @@ -937,6 +943,10 @@
}
}
}

.field_default {
margin: 0;
}
}

.social-switch-wraper {
Expand Down
44 changes: 22 additions & 22 deletions templates/store-header.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?php
$store_user = dokan()->vendor->get( get_query_var( 'author' ) );
$store_info = $store_user->get_shop_info();
$social_info = $store_user->get_social_profiles();
$store_tabs = dokan_get_store_tabs( $store_user->get_id() );
$social_fields = dokan_get_social_profile_fields();

$dokan_store_times = ! empty( $store_info['dokan_store_time'] ) ? $store_info['dokan_store_time'] : [];
$current_time = dokan_current_datetime();
$today = strtolower( $current_time->format( 'l' ) );

$dokan_appearance = get_option( 'dokan_appearance' );
$profile_layout = empty( $dokan_appearance['store_header_template'] ) ? 'default' : $dokan_appearance['store_header_template'];
$store_address = dokan_get_seller_short_address( $store_user->get_id(), false );

$dokan_store_time_enabled = isset( $store_info['dokan_store_time_enabled'] ) ? $store_info['dokan_store_time_enabled'] : '';
$store_open_notice = isset( $store_info['dokan_store_open_notice'] ) && ! empty( $store_info['dokan_store_open_notice'] ) ? $store_info['dokan_store_open_notice'] : __( 'Store Open', 'dokan-lite' );
$store_closed_notice = isset( $store_info['dokan_store_close_notice'] ) && ! empty( $store_info['dokan_store_close_notice'] ) ? $store_info['dokan_store_close_notice'] : __( 'Store Closed', 'dokan-lite' );
$show_store_open_close = dokan_get_option( 'store_open_close', 'dokan_appearance', 'on' );

$general_settings = get_option( 'dokan_general', [] );
$banner_width = dokan_get_vendor_store_banner_width();
$store_user = dokan()->vendor->get( get_query_var( 'author' ) );
$store_info = $store_user->get_shop_info();
$social_info = $store_user->get_social_profiles();
$store_tabs = dokan_get_store_tabs( $store_user->get_id() );
$social_fields = dokan_get_social_profile_fields();

$dokan_store_times = ! empty( $store_info['dokan_store_time'] ) ? $store_info['dokan_store_time'] : [];
$current_time = dokan_current_datetime();
$today = strtolower( $current_time->format( 'l' ) );

$dokan_appearance = get_option( 'dokan_appearance' );
$profile_layout = empty( $dokan_appearance['store_header_template'] ) ? 'default' : $dokan_appearance['store_header_template'];
$store_address = dokan_get_seller_short_address( $store_user->get_id(), false );
$store_banner_url = $store_user->get_banner();
$dokan_store_time_enabled = isset( $store_info['dokan_store_time_enabled'] ) ? $store_info['dokan_store_time_enabled'] : '';
$store_open_notice = isset( $store_info['dokan_store_open_notice'] ) && ! empty( $store_info['dokan_store_open_notice'] ) ? $store_info['dokan_store_open_notice'] : __( 'Store Open', 'dokan-lite' );
$store_closed_notice = isset( $store_info['dokan_store_close_notice'] ) && ! empty( $store_info['dokan_store_close_notice'] ) ? $store_info['dokan_store_close_notice'] : __( 'Store Closed', 'dokan-lite' );
$show_store_open_close = dokan_get_option( 'store_open_close', 'dokan_appearance', 'on' );

$general_settings = get_option( 'dokan_general', [] );
$banner_width = dokan_get_vendor_store_banner_width();

if ( ( 'default' === $profile_layout ) || ( 'layout2' === $profile_layout ) ) {
$profile_img_class = 'profile-img-circle';
Expand Down Expand Up @@ -48,7 +48,7 @@
title="<?php echo esc_attr( $store_user->get_shop_name() ); ?>"
class="profile-info-img">
<?php } else { ?>
<div class="profile-info-img dummy-image">&nbsp;</div>
<div class="profile-info-img dummy-image" style="background-image:url(<?php esc_url_raw( $store_banner_url ); ?>)">&nbsp;</div>
<?php } ?>

<div class="profile-info-summery-wrapper dokan-clearfix">
Expand Down
11 changes: 7 additions & 4 deletions templates/store-lists-loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@
<?php
foreach ( $sellers['users'] as $seller ) {
$vendor = dokan()->vendor->get( $seller->ID );
$store_banner_id = $vendor->get_banner_id();
$store_name = $vendor->get_shop_name();
$store_url = $vendor->get_shop_url();
$store_rating = $vendor->get_rating();
$is_store_featured = $vendor->is_featured();
$store_phone = $vendor->get_phone();
$store_info = dokan_get_store_info( $seller->ID );
$store_address = dokan_get_seller_short_address( $seller->ID );
$store_banner_url = $store_banner_id ? wp_get_attachment_image_src( $store_banner_id, $image_size ) : DOKAN_PLUGIN_ASSEST . '/images/default-store-banner.png';
$store_banner_url = $vendor->get_banner();
$show_store_open_close = dokan_get_option( 'store_open_close', 'dokan_appearance', 'on' );
$dokan_store_time_enabled = isset( $store_info['dokan_store_time_enabled'] ) ? $store_info['dokan_store_time_enabled'] : '';
$store_open_is_on = ( 'on' === $show_store_open_close && 'yes' === $dokan_store_time_enabled && ! $is_store_featured ) ? 'store_open_is_on' : '';

// get default banner set from admin settings
$default_store_banner = DOKAN_PLUGIN_ASSEST . '/images/default-store-banner.png';
$no_bannar_image_needed = $default_store_banner === $store_banner_url;
?>

<li class="dokan-single-seller woocommerce coloum-<?php echo esc_attr( $per_row ); ?> <?php echo ( ! $store_banner_id ) ? 'no-banner-img' : ''; ?>">
<li class="dokan-single-seller woocommerce coloum-<?php echo esc_attr( $per_row ); ?> <?php echo $no_bannar_image_needed ? 'no-banner-img' : ''; ?>">
<div class="store-wrapper">
<div class="store-header">
<div class="store-banner">
Expand All @@ -29,7 +32,7 @@
</div>
</div>

<div class="store-content <?php echo ! $store_banner_id ? esc_attr( 'default-store-banner' ) : ''; ?>">
<div class="store-content <?php echo $no_bannar_image_needed ? esc_attr( 'default-store-banner' ) : ''; ?>">
<div class="store-data-container">
<div class="featured-favourite">
<?php if ( $is_store_featured ) : ?>
Expand Down
Loading