plugin updates
This commit is contained in:
@@ -116,7 +116,11 @@ 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_filter('bulk_actions-upload', array($this, 'registerTagBulkAction'), 10, 1);
|
||||
add_action('wp_enqueue_media', array($this, 'removeDatabaseWhenCloudDisconnected'));
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -623,6 +627,12 @@ class WpMediaFolder
|
||||
case 'auto_load_video_thumbnail':
|
||||
$this->autoLoadVideoThumbnail();
|
||||
break;
|
||||
case 'get_tag_item':
|
||||
$this->getTagItem();
|
||||
break;
|
||||
case 'save_tag_item':
|
||||
$this->saveTagItem();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1174,6 +1184,13 @@ class WpMediaFolder
|
||||
WPMF_VERSION
|
||||
);
|
||||
|
||||
wp_enqueue_style(
|
||||
'wpmf-tagify-style',
|
||||
plugins_url('/assets/css/tagify.css', dirname(__FILE__)),
|
||||
array(),
|
||||
WPMF_VERSION
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'wpmf-gallery-popup',
|
||||
plugins_url('/assets/js/display-gallery/jquery.magnific-popup.min.js', dirname(__FILE__)),
|
||||
@@ -1199,6 +1216,15 @@ class WpMediaFolder
|
||||
);
|
||||
}
|
||||
|
||||
wp_register_script(
|
||||
'wpmf-tagify',
|
||||
plugins_url('/assets/js/tagify.js', dirname(__FILE__)),
|
||||
array(),
|
||||
WPMF_VERSION
|
||||
);
|
||||
|
||||
wp_enqueue_script('wpmf-tagify');
|
||||
|
||||
wp_enqueue_script('resumable', plugins_url('/assets/js/resumable.js', dirname(__FILE__)), array('jquery'), WPMF_VERSION);
|
||||
wp_register_script(
|
||||
'wpmf-base',
|
||||
@@ -1327,7 +1353,7 @@ class WpMediaFolder
|
||||
*/
|
||||
$wpmf_capability = apply_filters('wpmf_user_can', current_user_can('upload_files'), 'load_script_style');
|
||||
if ($wpmf_capability) {
|
||||
if ($pagenow === 'upload.php') {
|
||||
if ($pagenow === 'upload.php' || $pagenow === 'edit-tags.php') {
|
||||
$mode = get_user_option('media_library_mode', get_current_user_id()) ? get_user_option('media_library_mode', get_current_user_id()) : 'grid';
|
||||
if ($mode === 'list') {
|
||||
$this->loadAssets();
|
||||
@@ -1591,6 +1617,14 @@ class WpMediaFolder
|
||||
$enable_permissions_settings = ((isset($current_user->allcaps['wpmf_enable_permissions_settings']) && $current_user->allcaps['wpmf_enable_permissions_settings']) || in_array('administrator', $current_user->roles));
|
||||
}
|
||||
|
||||
$enable_all_files_button = in_array('administrator', $current_user->roles) || !$active_media_access ;
|
||||
/**
|
||||
* Filter to enable "Display all files" button for specific user roles
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
$show_all_files_button = apply_filters('wpmf_enable_all_files_button', $enable_all_files_button) ? 1 : 0;
|
||||
|
||||
$l18n = $this->translation();
|
||||
$vars = array(
|
||||
'site_url' => site_url(),
|
||||
@@ -1660,7 +1694,7 @@ class WpMediaFolder
|
||||
'img_url' => WPMF_PLUGIN_URL . 'assets/images/',
|
||||
'copy_files_to_bucket' => (!empty($configs['copy_files_to_bucket']) && is_plugin_active('wp-media-folder-addon/wp-media-folder-addon.php')) ? 1 : 0,
|
||||
'hide_own_media_button' => current_user_can('wpmf_hide_own_media_button') ? 1 : 0,
|
||||
'show_all_files_button' => in_array('administrator', $current_user->roles) || !$active_media_access ? 1 : 0
|
||||
'show_all_files_button' => $show_all_files_button
|
||||
);
|
||||
|
||||
return array('l18n' => $l18n, 'vars' => $vars);
|
||||
@@ -1755,6 +1789,9 @@ class WpMediaFolder
|
||||
'wpmf_remove_filter' => __('Media filters removed', 'wpmf'),
|
||||
'cancel' => __('Cancel', 'wpmf'),
|
||||
'create' => __('Create', 'wpmf'),
|
||||
'add' => __('Add', 'wpmf'),
|
||||
'add_tag' => __('Add tags', 'wpmf'),
|
||||
'create_or_select_tag' => __('Create or select tags', 'wpmf'),
|
||||
'save' => __('Save', 'wpmf'),
|
||||
'save_close' => __('Save and close', 'wpmf'),
|
||||
'ok' => __('OK', 'wpmf'),
|
||||
@@ -1966,7 +2003,8 @@ class WpMediaFolder
|
||||
'by_user' => esc_html__('By User', 'wpmf'),
|
||||
'remove_file_permission_msg' => esc_html__('You do not have permission to delete this file. Refresh folder to see image again', 'wpmf'),
|
||||
'remove_file_permission_msg1' => esc_html__('You do not have permission to delete this file', 'wpmf'),
|
||||
'update_file_permission_msg' => esc_html__('You do not have permission to update this file', 'wpmf')
|
||||
'update_file_permission_msg' => esc_html__('You do not have permission to update this file', 'wpmf'),
|
||||
'select_file_required' => esc_html__('Please select file to do this action', 'wpmf')
|
||||
);
|
||||
|
||||
return $l18n;
|
||||
@@ -5813,6 +5851,72 @@ class WpMediaFolder
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add bulk select tag
|
||||
*
|
||||
* @param array $bulk_actions List bulk actions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function registerTagBulkAction($bulk_actions)
|
||||
{
|
||||
$bulk_actions['tag'] = __('Add tags', 'wpmf');
|
||||
return $bulk_actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list tags
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getTagItem()
|
||||
{
|
||||
if (empty($_POST['wpmf_nonce'])
|
||||
|| !wp_verify_nonce($_POST['wpmf_nonce'], 'wpmf_nonce')) {
|
||||
die();
|
||||
}
|
||||
global $wpdb;
|
||||
|
||||
if (isset($_POST['tag_name']) && !empty($_POST['tag_name'])) {
|
||||
$list_tags = $wpdb->get_results($wpdb->prepare('SELECT t.name FROM ' . $wpdb->terms . ' as t INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON tt.term_id = t.term_id WHERE tt.taxonomy="wpmf_tag" AND t.name LIKE %s LIMIT %d', array('%' . $_POST['tag_name'] . '%',(int)10)));
|
||||
} else {
|
||||
$list_tags = $wpdb->get_results($wpdb->prepare('SELECT t.name FROM ' . $wpdb->terms . ' as t INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON tt.term_id = t.term_id WHERE tt.taxonomy="wpmf_tag" ORDER BY RAND() LIMIT %d', array((int)10)));
|
||||
}
|
||||
|
||||
if ($list_tags) {
|
||||
$list_tags = array_column($list_tags, 'name');
|
||||
wp_send_json(array('status' => true, 'list_tags' => $list_tags));
|
||||
} else {
|
||||
wp_send_json(array('status' => false));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save tags
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function saveTagItem()
|
||||
{
|
||||
if (empty($_POST['wpmf_nonce'])
|
||||
|| !wp_verify_nonce($_POST['wpmf_nonce'], 'wpmf_nonce')) {
|
||||
die();
|
||||
}
|
||||
if (isset($_POST['tag_name']) && !empty($_POST['tag_name']) && isset($_POST['post_ids'])) {
|
||||
foreach ($_POST['post_ids'] as $post_id) {
|
||||
$old_terms = array();
|
||||
$terms = wp_get_post_terms($post_id, 'wpmf_tag');
|
||||
if ($terms) {
|
||||
$old_terms = array_column($terms, 'name');
|
||||
}
|
||||
$new_term = array_unique(array_merge($_POST['tag_name'], $old_terms));
|
||||
wp_set_post_terms($post_id, $new_term, 'wpmf_tag');
|
||||
}
|
||||
wp_send_json(array('status' => true));
|
||||
}
|
||||
wp_send_json(array('status' => false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete files and folders information in database if cloud was disconnected
|
||||
*
|
||||
@@ -5851,4 +5955,59 @@ class WpMediaFolder
|
||||
$this->doRemoveFolders((int)$folder_next_cloud[0]->term_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tag helps
|
||||
*
|
||||
* @param array $form_fields Array of post fields.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function addTagHelps($form_fields)
|
||||
{
|
||||
$form_fields['wpmf_tag']['helps'] = 'Separate tags with commas';
|
||||
return $form_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tag filter
|
||||
*
|
||||
* @param object $query Query params.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addTagFilter($query)
|
||||
{
|
||||
$query->unset('wpmf_tag');
|
||||
if (isset($_COOKIE['wpmf_tag']) && !empty($_COOKIE['wpmf_tag'])) {
|
||||
$query->set('wpmf_tag', $_COOKIE['wpmf_tag']);
|
||||
} else {
|
||||
$query->unset('wpmf_tag');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change value of tags from slug to name
|
||||
*
|
||||
* @param array $form_fields Form fields.
|
||||
* @param object $post Post.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function changeTagSlugToName($form_fields, $post)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$terms = $wpdb->get_results($wpdb->prepare('SELECT tr.object_id, t.name FROM ' . $wpdb->terms . ' as t INNER JOIN ' . $wpdb->term_taxonomy . ' as tt ON tt.term_id = t.term_id INNER JOIN ' . $wpdb->term_relationships . ' as tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy="wpmf_tag" AND tr.object_id = %s', array($post->ID)));
|
||||
|
||||
$values = array();
|
||||
|
||||
foreach ($terms as $term) {
|
||||
$values[] = $term->name;
|
||||
}
|
||||
|
||||
$form_fields['wpmf_tag']['value'] = implode(', ', $values);
|
||||
|
||||
return $form_fields;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user