From 3874437a199e00de2a5711e14ea3bff5af7f44e6 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 3 Oct 2019 11:26:28 -0400 Subject: [PATCH] Updating delete hook for members. Delete hook now deleting the images and files and logo of member_info records. --- setup/adminHooks.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 240af7fb..08e3fe09 100755 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -335,6 +335,10 @@ add_action( 'glm-member-db-delete-member', function( $memberId ){ // Call to delete a member record. trigger_error( 'Delete for member with id:' . $memberId, E_USER_NOTICE ); + // Setup all folders for images. Including original. + $imageSizes = $this->config['imageSizes']; + $imageSizes['original'] = 'Original'; + // Delete Member Info Records. // Get all member Info Records (for url's) $memberInfoRecords = $this->wpdb->get_results( @@ -363,12 +367,13 @@ add_action( 'glm-member-db-delete-member', function( $memberId ){ WHERE ref_type = 20 AND ref_dest = %d", $info['id'] - ) + ), + ARRAY_A ); if ( $files ) { foreach ( $files as $file ) { // Remove this file. - unlink( GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $file ); + unlink( GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $file['file_name'] ); } } $this->wpdb->delete( GLM_MEMBERS_PLUGIN_DB_PREFIX . 'files', array( 'ref_type' => 20, 'ref_dest' => $info['id'] ), array( '%d', '%d' ) ); @@ -383,18 +388,34 @@ add_action( 'glm-member-db-delete-member', function( $memberId ){ WHERE ref_type = 20 AND ref_dest = %d", $info['id'] - ) + ), + ARRAY_A ); if ( $images ) { foreach ( $images as $image ) { // Remove this file. - foreach ( $this->config['imageSizes'] as $k => $v ) { - unlink( GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $k . '/' . $image ); + foreach ( $imageSizes as $k => $v ) { + unlink( GLM_MEMBERS_PLUGIN_IMAGES_PATH . '/' . $k . '/' . $image['file_name'] ); } } } $this->wpdb->delete( GLM_MEMBERS_PLUGIN_DB_PREFIX . 'images', array( 'ref_type' => 20, 'ref_dest' => $info['id'] ), array( '%d', '%d' ) ); + // Delete member logo if it exists. + $memberLogo = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT logo + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info + WHERE id = %d" , + $info['id'] + ) + ); + if ( $memberLogo ) { + foreach ( $imageSizes as $k => $v ) { + unlink( GLM_MEMBERS_PLUGIN_IMAGES_PATH . '/' . $k . '/' . $memberLogo ); + } + } + // Delete category_member_info. $this->wpdb->delete( GLM_MEMBERS_PLUGIN_DB_PREFIX . 'category_member_info', array( 'member_info' => $info['id'] ), array( '%d' ) ); @@ -415,6 +436,7 @@ add_action( 'glm-member-db-delete-member', function( $memberId ){ } } + // Delete member_detail_stats. $this->wpdb->delete( GLM_MEMBERS_PLUGIN_DB_PREFIX . 'member_detail_stats', array( 'member' => $memberId ), array( '%d' ) ); -- 2.17.1