error or status message(s), 'body' => '',
* 'prevent_default' => true to bypass the MLA handler )
*/
public static function mla_list_table_inline_action( $item_content, $post_id ) {
/*
* Convert the comma-delimited string of "checked" checkbox values back to
* an ACF-compatible array
*/
if ( isset( $_REQUEST['custom_updates'] ) && isset( $_REQUEST['custom_updates']['acf_checkbox'] ) ) {
if ( ! empty( $_REQUEST['custom_updates']['acf_checkbox'] ) ) {
$_REQUEST['custom_updates']['acf_checkbox'] = explode( ',', $_REQUEST['custom_updates']['acf_checkbox'] );
}
}
return $item_content;
} // mla_list_table_inline_action
/**
* Process an MLA_List_Table bulk action
*
* This filter gives you an opportunity to pre-process an MLA_List_Table page-level
* or single-item action, standard or custom, before the MLA handler.
* The filter is called once for each of the items in $_REQUEST['cb_attachment'].
*
* @since 1.00
*
* @param array $item_content NULL, to indicate no handler.
* @param string $bulk_action the requested action.
* @param integer $post_id the affected attachment.
*
* @return object updated $item_content. NULL if no handler, otherwise
* ( 'message' => error or status message(s), 'body' => '',
* 'prevent_default' => true to bypass the MLA handler )
*/
public static function mla_list_table_bulk_action( $item_content, $bulk_action, $post_id ) {
static $acf_checkbox_value = NULL;
/*
* If the field is present and this is the first time we've been called,
* save the field value for our own update process and remove it from the
* $_REQUEST array to prevent MLA's default update processing.
*/
if ( ! empty( $_REQUEST['c_acf_checkbox'] ) ) {
if ( is_null( $acf_checkbox_value ) ) {
$acf_checkbox_value = trim( $_REQUEST['c_acf_checkbox'] );
}
$_REQUEST['c_acf_checkbox'] = '';
}
/*
* If the field is present,apply our own update process. Note the
* special 'empty' value to bulk-delete the custom field entirely.
*/
if ( ! empty( $acf_checkbox_value ) ) {
if ( 'empty' == $acf_checkbox_value ) {
delete_post_meta( $post_id, 'acf_checkbox' );
$item_content = array( 'message' => sprintf( __( 'Deleting %1$s', 'media-library-assistant' ) . '
', 'acf_checkbox' ) );
} else {
update_post_meta( $post_id, 'acf_checkbox', explode( ',', $acf_checkbox_value ) );
$item_content = array( 'message' => sprintf( __( 'Adding %1$s = %2$s', 'media-library-assistant' ) . '
', 'acf_checkbox', $acf_checkbox_value ) );
}
}
return $item_content;
} // mla_list_table_bulk_action
/**
* MLA_List_Table inline edit item values
*
* This filter gives you a chance to modify and extend the substitution values
* for the Quick and Bulk Edit forms.
*
* @since 1.00
*
* @param array $item_values parameter_name => parameter_value pairs
*
* @return array updated substitution parameter name => value pairs
*/
public static function mla_list_table_inline_values( $item_values ) {
/*
* Replace the ACF Field Name with a more friendly Field Label
*/
$item_values['custom_fields'] = str_replace( '>acf_checkbox<', '>ACF Checkbox<', $item_values['custom_fields'] );
$item_values['bulk_custom_fields'] = str_replace( '>acf_checkbox<', '>ACF Checkbox<', $item_values['bulk_custom_fields'] );
return $item_values;
} // mla_list_table_inline_values
/**
* 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
*
* @return array updated array of columns.
*/
public static function mla_list_table_get_columns( $columns ) {
/*
* Replace the MLA custom field slug with our own slug value
*/
if ( isset( $columns['c_acf_checkbox'] ) ) {
unset( $columns['c_acf_checkbox'] );
$columns['my_acf_checkbox'] = 'ACF Checkbox';
}
return $columns;
} // mla_list_table_get_columns_filter
/**
* 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
*
* @return array updated array of columns.
*/
public static function mla_list_table_get_hidden_columns( $hidden_columns ) {
/*
* Replace the MLA custom field slug with our own slug value
*/
$index = array_search( 'c_acf_checkbox', $hidden_columns );
if ( false !== $index ) {
$hidden_columns[ $index ] = 'my_acf_checkbox';
}
return $hidden_columns;
} // mla_list_table_get_hidden_columns_filter
/**
* 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.
*
* @return array updated array of columns.
*/
public static function mla_list_table_get_sortable_columns( $sortable_columns ) {
/*
* Replace the MLA custom field slug with our own slug value
*/
if ( isset( $sortable_columns['c_acf_checkbox'] ) ) {
$sortable_columns['my_acf_checkbox'] = $sortable_columns['c_acf_checkbox'];
unset( $sortable_columns['c_acf_checkbox'] );
}
return $sortable_columns;
} // mla_list_table_get_sortable_columns_filter
/**
* Supply a column value if no column-specific function has been defined
*
* Called when the MLA_List_Table can't find a value for a given column.
*
* @since 1.00
*
* @param string NULL, indicating no default content
* @param array A singular item (one full row's worth of data)
* @param array The name/slug of the column to be processed
* @return string Text or HTML to be placed inside the column
*/
public static function mla_list_table_column_default( $content, $item, $column_name ) {
/*
* Convert the ACF-compatible array to a comma-delimited list of
* "checked" checkbox values.
*/
if ( 'my_acf_checkbox' == $column_name ) {
$values = isset( $item->mla_item_acf_checkbox ) ? $item->mla_item_acf_checkbox : '';
if ( empty( $values ) ) {
return '';
} elseif ( is_array( $values ) ) {
return '[' . implode( '],[', $values ) . ']';
} else {
return $values;
}
}
return $content;
} // mla_list_table_column_default_filter
/**
* Filter the data for inline (Quick and Bulk) editing
*
* This filter gives you an opportunity to filter the data passed to the
* JavaScript functions for Quick and Bulk editing.
*
* @since 1.00
*
* @param string $inline_data The HTML markup for inline data.
* @param object $item The current Media Library item.
*
* @return string updated HTML markup for inline data.
*/
public static function mla_list_table_build_inline_data( $inline_data, $item ) {
/*
* Convert the ACF-compatible array to a comma-delimited list of
* "checked" checkbox values.
*/
$match_count = preg_match_all( '/\