plugin updates

This commit is contained in:
Tony Volpe
2024-11-25 13:10:11 -05:00
parent 864fe717f9
commit 76d447655a
48 changed files with 1945 additions and 200 deletions

View File

@@ -87,7 +87,12 @@ class WpMediaFolder
add_filter('wp_prepare_attachment_for_js', array($this, 'svgsResponseForSvg'), 10, 3);
add_filter('wp_prepare_attachment_for_js', array($this, 'prepareAttachmentForJs'), 10, 3);
add_action('admin_footer', array($this, 'editorFooter'));
$format_mediatitle = wpmfGetOption('format_mediatitle');
$format_mediatitle = 1;
$settings = get_option('wpmf_settings');
if (isset($settings) && isset($settings['format_mediatitle'])) {
$format_mediatitle = $settings['format_mediatitle'];
}
if ((int) $format_mediatitle === 1) {
add_action('add_attachment', array($this, 'updateFileTitle'));
}
@@ -121,6 +126,7 @@ class WpMediaFolder
add_action('pre_get_posts', array($this, 'addTagFilter'), 10, 1);
add_filter('attachment_fields_to_edit', array($this, 'changeTagSlugToName'), 10, 2);
add_filter('attachment_fields_to_edit', array($this, 'addTagHelps'), 10, 2);
add_action('pre_delete_attachment', array($this, 'deleteAttachmentCloud'), 11, 2);
}
/**
@@ -3489,9 +3495,31 @@ class WpMediaFolder
$attach_data = wp_generate_attachment_metadata($id_file, $file_dir . $newname);
wp_update_attachment_metadata($id_file, $attach_data);
}
//check is cloud
$id_category_new = $id_category;
$parent = $this->getFolderParent($id_category, $id_category);
$cloud_folder_type = wpmfGetCloudFolderType($parent);
if ($cloud_folder_type !== 'local') {
$id_category = 0;
}
do_action('wpmf_add_attachment', $id_file, $id_category);
// set attachment to term
wp_set_object_terms((int)$id_file, (int)$id_category, WPMF_TAXO, false);
wp_set_object_terms((int)$id_file, (int)$id_category_new, WPMF_TAXO, false);
if ($cloud_folder_type !== 'local') {
// check current folder
$current_category = 0;
// compability with WPML plugin
WpmfHelper::moveFileWpml($id_file, $current_category, $parent);
wp_remove_object_terms((int) $id_file, $current_category, WPMF_TAXO);
$params = array('trigger' => 'move_attachment');
$params['local_to_cloud'] = 1;
do_action('wpmf_attachment_set_folder', $id_file, (int)$parent, $params);
}
wp_send_json(array('status' => true, 'id_file' => $id_file, 'name' => $newname, 'id_category' => $id_category));
@@ -3690,6 +3718,21 @@ class WpMediaFolder
if (is_wp_error($inserted)) {
wp_send_json(array('status' => false, 'msg' => $inserted->get_error_message()));
} else {
// create physical folder
$folder_options = get_option('wpmf_queue_options');
if (isset($folder_options['enable_physical_folders']) && !empty($folder_options['enable_physical_folders'])) {
$cat_path = get_term_parents_list($inserted['term_id'], WPMF_TAXO, array(
'separator' => '/',
'link' => false,
'format' => 'name',
));
$upload_dir = wp_upload_dir();
$folder_dir = $upload_dir['basedir'] . '/' . trim($cat_path, '/');
if (!file_exists($folder_dir)) {
wp_mkdir_p($folder_dir);
}
}
// update term_group for new term
$updateted = wp_update_term($inserted['term_id'], WPMF_TAXO, array('term_group' => $user_id));
$termInfos = get_term($updateted['term_id'], WPMF_TAXO);
@@ -3826,11 +3869,12 @@ class WpMediaFolder
/**
* Do remove multiple folders
*
* @param string $folder_list Folder list id
* @param string $folder_list Folder list id
* @param boolean $remove_on_cloud Remove file on cloud
*
* @return boolean
*/
public function doRemoveFolders($folder_list)
public function doRemoveFolders($folder_list, $remove_on_cloud = true)
{
$wpmf_list_sync_media = get_option('wpmf_list_sync_media');
$wpmf_ao_lastRun = get_option('wpmf_ao_lastRun');
@@ -3877,7 +3921,9 @@ class WpMediaFolder
$type = get_term_meta((int) $sub_folder_id, 'wpmf_drive_root_type', true);
if (empty($type)) {
$term = get_term($sub_folder_id, WPMF_TAXO);
do_action('wpmf_before_delete_folder', $term);
if ($remove_on_cloud) {
do_action('wpmf_before_delete_folder', $term);
}
wp_delete_term($sub_folder_id, WPMF_TAXO);
/**
* Delete a folder
@@ -3904,6 +3950,9 @@ class WpMediaFolder
}
} else {
foreach ($attachments as $attachment_id) {
if (!$remove_on_cloud) {
remove_action('pre_delete_attachment', array($this, 'deleteAttachmentCloud'), 11);
}
wp_delete_attachment($attachment_id);
}
@@ -5895,31 +5944,31 @@ class WpMediaFolder
$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);
$this->doRemoveFolders($folder_google_drive[0]->term_id, false);
}
//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);
$this->doRemoveFolders((int)$folder_dropbox[0]->term_id, false);
}
//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);
$this->doRemoveFolders((int)$folder_one_drive[0]->term_id, false);
}
//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);
$this->doRemoveFolders((int)$folder_one_drive_business[0]->term_id, false);
}
//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);
$this->doRemoveFolders((int)$folder_next_cloud[0]->term_id, false);
}
}
@@ -6033,4 +6082,17 @@ class WpMediaFolder
return $form_fields;
}
/**
* Delete file on cloud
*
* @param object $null Null.
* @param object $post Post.
*
* @return void
*/
public function deleteAttachmentCloud($null, $post)
{
do_action('wpmf_delete_attachment_cloud', $post->ID);
}
}