Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'wcfmmp_new_store_created', function( $vendor_id, $wcfmmp_settings ) {
- global $wpdb;
- if ( !empty( $wcfmmp_settings['store_name'] ) ) {
- $store_name = trim( $wcfmmp_settings['store_name'] );
- $store_slug = sanitize_title( wc_clean( $store_name ) );
- $wpdb->query( "UPDATE {$wpdb->prefix}users SET user_nicename = '{$store_slug}' WHERE ID = $vendor_id" );
- }
- }, 50, 2 );
- add_action('wcfm_vendor_settings_update', function($vendor_id, $wcfm_settings_form) {
- global $wpdb;
- if(!empty($wcfm_settings_form['store_name'])) {
- $store_name = trim( $wcfm_settings_form['store_name'] );
- $store_slug = sanitize_title( wc_clean( $store_name ) );
- $wpdb->query( "UPDATE {$wpdb->prefix}users SET user_nicename = '{$store_slug}' WHERE ID = $vendor_id" );
- }
- }, 10, 2);
- add_filter( 'wcfm_is_allow_store_slug', '__return_false' );
- add_filter('wcfm_form_custom_validation', function($wcfm_vendor_form_data, $form_type) {
- $error = false;
- if($form_type==='vendor_manage') {
- if(!empty($wcfm_vendor_form_data['store_name'])) {
- $store_name = trim( $wcfm_vendor_form_data['store_name'] );
- $store_slug = sanitize_title( wc_clean( $store_name ) );
- $store_user = get_user_by( 'slug', $store_slug );
- if ( $store_user ) {
- $error = true;
- }
- }
- } elseif($form_type === 'vendor_setting_manage') {
- if(!empty($wcfm_vendor_form_data['store_name'])) {
- $store_name = trim( $wcfm_vendor_form_data['store_name'] );
- $store_slug = sanitize_title( wc_clean( $store_name ) );
- $store_user = get_user_by( 'slug', $store_slug );
- if($store_user) {
- $store_id = $store_user->ID;
- if( wcfm_is_vendor() ) {
- $user_id = apply_filters( 'wcfm_current_vendor_id', get_current_user_id() );
- } else {
- $user_id = absint( $wcfm_vendor_form_data['vendor_id'] );
- }
- if ( $store_id && $store_id != $user_id) {
- $error = true;
- }
- }
- }
- }
- if($error){
- return array(
- 'has_error' => true,
- 'message' => __( 'Store name already exists - Please use a different name.' ),
- );
- }
- return array('has_error' => false,);
- }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement