plugin updates
This commit is contained in:
@@ -237,4 +237,117 @@ class WpmfFolderAccess
|
||||
|
||||
return $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete folders created by the user
|
||||
*
|
||||
* @param integer $user_id User ID
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function deleteUserFolders($user_id)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
// Get folders created by the user
|
||||
$folders = $wpdb->get_results($wpdb->prepare(
|
||||
'SELECT term_id FROM ' . $wpdb->terms . ' WHERE term_group = %d',
|
||||
$user_id
|
||||
));
|
||||
|
||||
if (!empty($folders)) {
|
||||
foreach ($folders as $folder) {
|
||||
wp_delete_term($folder->term_id, WPMF_TAXO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete folders created by deleted users
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function deleteFoldersOfDeletedUsers()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$wpmf_checkbox_tree = get_option('wpmf_checkbox_tree');
|
||||
$parent = 0;
|
||||
if (!empty($wpmf_checkbox_tree)) {
|
||||
$current_parrent = get_term($wpmf_checkbox_tree, WPMF_TAXO);
|
||||
if (!empty($current_parrent)) {
|
||||
$parent = $wpmf_checkbox_tree;
|
||||
}
|
||||
}
|
||||
|
||||
$descendant_term_ids = get_term_children($parent, WPMF_TAXO);
|
||||
|
||||
if (empty($descendant_term_ids)) {
|
||||
return;
|
||||
}
|
||||
$descendant_term_ids_str = implode(',', $descendant_term_ids);
|
||||
|
||||
$query = '
|
||||
SELECT t.term_id, t.term_group
|
||||
FROM ' . $wpdb->terms . ' t
|
||||
INNER JOIN ' . $wpdb->term_taxonomy . ' tt ON t.term_id = tt.term_id
|
||||
WHERE tt.taxonomy = %s
|
||||
AND t.term_group != 0
|
||||
AND tt.term_id IN (' . $descendant_term_ids_str . ')
|
||||
';
|
||||
|
||||
$folders = $wpdb->get_results($wpdb->prepare($query, WPMF_TAXO)); // phpcs:ignore
|
||||
|
||||
if (!empty($folders)) {
|
||||
foreach ($folders as $folder) {
|
||||
// Check if the user still exists
|
||||
if (!get_user_by('ID', $folder->term_group)) {
|
||||
// If the user does not exist, delete the folder
|
||||
wp_delete_term($folder->term_id, WPMF_TAXO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin menu for deleting user folders
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function addDeleteUserFoldersMenu()
|
||||
{
|
||||
add_menu_page(
|
||||
esc_html__('WPMF Delete Folders of Deleted Users', 'wpmf'),
|
||||
esc_html__('WPMF Delete Folders', 'wpmf'),
|
||||
'manage_options',
|
||||
'wpmf-delete-user-folders',
|
||||
array('WpmfFolderAccess', 'deleteUserFoldersPage')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to render the admin page for deleting folders
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function deleteUserFoldersPage()
|
||||
{
|
||||
// Handle the form submission
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- No action, nonce is not required
|
||||
if (isset($_POST['delete_folders'])) {
|
||||
self::deleteFoldersOfDeletedUsers();
|
||||
echo '<div class="updated"><p>' . esc_html__('All folders of deleted users have been removed.', 'wpmf') . '</p></div>';
|
||||
}
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_html__('Delete Folders of Deleted Users', 'wpmf'); ?></h1>
|
||||
<form method="post" action="">
|
||||
<input type="hidden" name="delete_folders" value="1" />
|
||||
<p>
|
||||
<input type="submit" class="button-primary" value="<?php echo esc_attr__('Delete Folders', 'wpmf'); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,30 @@ class WpMediaFolder
|
||||
* @var integer
|
||||
*/
|
||||
public $folderRootId = 0;
|
||||
|
||||
/**
|
||||
* Init option configuration variable
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $option_google_drive_config = '_wpmfAddon_cloud_config';
|
||||
/**
|
||||
* Init option configuration variable
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $option_dropbox_config = '_wpmfAddon_dropbox_config';
|
||||
/**
|
||||
* Init option configuration variable
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $option_one_drive_config = '_wpmfAddon_onedrive_config';
|
||||
/**
|
||||
* Init option configuration variable
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $option_one_drive_business_config = '_wpmfAddon_onedrive_business_config';
|
||||
/**
|
||||
* Check user full access
|
||||
*
|
||||
@@ -93,6 +116,7 @@ class WpMediaFolder
|
||||
add_filter('wp_insert_post_empty_content', array($this, 'disableSave'), 999999, 2);
|
||||
add_action('pre-upload-ui', array( $this, 'selectFolderUpload'));
|
||||
add_filter('add_attachment', array($this, 'moveFileUploadToSelectFolder'), 0, 1);
|
||||
add_action('wp_enqueue_media', array($this, 'removeDatabaseWhenCloudDisconnected'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -5725,7 +5749,7 @@ class WpMediaFolder
|
||||
*/
|
||||
public function moveFileUploadToSelectFolder($attachment_id)
|
||||
{
|
||||
if (isset($_POST['id_category'])) {
|
||||
if (isset($_POST['id_category']) && isset($_POST['wpmf_nonce'])) {
|
||||
if (empty($_POST['wpmf_nonce']) || !wp_verify_nonce($_POST['wpmf_nonce'], 'wpmf_nonce')) {
|
||||
die();
|
||||
}
|
||||
@@ -5788,4 +5812,43 @@ class WpMediaFolder
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete files and folders information in database if cloud was disconnected
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeDatabaseWhenCloudDisconnected()
|
||||
{
|
||||
//on Google Drive
|
||||
$option_cloud_google_drive = get_option(self::$option_google_drive_config);
|
||||
$folder_google_drive = get_terms(array('name' => 'Google Drive', 'parent' => 0, 'hide_empty' => false, 'taxonomy' => WPMF_TAXO));
|
||||
if (!is_wp_error($folder_google_drive) && $folder_google_drive && (!isset($option_cloud_google_drive['connected']) || $option_cloud_google_drive['connected'] !== 1)) {
|
||||
$this->doRemoveFolders($folder_google_drive[0]->term_id);
|
||||
}
|
||||
//on Dropbox
|
||||
$option_cloud_dropbox = get_option(self::$option_dropbox_config);
|
||||
$folder_dropbox = get_terms(array('name' => 'Dropbox', 'parent' => 0, 'hide_empty' => false, 'taxonomy' => WPMF_TAXO));
|
||||
if (!is_wp_error($folder_dropbox) && $folder_dropbox && empty($option_cloud_dropbox['dropboxToken'])) {
|
||||
$this->doRemoveFolders((int)$folder_dropbox[0]->term_id);
|
||||
}
|
||||
//on One Drive
|
||||
$option_cloud_one_drive = get_option(self::$option_one_drive_config);
|
||||
$folder_one_drive = get_terms(array('name' => 'Onedrive', 'parent' => 0, 'hide_empty' => false, 'taxonomy' => WPMF_TAXO));
|
||||
if (!is_wp_error($folder_one_drive) && $folder_one_drive && !isset($option_cloud_one_drive['connected'])) {
|
||||
$this->doRemoveFolders((int)$folder_one_drive[0]->term_id);
|
||||
}
|
||||
//on One Drive business
|
||||
$option_cloud_one_drive_business = get_option(self::$option_one_drive_business_config);
|
||||
$folder_one_drive_business = get_terms(array('name' => 'Onedrive Business', 'parent' => 0, 'hide_empty' => false, 'taxonomy' => WPMF_TAXO));
|
||||
if (!is_wp_error($folder_one_drive_business) && $folder_one_drive_business && !isset($option_cloud_one_drive_business['connected'])) {
|
||||
$this->doRemoveFolders((int)$folder_one_drive_business[0]->term_id);
|
||||
}
|
||||
//on Next Cloud
|
||||
$connect_nextcloud = wpmfGetOption('connect_nextcloud');
|
||||
$folder_next_cloud = get_terms(array('name' => 'Nextcloud', 'parent' => 0, 'hide_empty' => false, 'taxonomy' => WPMF_TAXO));
|
||||
if (!is_wp_error($folder_next_cloud) && $folder_next_cloud && empty($connect_nextcloud)) {
|
||||
$this->doRemoveFolders((int)$folder_next_cloud[0]->term_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -511,7 +511,7 @@ class WpmfMediaFolderOption
|
||||
$wpmfQueue = JuMainQueue::getInstance('wpmf');
|
||||
$wpmfQueue->updateQueueTermMeta((int)$responses['folder_id'], (int)$element_id);
|
||||
$wpmfQueue->updateResponses((int)$element_id, $responses);
|
||||
$this->doAddImportFtpQueue($datas['path'] . DIRECTORY_SEPARATOR, (int)$responses['folder_id']);
|
||||
$this->doAddImportFtpQueue($datas['path'] . DIRECTORY_SEPARATOR, (int)$responses['folder_id'], $datas['only_file']);
|
||||
} else {
|
||||
$upload_dir = wp_upload_dir();
|
||||
$info_file = wp_check_filetype($datas['path']);
|
||||
@@ -908,10 +908,11 @@ class WpmfMediaFolderOption
|
||||
*
|
||||
* @param string $directory Directory
|
||||
* @param integer $folder_parent ID of folder parent on media library
|
||||
* @param integer $only_file Import file without subdirectories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function doAddImportFtpQueue($directory, $folder_parent = 0)
|
||||
public function doAddImportFtpQueue($directory, $folder_parent = 0, $only_file = null)
|
||||
{
|
||||
if (file_exists($directory)) {
|
||||
$dir_files = glob($directory . '*');
|
||||
@@ -929,7 +930,7 @@ class WpmfMediaFolderOption
|
||||
'folder_parent' => $folder_parent,
|
||||
'action' => 'wpmf_import_ftp_to_library'
|
||||
);
|
||||
if (is_dir($dir_file)) {
|
||||
if (is_dir($dir_file) && empty($only_file)) {
|
||||
$datas['name'] = $name;
|
||||
$datas['type'] = 'folder';
|
||||
} else {
|
||||
@@ -1315,6 +1316,7 @@ class WpmfMediaFolderOption
|
||||
}
|
||||
|
||||
$list_import = $_POST['wpmf_list_import'];
|
||||
$only_file = $_POST['wpmf_only_file'];
|
||||
if ($list_import !== '') {
|
||||
$lists = explode(',', $list_import);
|
||||
if (in_array('', $lists)) {
|
||||
@@ -1337,7 +1339,8 @@ class WpmfMediaFolderOption
|
||||
'folder_parent' => 0,
|
||||
'action' => 'wpmf_import_ftp_to_library',
|
||||
'name' => basename($validate_path),
|
||||
'type' => 'folder'
|
||||
'type' => 'folder',
|
||||
'only_file' => $only_file
|
||||
);
|
||||
|
||||
$wpmfQueue = JuMainQueue::getInstance('wpmf');
|
||||
@@ -1347,7 +1350,7 @@ class WpmfMediaFolderOption
|
||||
} else {
|
||||
$responses = json_decode($row->responses, true);
|
||||
if (isset($responses['folder_id'])) {
|
||||
$this->doAddImportFtpQueue($datas['path'] . DIRECTORY_SEPARATOR, (int)$responses['folder_id']);
|
||||
$this->doAddImportFtpQueue($datas['path'] . DIRECTORY_SEPARATOR, (int)$responses['folder_id'], $only_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +124,10 @@ $size = size_format($bytes);
|
||||
<div class="wpmf-process-bar-full process_import_ftp_full" style="">
|
||||
<div class="wpmf-process-bar process_import_ftp" data-w="0"></div>
|
||||
</div>
|
||||
<div class="wpmf-setting-only-file-import">
|
||||
<input type="checkbox" id="only_file">
|
||||
<span>Import folders without their subdirectories</span>
|
||||
</div>
|
||||
<button type="button"
|
||||
class="ju-button no-background orange-button waves-effect waves-light import_ftp_button"
|
||||
style="padding: 8.5px 15px">
|
||||
|
||||
Reference in New Issue
Block a user