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: Implement vendor default banner, profile image & controls. #2275

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified assets/images/default-store-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
24 changes: 24 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.
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.
throw new DokanException( 'dokan_settings_unauthorized_operation', __( 'You are not authorized to perform this action.', 'dokan-lite' ), 401 );
}

Expand Down Expand Up @@ -594,6 +594,10 @@
]
);

// Collect store banner dimensions for croppable fields.
$store_banner_width = dokan()->is_pro_exists() ? dokan_get_option( 'store_banner_width', 'dokan_appearance', 625 ) : 625;
$store_banner_height = dokan()->is_pro_exists() ? dokan_get_option( 'store_banner_height', 'dokan_appearance', 300 ) : 300;

$settings_fields = [
'dokan_general' => array_merge(
$general_site_options,
Expand Down Expand Up @@ -808,6 +812,26 @@
],
'default' => 'default',
],
'default_store_banner' => [
'name' => 'default_store_banner',
'label' => __( 'Default Store Banner', 'dokan-lite' ),
'type' => 'croppable_image',
'default' => DOKAN_PLUGIN_ASSEST . '/images/default-store-banner.png',
'restore' => true,
'render_width' => 625,
'cropping_width' => $store_banner_width,
'cropping_height' => $store_banner_height,
],
'default_store_profile' => [
'name' => 'default_store_profile',
'label' => __( 'Default Store Profile Picture', 'dokan-lite' ),
'type' => 'croppable_image',
'default' => DOKAN_PLUGIN_ASSEST . '/images/mystery-person.jpg',
'restore' => true,
'render_width' => 120,
'cropping_width' => 625,
'cropping_height' => 625,
],
'store_open_close' => [
'name' => 'store_open_close',
'label' => __( 'Store Opening Closing Time Widget', 'dokan-lite' ),
Expand Down
6 changes: 3 additions & 3 deletions includes/Dashboard/Templates/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
}

