• Resolved bhasic

    (@bhasic)


    Would it be possible to make Att. Category and Att. Tags titles replaceable with Say What? and other plugins or code snippets in the Add media page? These:

    taxonomy-attachment_category > span.title.inline-edit-categories-label
    #mla-add-new-bulk-edit-div > fieldset.inline-edit-col-center.inline-edit-tags > div > label
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for the question – I want to make sure I understand your goal. You are asking how to change the titles above the taxonomy boxes in the Media/Add New Media File screen Bulk Edit area; is that right?

    If so, you can use some of MLA’s filters to modify the values and markup of the area. In particular, the mla_list_table_inline_bulk_values filter contains the markup for the taxonomy titles. Here is an outline of the filter function from the “MLA List Table Hooks Example” plugin:

    	/**
    	 * MLA_List_Table item bulk edit substitution values
    	 *
    	 * This filter gives you a chance to modify and extend the substitution values
    	 * for the three Bulk Edit form fieldsets.
    	 *
    	 * @since 1.10
    	 *
    	 * @param	array	$item_values [ parameter_name => parameter_value ] pairs
    	 */
    	public static function mla_list_table_inline_bulk_values( $item_values ) {
    		//error_log( 'MLAListTableHooksExample::mla_list_table_inline_bulk_values $item_values = ' . var_export( $item_values, true ), 0 );
    
    		/*
    		 * You can use the 'filter_root' element to distinguish among :
    		 *     'mla_upload_bulk_edit_form_blank',
    		 *     'mla_upload_bulk_edit_form_initial',
    		 *     'mla_upload_bulk_edit_form_preset',
    		 *     'mla_list_table_inline_blank',
    		 *     'mla_list_table_inline_initial',
    		 *     'mla_list_table_inline_preset'
    		 */
    		//error_log( "MLAListTableHooksExample::mla_list_table_inline_bulk_values filter_root = {$item_values['filter_root']}", 0 );
    
    		return $item_values;
    	} // mla_list_table_inline_bulk_values
    

    Here is an excerpt of the $item_values content:

    [19-Nov-2023 21:07:31 UTC] MLAListTableHooksExample::mla_list_table_inline_bulk_values $item_values = array (
      'filter_root' => 'mla_upload_bulk_edit_form_blank',
      'category_fieldset' => '  <fieldset class="inline-edit-col-left inline-edit-categories">
        <div class="inline-edit-col">
        <div id="taxonomy-attachment_category" class="categorydiv">
    		<span class="title inline-edit-categories-label">Att. Categories</span>
    		<input type="hidden" name="tax_input[attachment_category][]" value="0" />
    		<ul class="cat-checklist attachment_categorychecklist form-no-clear" id="attachment_categorychecklist" data-wp-lists="list:attachment_category">
    	
    		</ul>
    
    		<span><a class="hide-if-no-js" id="attachment_category-search-toggle" href="#attachment_category-search">?&nbsp;Search</a></span>
    
    		<div id="attachment_category-searcher" class="wp-hidden-children">
    		  <p id="attachment_category-search" class="category-add wp-hidden-child">
    			<label class="screen-reader-text" for="search-category">Search Att. Categories</label>
    			<input type="text" name="search-attachment_category" id="search-attachment_category" class="form-required form-input-tip" value="Search Att. Categories" aria-required="true">
    		  </p>
    		</div>
    	</div>
        <div class="mla_bulk_taxonomy_options">
          <input type="radio" name="tax_action[attachment_category]" id="tax_add_attachment_category" checked="checked" value="add" /> Add&nbsp;
          <input type="radio" name="tax_action[attachment_category]" id="tax_remove_attachment_category"  value="remove" /> Remove&nbsp;
          <input type="radio" name="tax_action[attachment_category]" id="tax_reset_attachment_category"  value="replace" /> Replace&nbsp;
        </div>
        </div>
      </fieldset>
    ',
      'tag_fieldset' => '  <fieldset class="inline-edit-col-center inline-edit-tags">
    ...

    You could use the PHP preg_replace() function to replace the existing title in the category_fieldset and tag_fieldset array elements with anything you choose.

    There is more information on the filters in the “Media/Assistant Submenu Actions and Filters (Hooks)” section of the Settings/Media Library Assistant Documentation tab.

    I am marking this topic resolved, but please update it if you have problems or further questions regarding the above suggestions.

    Thread Starter bhasic

    (@bhasic)

    I don’t understand how to make it work. This does nothing:

    function replace_text($item_values){
    ? ? $item_values ?= str_replace('Att. Categories', 'new text', $item_values);
    ? ? echo var_dump($item_values);
    ? ? return $item_values;
    }
    
    add_filter('mla_list_table_inline_bulk_values', 'replace_text');
    Plugin Author David Lingren

    (@dglingren)

    Thanks for giving my suggestions a try. I think a simple modification will give you better results. In my post I suggested the preg_replace()?function. Here is an example that is working well on my system

        $patterns = array(
        '!>Att. Categories</span>!',
        '!>Search Att. Categories</label>!',
        '!value="Search Att. Categories"!',
        );
    
        $replacements = array(
        '>My Categories</span>',
        '>Search My Categories</label>',
        'value="Search My Categories"',
        );
    
        $item_values = preg_replace( $patterns, $replacements, $item_values );

    The first element is the visible title at the top of the text area. The other two elements are required for screen readers, but do not display in normal circumstances. You can add additional sets of elements for other taxonomies as required. Let me know if this example works for you.

    Thread Starter bhasic

    (@bhasic)

    Still texts don’t change in media-new.php and nothing from var_dumps also. Maybe wrong filter?

    • This reply was modified 1 year ago by bhasic.
    Plugin Author David Lingren

    (@dglingren)

    Thanks for trying my suggestion. You’re using the right filter, but you may be calling the add_filter() function too soon. Here’s a comment I found in the WordPress Codex:

    https://developer.www.ads-software.com/reference/functions/add_filter/#comment-4863

    If you look at the “MLA List Table Hooks Example” plugin you will see that the add_filter() calls are run in the “init” action. You can try adding your code to the example plugin or you can try the solution outlined in the comment. You might also try writing to the error log instead of echoing to the browser. You can view the error log in the Settings/Media Library Assistant Debug tab.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Text changes’ is closed to new replies.