• Resolved idlee69

    (@idlee69)


    When I add a folder name to the path in media library it changes the url correctly and moves the file correctly but enters the folder name twice in the filepath in the database. For example: changing /xxx.pdf to /posters/xxx.pdf becomes …../updates/posters/posters/xxx.pdf for my custom field meta in the database.

Viewing 3 replies - 16 through 18 (of 18 total)
  • Thread Starter idlee69

    (@idlee69)

    Just letting you know that I have given up with this. Also, I foolishly purchased the WP Media Folder plugin you recommended and have now removed it – partly because half of it does not work with Firefox but mainly because so much of the extras it provides like watermarking and thumbnail regeneration, etc. can be far better done and controlled using other small plugins. The ability to mimic folders is really no better than a simple plugin to provide categories. If only you could lift some open-source category code for your plugin you would have a brilliant self-contained utility well worth paying for. Please let me know if you ever change your mind.

    Plugin Author dbarrere

    (@dbarrere)

    My bad, I did not tell you the update was available.
    It has been updated a week ago.

    About WP Media Folder you can ask the support team I’m sure they will fix any browser compatibility problem.

    Of course I can let you know if I change my mind about categories.

    Best regards

    Thread Starter idlee69

    (@idlee69)

    I have found a way to add a taxonomy or category as a folder list to the media edit screen so you can create and select folders by ticking boxes rather than entering folder changes manually into an input box. It works perfectly except for one little hitch – you have to update the media item twice! First to get the taxonomy folder list changes updated so then they can be used by the plugin to do its stuff. My skills in WordPress have now reached there limit. Any ideas?

    The following changes were made in plugins\wp-media-folders\classes\classes\wp-media-folders.php Line 140-173 are replaced with:
    /**
    * ###############################################################################
    * Add hierarchical taxonomy called ‘Folders’ to ‘Media’ menu
    * https://code.tutsplus.com/articles/applying-categories-tags-and-custom-taxonomies-to-media-attachments–wp-32319
    * register new taxonomy which applies to attachments
    */

    function wptp_add_folders_taxonomy() {
    $labels = array(
    ‘name’ => ‘Folders’,
    ‘singular_name’ => ‘Folder’,
    ‘search_items’ => ‘Search Folders’,
    ‘all_items’ => ‘All Folders’,
    ‘parent_item’ => ‘Parent Folder’,
    ‘parent_item_colon’ => ‘Parent Folder:’,
    ‘edit_item’ => ‘Edit Folder’,
    ‘update_item’ => ‘Update Folder’,
    ‘add_new_item’ => ‘Add New Folder’,
    ‘new_item_name’ => ‘New Folder Name’,
    ‘menu_name’ => ‘Folders’,
    );

    $args = array(
    ‘labels’ => $labels,
    ‘hierarchical’ => true,
    ‘query_var’ => ‘true’,
    ‘rewrite’ => ‘true’,
    ‘show_admin_column’ => ‘true’,
    );

    register_taxonomy( ‘folders’, ‘attachment’, $args );
    }
    add_action( ‘init’, ‘wptp_add_folders_taxonomy’ );

    /**
    * Change file path using the taxonomy of folders.
    * BUT this requires pressing [Update] twice as have to save taxonomy/folder changes first.
    */
    add_filter(
    ‘attachment_fields_to_edit’,
    function ($form_fields, $post) {
    $url = wp_get_attachment_url($post->ID);
    $uploads = wp_upload_dir();
    if (strpos($url, $uploads[‘baseurl’])!==0) {
    $html = __(‘This file is not in the allowed upload folder’, ‘wp-media-folders’);
    } else {
    $path = str_replace($uploads[‘baseurl’], “”, $url);
    $file_extension = pathinfo($path, PATHINFO_EXTENSION);
    $path = ‘/’.$post->post_name;
    $folders_array = wp_get_post_terms($post->ID, ‘folders’, array(‘orderby’ => ‘parent’, “fields” => “names”));
    if (!empty($folders_array)) {$path = ‘/’.strtolower(implode(“/”,$folders_array)).$path;}
    //$html = ‘<span style=”width:80%;” name=”attachments[‘.$post->ID.’][file_path]” id=”attachments[‘.$post->ID.’][file_path]” value=”‘.htmlentities($path).'”>’.htmlentities($path).'</span>’.’.’.$file_extension;
    $html = ‘<input style=”width:80%;” name=”attachments[‘.$post->ID.’][file_path]” id=”attachments[‘.$post->ID.’][file_path]” value=”‘.htmlentities($path).'” /> . ‘.$file_extension;
    }

    $form_fields[‘file_path’] = array(
    ‘label’ => __(‘File path’, ‘wp-media-folders’),
    ‘input’ => ‘html’,
    ‘html’ => $html,
    ‘helps’ => __(sprintf(‘File path and name related to upload folder %s’, ‘/’ . substr($uploads[‘basedir’], strlen(get_home_path()))), ‘wp-media-folders’)
    );

    return $form_fields;
    },
    10,
    2
    );
    /**
    * #####################################################################
    */

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Incorrect filepath change in database’ is closed to new replies.