Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for your question. I want to be sure I understand what you are asking.

    1. Which method are you using to “upload multiple files“? Are you using the Media/Add New (Upload New Files) screen or some other method?
    2. When you write “Add Title eg. Title name“, where does “Title name” come from?
    3. Do you want the number to start over at 1 for each new batch of files?

    I am traveling until 12 August and I do not have access to my development system. If you can answer my questions I can work on this after I return home. Thanks for your interest in the plugin.

    Thread Starter Superbobo75

    (@superbobo75)

    Method upload multiple files. Caption etc. I put through bulk edit area.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your patience. I have finally had some time to investigate this question. I will need more information from you before I can develop an answer.

    The bulk edit area on the Media/Upload New Media screen shares the same code that the Media/Assistant submenu table Bulk Edit action uses. You can use MLA’s “Media/Assistant Submenu Actions and Filters (Hooks)” to do things like add a counter to the Title string.

    However, each file added to the Media/Upload New Media is processed as an independent Ajax request/response, so there is no easy way to know which files are part of the same “upload multiple files” batch.

    WordPress will generate a Title for each file based on the file name and some other fields within each file. You can override the default Title if you enter a value in the “bulk edit area”. If you enter a value in this field such as “Title name”, that value will be the same on every upload until you change it or leave the Upload New Media screen.

    I can write code that will “remember” the value you enter and use that to know that the files are part of the same “batch”; will that work for your application? Do you always enter something in the “Title” field of the bulk edit area?

    I will work on a solution that uses the value in the Title field and adds a counter to every title that is the same. If that does not work for you, let me know how to tell which files are part of one batch. Thanks for your help and any additional information you can give me.

    Plugin Author David Lingren

    (@dglingren)

    I have uploaded a new Development Version dated 20150824. It contains a new example plugin, /examples/mla-upload-bulk-edit-example.php.txt, that contains a solution for your application. It will recognize a non-empty Title string in the Bulk Edit area of the Upload New Media screen and append a sequence number to each new item with the same Title value.

    The code specific to your needs is in one filter; you can use the example plugin or add this code to your theme’s functions.php file:

    public static function mla_list_table_bulk_action_item_request( $request, $bulk_action, $post_id, $custom_field_map ) {
        // If it's not Upload New Media or there's no Title, we're done
        if ( ! ( isset( $request['screen'] ) && 'async-upload' == $request['screen'] && ! empty( $request['post_title'] ) ) ) {
            return $request;
        }
    
        // Retrieve the transient and continue the batch or start a new batch
        $batch = get_transient( 'mla-upload-bulk-edit-example-batch' );
    
        // Title must match to continue a batch
        if ( is_array( $batch ) && isset( $batch['post_title'] ) && ( $batch['post_title'] != $request['post_title'] )) {
            $batch = false;
        }
    
        // Increment or set the counter and modify the Title
        if ( is_array( $batch ) && isset( $batch['post_title'] ) ) {
            $batch['instance'] += 1;
        } else {
            $batch = array( 'post_title' => $request['post_title'], 'instance' => 1 );
        }
    
        $request['post_title'] .= ' ' . $batch['instance'];
    
        // Save the transient for more batch items
        set_transient( 'mla-upload-bulk-edit-example-batch', $batch, 300 ); // five minutes
    
        return $request;
    } // mla_list_table_bulk_action_item_request

    If you need more specific help installing and activating the example plugin, let me know. If you would like a copy of the plugin by email, use the Contact Us page at the FTJ web site to send me your contact information:

    Fair Trade Judaica/Contact Us

    Do not post your e-mail address in the forum; personal details in a public forum violates WordPress guidelines. If you have trouble accessing the FTJ site, post a note here with your country of origin and I can temporarily unblock it.

    I am marking this topic resolved, but please update it if you have any problems or further questions regarding the solution presented above. Thanks for your patience and for your interest in the plugin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Counter in title for multiple upload images’ is closed to new replies.