// check if user have permission to view settings page
if ( ! current_user_can( 'dokan_view_store_settings_menu' ) ) {

Check warning on line 134 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "dokan_view_store_settings_menu" 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.
dokan_get_template_part(
'global/dokan-error', '', [
'deleted' => false,
Expand Down Expand Up @@ -161,12 +161,12 @@
* @return void
*/
public function load_store_content() {
$currentuser = dokan_get_current_user_id();
$profile_info = dokan_get_store_info( dokan_get_current_user_id() );
$current_user = dokan_get_current_user_id();
$profile_info = dokan_get_store_info( $current_user );
Comment on lines +164 to +165
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor variable names for consistency.

- public $currentuser;
+ public $current_user;

This change aligns the variable name with WordPress coding standards, which recommend using underscores in variable names for better readability.

Committable suggestion was skipped due low confidence.


dokan_get_template_part(
'settings/store-form', '', [
'current_user' => $currentuser,
'current_user' => $current_user,
Comment on lines +164 to +169
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper sanitization and escaping of user data.

The method load_store_content retrieves user IDs and store information but does not explicitly sanitize the $current_user variable before using it. Consider sanitizing this variable to prevent security vulnerabilities.

'profile_info' => $profile_info,
]
);
Expand Down Expand Up @@ -317,7 +317,7 @@

switch ( sanitize_text_field( wp_unslash( $_POST['form_id'] ) ) ) { // phpcs:ignore
case 'profile-form':
if ( ! current_user_can( 'dokan_view_store_social_menu' ) ) {

Check warning on line 320 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "dokan_view_store_social_menu" 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( __( 'Pemission denied social', 'dokan-lite' ) );
}

Expand All @@ -329,7 +329,7 @@
break;

case 'store-form':
if ( ! current_user_can( 'dokan_view_store_settings_menu' ) ) {

Check warning on line 332 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "dokan_view_store_settings_menu" 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( __( 'Pemission denied', 'dokan-lite' ) );
}

Expand All @@ -341,7 +341,7 @@
break;

case 'payment-form':
if ( ! current_user_can( 'dokan_view_store_payment_menu' ) ) {

Check warning on line 344 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "dokan_view_store_payment_menu" 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( __( 'Pemission denied', 'dokan-lite' ) );
}

Expand Down Expand Up @@ -563,8 +563,8 @@

// Get & set 7 days opening & closing time for update dokan store time.
foreach ( $dokan_days as $day_key => $day ) {
$opening_time = isset( $_POST['opening_time'][ $day_key ] ) ? wc_clean( wp_unslash( $_POST['opening_time'][ $day_key ] ) ) : '';

Check failure on line 566 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of a non-sanitized input variable: $_POST['opening_time'][$day_key]
$closing_time = isset( $_POST['closing_time'][ $day_key ] ) ? wc_clean( wp_unslash( $_POST['closing_time'][ $day_key ] ) ) : '';

Check failure on line 567 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of a non-sanitized input variable: $_POST['closing_time'][$day_key]
$store_status = ! empty( $_POST[ $day_key ]['working_status'] ) ? sanitize_text_field( wp_unslash( $_POST[ $day_key ]['working_status'] ) ) : 'close';

// If open or closing time is array then return from here.
Expand Down Expand Up @@ -609,11 +609,11 @@
// Update store settings info.
$dokan_settings = [
'store_name' => isset( $_POST['dokan_store_name'] ) ? sanitize_text_field( wp_unslash( $_POST['dokan_store_name'] ) ) : '',
'address' => isset( $_POST['dokan_address'] ) ? wc_clean( wp_unslash( $_POST['dokan_address'] ) ) : $prev_dokan_settings['address'],

Check failure on line 612 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of a non-sanitized input variable: $_POST['dokan_address']
'location' => $location,
'find_address' => $find_address,
'banner' => isset( $_POST['dokan_banner'] ) ? absint( $_POST['dokan_banner'] ) : 0,
'phone' => isset( $_POST['setting_phone'] ) ? dokan_sanitize_phone_number( wp_unslash( $_POST['setting_phone'] ) ) : 'no',

Check failure on line 616 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of a non-sanitized input variable: $_POST['setting_phone']
'show_email' => isset( $_POST['setting_show_email'] ) ? sanitize_text_field( wp_unslash( $_POST['setting_show_email'] ) ) : 'no',
'gravatar' => isset( $_POST['dokan_gravatar'] ) ? absint( $_POST['dokan_gravatar'] ) : 0,
'enable_tnc' => isset( $_POST['dokan_store_tnc_enable'] ) && 'on' === sanitize_text_field( wp_unslash( $_POST['dokan_store_tnc_enable'] ) ) ? 'on' : 'off',
Expand All @@ -633,7 +633,7 @@
];

if ( isset( $_POST['settings']['bank'] ) ) {
$bank = wc_clean( wp_unslash( $_POST['settings']['bank'] ) );

Check failure on line 636 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of a non-sanitized input variable: $_POST['settings']['bank']

$dokan_settings['payment']['bank'] = [
'ac_name' => $bank['ac_name'],
Expand Down Expand Up @@ -821,7 +821,7 @@
*
* @return string
*/
public function get_method_frontend_title( $title, $method ) {

Check warning on line 824 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The method parameter $method is never used
if ( 0 === stripos( $title, 'Dokan ' ) ) {
return substr( $title, 6 );
}
Expand Down
102 changes: 93 additions & 9 deletions includes/Vendor/Vendor.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,59 @@ public function get_location() {
}

/**
* Get the shop banner
* Get the store banner URL.
*
* This method first checks if a specific banner ID is set for the store and retrieves it. If not set,
* it falls back to the default store banner defined in the Dokan settings.
*
* @since DOKAN_SINCE Applied default banner image.
*
* @return string
*/
public function get_banner() {
$banner_id = $this->get_banner_id();
public function get_banner(): string {
// Check if a specific banner ID is set and return its URL.
if ( $this->get_banner_id() ) {
return wp_get_attachment_url( $this->get_banner_id() );
}

// Define the default store banner URL from plugin assets.
$default_store_banner = $this->get_default_banner();

// Retrieve the default banner URL from Dokan settings, with fallback to the plugin's default banner.
$banner_url = dokan_get_option( 'default_store_banner', 'dokan_appearance', $default_store_banner );

/**
* Filters for the store banner URL.
*
* Allows overriding of the store banner URL via external plugins or themes.
* This is particularly useful if there is a need to dynamically change the banner based on specific conditions or configurations.
*
* @since DOKAN_SINCE
*
* @param string $banner_url The URL of the default banner.
* @param Vendor $this Instance of the current class.
*/
return apply_filters( 'dokan_get_banner_url', $banner_url, $this );
}

/**
* Get the default store banner URL.
*
* @since DOKAN_SINCE
*
* @return void
*/
public function get_default_banner(): string {

return $banner_id ? wp_get_attachment_url( $banner_id ) : '';
/**
* Filters for the default store banner URL.
*
* Allows overriding of the default store banner URL via external plugins or themes.
* This is particularly useful if there is a need to dynamically change the banner based on specific conditions or configurations.
*
* @since DOKAN_SINCE
*/
return apply_filters( 'dokan_get_banner_url', DOKAN_PLUGIN_ASSEST . '/images/default-store-banner.png' );
}

/**
Expand All @@ -460,20 +505,59 @@ public function get_banner_id() {
}

/**
* Get the shop profile icon
* Get the shop profile icon.
*
* @since 2.8
* @since DOKAN_SINCE Applied default vendor profile image.
*
* @return string
*/
public function get_avatar() {
public function get_avatar(): string {
$avatar_id = $this->get_avatar_id();

if ( ! $avatar_id && ! empty( $this->data->user_email ) ) {
return get_avatar_url( $this->data->user_email, 96 );
// Check if a specific avatar ID is set and return its URL.
if ( $avatar_id ) {
return wp_get_attachment_url( $avatar_id );
}

return wp_get_attachment_url( $avatar_id );
// Define the default avatar URL from plugin assets.
$default_store_avatar = $this->get_default_avatar();

// Retrieve the default avatar URL from Dokan settings, with fallback to the plugin's default avatar.
$avatar_url = dokan_get_option( 'default_store_profile', 'dokan_appearance', $default_store_avatar );

/**
* Filters for the store avatar URL.
*
* Allows overriding of the store avatar URL via external plugins or themes.
* This is particularly useful if there is a need to dynamically change the avatar based on specific conditions or configurations.
*
* @since DOKAN_SINCE
*
* @param string $avatar_url The URL of the default avatar.
* @param Vendor $this Instance of the current class.
*/
return apply_filters( 'dokan_get_avatar_url', $avatar_url, $this );
}

/**
* Get the default store avatar URL.
*
* @since DOKAN_SINCE
*
* @return string
*/
public function get_default_avatar(): string {

/**
* Filters for the default store avatar URL.
*
* Allows overriding of the default store avatar URL via external plugins or themes.
* This is particularly useful if there is a need to dynamically change the avatar based on specific conditions or configurations.
*
* @since DOKAN_SINCE
*/
return apply_filters( 'dokan_get_default_avatar_url', 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 === 'croppable_image' && 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>
49 changes: 47 additions & 2 deletions src/admin/components/Fields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,27 @@
</div>
</template>

<template v-if="'croppable_image' === fieldData.type">
<div class="field_contents" v-bind:class="[fieldData.content_class ? fieldData.content_class : '']">
<fieldset>
<FieldHeading :fieldData="fieldData"></FieldHeading>
<div class="field add_files">
<label :style="{ maxWidth: fieldData.render_width + 'px' }" :for="sectionId + '[' + fieldData.name + ']'">
<UploadImage
:croppingWidth="parseInt( croppingWidth )"
:croppingHeight="parseInt( croppingHeight )"
:src="fieldValue[fieldData.name]"
@uploadedImage="uploadedImage"
:showButton="false" />
</label>
</div>
</fieldset>
<p v-if="hasError( fieldData.name )" class="dokan-error">
{{ getError( fieldData.label ) }}
</p>
</div>
</template>
Comment on lines +275 to +294
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add handling for missing or invalid image data in the croppable_image field.

The current implementation does not handle cases where the image data might be missing or invalid. It's important to ensure robustness by adding error handling for these scenarios.

+ if (!fieldValue[fieldData.name]) {
+   console.error('Invalid or missing image data');
+   return;
+ }

Committable suggestion was skipped due low confidence.


<template v-if="'color' === fieldData.type">
<div class="field_contents" v-bind:class="[fieldData.content_class ? fieldData.content_class : '']">
<fieldset>
Expand Down Expand Up @@ -511,6 +532,7 @@
import SecretInput from './SecretInput.vue';
import WithdrawCharges from './Fields/WithdrawCharges.vue'
import DokanRadioGroup from "admin/components/DokanRadioGroup.vue";
import UploadImage from "admin/components/UploadImage.vue";

let Mapbox = dokan_get_lib('Mapbox');
let TextEditor = dokan_get_lib('TextEditor');
Expand All @@ -521,7 +543,8 @@
name: 'Fields',

components: {
DokanRadioGroup,
UploadImage,
DokanRadioGroup,
Mapbox,
Switches,
TextEditor,
Expand All @@ -542,12 +565,15 @@
checked : this.isChecked(),
socialChecked : this.isSocialChecked(),
expandSocials : false,
croppingWidth : this.fieldData.cropping_width,
croppingHeight : this.fieldData.cropping_height,
repeatableItem : {},
repeatableTime : [],
singleColorPicker : { default: this.fieldData.default, label: '', show_pallete: false },
yourStringTimeValue : '',
customFieldComponents : dokan.hooks.applyFilters( 'getDokanCustomFieldComponents', [] ),
multiCheckValues : {},
dokanProExists : dokan.hasPro,
}
},

Expand All @@ -565,11 +591,21 @@
this.checked = value;
}
});

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

watch: {
fieldValue: {
handler() {
handler( newValue ) {
if ( this.id === 'default_store_banner' ) {
this.croppingWidth = newValue.store_banner_width;
this.croppingHeight = newValue.store_banner_height;
}
},
deep: true,
}
Expand Down Expand Up @@ -723,6 +759,11 @@
fieldData.is_lite ?? false
);
},

uploadedImage( image ) {
this.fieldValue[ this.id ] = this.validateInputData( this.id, image.src, this.fieldValue[ this.id ], this.fieldData );
},

inputValueHandler( name, newValue, oldValue ) {
this.fieldValue[ name ] = this.validateInputData( name, newValue, oldValue, this.fieldData );
},
Expand Down Expand Up @@ -1095,6 +1136,10 @@
}
}
}

.field_default {
margin: 0;
}
}

.social-switch-wraper {
Expand Down
7 changes: 7 additions & 0 deletions src/admin/components/UploadImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,14 @@ export default {
.dokan-upload-image {
width: 100%;

.dokan-upload-image-container {
background: #496a94;
border-radius: 50%;
}

img {
width: 100%;
display: flex;
cursor: pointer;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/admin/pages/Vendors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ export default {
td.store_name img {
float: left;
margin-right: 10px;
border-radius: 12px;
margin-top: 1px;
width: 24px;
height: auto;
Expand Down
Loading
Loading