Skip to content

Commit

Permalink
Merge pull request #84 from ultimatemember/fix/um-vcard/block_removing
Browse files Browse the repository at this point in the history
Blocked removing the vcard.vcf file on profile update
  • Loading branch information
champsupertramp authored Mar 8, 2024
2 parents f2d6cd5 + 5f90a3d commit d075928
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/um-vcard/src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ public function __construct() {
// Don't display the field in Edit View.
add_filter( 'um_vcard_form_edit_field', '__return_empty_string' );

// Don't remove the vcard.vcf from the members' folder.
add_filter( 'um_can_remove_uploaded_file', array( $this, 'block_removing' ), 10, 3 );

add_action( 'um_after_user_updated', array( $this, 'generate' ) );
add_action( 'um_registration_complete', array( $this, 'generate' ) );

// Remove unused field options.
add_filter(
'um_core_fields_hook',
function( $fields ) {
function ( $fields ) {
if ( isset( $_REQUEST['arg3'] ) && 'vcard' === $_REQUEST['arg3'] ) { // phpcs:ignore WordPress.Security.NonceVerification
$fields['file']['col1'] = array( '_title', '_metakey', '_help', '_visibility' );
$fields['file']['col2'] = array( '_label', '_public', '_roles', '_icon' );
Expand All @@ -66,9 +69,31 @@ function( $fields ) {
return $fields;
}
);
}


/**
* Don't remove the vcard.vcf file from the members' folder.
*
* @see \um\core\Uploader::remove_unused_uploads()
*
* @param boolean $can_unlink Can unlink or not.
* @param int $user_id User ID.
* @param string $str File name.
*
* @return boolean
*/
public function block_removing( $can_unlink, $user_id, $str ) {
if ( 'vcard.vcf' === $str ) {
$can_unlink = false;
}
if ( 0 === strpos( $str, 'vcard-120x120.' ) ) {
$can_unlink = false;
}
return $can_unlink;
}


/**
* Generate VCard on profile update
*
Expand Down Expand Up @@ -210,7 +235,6 @@ public function generate( $user_id ) {
}

update_user_meta( $user_id, 'vcard', 'vcard.vcf' );

}

/**
Expand Down Expand Up @@ -246,6 +270,4 @@ public function image_encode( $path ) {
$big_type = strtoupper( str_replace( 'image/', '', $type ) );
return 'data:' . $type . ';ENCODING=b;TYPE=' . $big_type . ':' . base64_encode( $image ); //phpcs:ignore
}


}

0 comments on commit d075928

Please sign in to comment.