• Resolved bhasic

    (@bhasic)


    Hello

    I’m customizing the backend view based on user roles and I need to unset some screen options (columns) in mla-menu. What do I need to add in my functions.php?

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

    (@dglingren)

    Thanks for the question. MLA provides many actions and filters (hooks) to let you customize the Media/Assistant admin submenu. They are outlined in the “Media/Assistant Submenu Actions and Filters (Hooks)” section of the Settings/Media Library Assistant Documentation tab. The following hooks for column customization are defined in /media-library-assistant/includes/class-mla-list-table.php:

    • mla_list_table_get_columns – Gives you an opportunity to filter the list table columns.
    • mla_list_table_get_hidden_columns – Gives you an opportunity to filter the hidden list table columns.
    • mla_list_table_get_sortable_columns – Gives you an opportunity to filter the sortable list table columns; a good alternative to the ‘manage_media_page_mla_menu_sortable_columns’ filter.

    The calling parameters for all of the hooks are provided in the “MLA List Table Hooks Example” plugin. Here are the three column customization hooks in that plugin:

    	/**
    	 * Filter the MLA_List_Table columns
    	 *
    	 * This MLA-specific filter gives you an opportunity to filter the list table columns.
    	 *
    	 * @since 1.00
    	 *
    	 * @param	array	$columns An array of columns.
    	 *					format: column_slug => Column Label
    	 */
    	public static function mla_list_table_get_columns( $columns ) {
    		//error_log( 'MLAListTableHooksExample::mla_list_table_get_columns $columns = ' . var_export( $columns, true ), 0 );
    		return $columns;
    	} // mla_list_table_get_columns
    
    	/**
    	 * Filter the MLA_List_Table hidden columns
    	 *
    	 * This MLA-specific filter gives you an opportunity to filter the hidden list table columns.
    	 *
    	 * @since 1.00
    	 *
    	 * @param	array	$hidden_columns An array of columns.
    	 *					format: index => column_slug
    	 */
    	public static function mla_list_table_get_hidden_columns( $hidden_columns ) {
    		//error_log( 'MLAListTableHooksExample::mla_list_table_get_hidden_columns $hidden_columns = ' . var_export( $hidden_columns, true ), 0 );
    		return $hidden_columns;
    	} // mla_list_table_get_hidden_columns
    
    	/**
    	 * Filter the MLA_List_Table sortable columns
    	 *
    	 * This MLA-specific filter gives you an opportunity to filter the sortable list table
    	 * columns; a good alternative to the 'manage_media_page_mla_menu_sortable_columns' filter.
    	 *
    	 * @since 1.00
    	 *
    	 * @param	array	$sortable_columns	An array of columns.
    	 *										Format: 'column_slug' => 'orderby'
    	 *										or 'column_slug' => array( 'orderby', true )
    	 *
    	 * The second format will make the initial sorting order be descending.
    	 */
    	public static function mla_list_table_get_sortable_columns( $sortable_columns ) {
    		//error_log( 'MLAListTableHooksExample::mla_list_table_get_sortable_columns $sortable_columns = ' . var_export( $sortable_columns, true ), 0 );
    		return $sortable_columns;
    	} // mla_list_table_get_sortable_columns

    I hope that gets you started on a solution for your application. I am marking this topic resolved, but please update it if you have problems or further questions regarding the customization of the Media/Assistant admin submenu.

    Thread Starter bhasic

    (@bhasic)

    I got the columns disabled, but I’m stuck trying to disable mla-menu list’s thumbnail links to attachment editor page and Edit item from Quick edit. I want the Quick edit to be the only way to edit attachments.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the good news about your progress. You wrote “I’m stuck trying to disable mla-menu list’s thumbnail links…” The current MLA version does not have any filters for that. I have implemented two new filters to make that possible:

    • mla_list_table_primary_column_link – Gives you an opportunity to filter the primary column thumbnail hyperlink permission.
    • mla_list_table_primary_column_content – Gives you an opportunity to modify or replace the content of the primary column.

    The calling parameters for all of the hooks are provided in the “MLA List Table Hooks Example” plugin. Here are the two primary column customization hooks in that plugin:

    	/**
    	 * Filter the primary column thumbnail hyperlink permission
    	 *
    	 * This filter gives you an opportunity to include or omit the Media/Edit Media hyperlink
    	 * behind the item thumbnail image.
    	 *
    	 * @since 1.14
    	 *
    	 * @param	boolean	$add_link	True to add hyperlink, false to omit it.
    	 * @param	object	$item		The current Media Library item.
    	 * @param	boolean	$is_trash	True if the current view is of the Media Trash.
    	 */
    	public static function mla_list_table_primary_column_link( $add_link, $item, $is_trash ) {
    		//error_log( "MLAListTableHooksExample::mla_list_table_primary_column_link( add: {$add_link}, trash: {$is_trash} ) \$item = " . var_export( $item, true ), 0 );
    		return $add_link;
    	} // mla_list_table_primary_column_link
    
    	/**
    	 * Filter the primary column content
    	 *
    	 * This filter gives you an opportunity to modify or replace the content of the primary column.
    	 *
    	 * @since 1.14
    	 *
    	 * @param	boolean	$final_content True to add hyperlink, false to omit it.
    	 * @param	object	$item		The current Media Library item.
    	 * @param	boolean	$add_link	True to add hyperlink, false to omit it.
    	 * @param	string	$thumb		IMG tag for the item thumbnail image.
    	 * @param	string	$title		Item "draft or post" title.
    	 * @param	string	$edit_url	URL for the Media/Edit Media page with view arguments.
    	 * @param	string	$column_content Original content for the column, without MLA additions.
    	 */
    	public static function mla_list_table_primary_column_content( $final_content, $item, $add_link, $thumb, $title, $edit_url, $column_content ) {
    		//error_log( "MLAListTableHooksExample::mla_list_table_primary_column_content( add: {$add_link}, {$title}, {$edit_url} ) \$item = " . var_export( $item, true ), 0 );
    		//error_log( "MLAListTableHooksExample::mla_list_table_primary_column_content( add: {$add_link}, {$title}, {$edit_url} ) \$column_content = " . var_export( $column_content, true ), 0 );
    		//error_log( "MLAListTableHooksExample::mla_list_table_primary_column_content( add: {$add_link}, {$title}, {$edit_url} ) \$final_content = " . var_export( $final_content, true ), 0 );
    		return $final_content;
    	} // mla_list_table_primary_column_content

    The first filter should complete your application; just pass “false” back from the filter to disable the Media/Edit Media link when appropriate.

    I have uploaded a new MLA Development Version dated 20231106 that includes the enhancement. You can find step-by-step instructions for using the Development Version in this earlier topic:

    How to download & install the current development version of MLA

    Once the Development Version is installed you can try out the new filters.

    The enhancement will be part of my next MLA version, but in the interim it would be great if you could install the Development Version and let me know how it works for you. Thanks for inspiring this MLA improvement.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to unset columns?’ is closed to new replies.