Closed MissVeronica closed 10 months ago
Solution for this VCard issue:
You can replace all of the current um-vcard.php
file with this new code version 1.1.0:
<?php
/*
Plugin Name: Ultimate Member - VCard
Plugin URI: https://www.ultimatemember.com
Description: Adds a predefined field to generate VCard for users to download from their profiles.
Version: 1.1.0
Author: Ultimate Member Ltd.
Author URI: https://www.ultimatemember.com
Text Domain: um-vcard
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'You are not allowed to call this page directly.' );
}
define( 'UM_VCARD_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'UM_VCARD_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
// Composer dependencies.
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
require __DIR__ . '/vendor/autoload.php';
}
use JeroenDesloovere\VCard\Formatter\Formatter;
use JeroenDesloovere\VCard\Formatter\VcfFormatter;
use JeroenDesloovere\VCard\Parser\Parser;
use JeroenDesloovere\VCard\Parser\VcfParser;
use JeroenDesloovere\VCard\Property\Address;
use JeroenDesloovere\VCard\Property\Anniversary;
use JeroenDesloovere\VCard\Property\Birthdate;
use JeroenDesloovere\VCard\Property\Email;
use JeroenDesloovere\VCard\Property\Gender;
use JeroenDesloovere\VCard\Property\Logo;
use JeroenDesloovere\VCard\Property\Name;
use JeroenDesloovere\VCard\Property\Nickname;
use JeroenDesloovere\VCard\Property\Note;
use JeroenDesloovere\VCard\Property\Parameter\Kind;
use JeroenDesloovere\VCard\Property\Parameter\Revision;
use JeroenDesloovere\VCard\Property\Parameter\Type;
use JeroenDesloovere\VCard\Property\Parameter\Version;
use JeroenDesloovere\VCard\Property\Photo;
use JeroenDesloovere\VCard\Property\Telephone;
use JeroenDesloovere\VCard\Property\Title;
use JeroenDesloovere\VCard\Property\Role;
use JeroenDesloovere\VCard\Property\Url;
use JeroenDesloovere\VCard\VCard;
/**
* Generate VCard on profile update
*
* @param integer $user_id The current user's ID.
*/
function um_vcard_generate( $user_id ) {
um_fetch_user( $user_id );
$lastname = um_user( 'last_name' );
$firstname = um_user( 'first_name' );
$additional = um_user( 'display_name' );
$prefix = um_user( 'prefix' );
$suffix = um_user( 'suffix' );
$user_dir = UM()->uploader()->get_upload_user_base_dir( $user_id ) . DIRECTORY_SEPARATOR;
if( !file_exists( $user_dir )) {
wp_mkdir_p( $user_dir );
}
$vcard = new VCard( null, Version::version3() );
$vcard->add( new Name( $lastname, $firstname ) );
$vcard->add( new Title( um_user( 'title' ) ) );
$vcard->add( new Role( um_user( 'role' ) ) );
$vcard->add( new Telephone( um_user( 'mobile_number' ) ) );
if ( file_exists( $user_dir . um_profile( 'profile_photo' ) ) && is_file( $user_dir . um_profile( 'profile_photo' ) ) ) {
//$sizes = UM()->options()->get( 'photo_thumb_sizes' );
//$min_size = min( $sizes );
//$avatar = str_replace( 'profile_photo', 'profile_photo-' . $min_size . 'x' . $min_size, $user_dir . um_profile( 'profile_photo' ) );
$avatar = $user_dir . um_profile( 'profile_photo' );
$data = file_get_contents( $avatar );
// we should split this large string into smaller 72-symbols strings, to correspond the standard.
$vcard->add( new Photo( $data ) );
$vcard->add( new Logo( $data ) );
}
add_action( 'um_vcard_before_save', $vcard, $user_id );
$formatter = new Formatter( new VcfFormatter(), 'vcard' );
$formatter->addVCard( $vcard );
$formatter->save( $user_dir );
update_user_meta( $user_id, 'vcard', 'vcard.vcf' );
}
add_action( 'um_after_user_updated', 'um_vcard_generate' );
add_action( 'um_registration_complete', 'um_vcard_generate' );
/**
* Add Vcard predefined field.
*
* @param array $fields predefined fields array.
*/
function um_vcard_add_field( $fields ) {
$fields['vcard'] = array(
'title' => __( 'VCard', 'ultimate-member' ),
'metakey' => 'vcard',
'type' => 'file',
'label' => __( 'VCard', 'ultimate-member' ),
'required' => 0,
'public' => 1,
'editable' => false,
'icon' => 'um-icon-card',
'color' => '#6441A4',
);
return $fields;
}
add_filter( 'um_predefined_fields_hook', 'um_vcard_add_field', 10, 1 );
// Don't display the field in Edit View.
add_filter( 'um_vcard_form_edit_field', '__return_empty_string' );
This code update has been verified by two of the UM Support Forum Thread starters to fix their issues with vCard. Merge this code update with https://github.com/ultimatemember/Extended/pull/14
There are three threads in the UM Support Forum where there is a Form message "This file has been removed" for the VCard field both after User Registration and User Profile update. Looks like the VCard plugin worked for a while after activation probably because tests were made with users having uploaded files and the folder being created by UM.
https://wordpress.org/support/topic/vcard-extension-doesnt-work-anymore/ https://wordpress.org/support/topic/vcard-error-this-file-has-been-removed/ https://wordpress.org/support/topic/vcard-this-file-has-been-removed/
PHP Debug verified that the user uploads folder was not created and the error message correct: