-
Notifications
You must be signed in to change notification settings - Fork 0
/
ac-addon-mla.php
108 lines (87 loc) · 2.79 KB
/
ac-addon-mla.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/*
Plugin Name: Admin Columns - Media Library Assistant
Version: 1.1
Description: Compatibility add-on for Media Library Assistant
Author: Codepress
Author URI: https://admincolumns.com
Text Domain: codepress-admin-columns
*/
defined( 'ABSPATH' ) or die();
define( 'ADDON_MLA_FILE', __FILE__ );
class AC_Addon_MLA {
public function __construct() {
add_action( 'after_setup_theme', array( $this, 'init' ) );
}
public function init() {
if ( ! class_exists( 'MLACore' ) ) {
return;
}
// Listscreen
add_action( 'ac/list_screens', array( $this, 'register_list_screen' ) );
// Columns
add_filter( 'ac/column/custom_field/meta_keys', array( $this, 'remove_custom_columns' ) );
// Export
add_action( 'ac/table/list_screen', array( $this, 'export_table_global' ) );
}
public static function get_plugin_dir() {
return plugin_dir_path( __FILE__ ) . 'includes/';
}
/**
* MLA list screen
*/
public function register_list_screen() {
require_once self::get_plugin_dir() . 'class-listscreen.php';
if ( function_exists( 'ACP' ) ) {
require_once self::get_plugin_dir() . 'class-listscreen-pro.php';
AC()->register_list_screen( new AC_Addon_MLA_ListScreen_Pro );
}
else {
AC()->register_list_screen( new AC_Addon_MLA_ListScreen );
}
}
/**
* Remove duplicate columns from the Admin Columns "Custom" section
*
* @since 2.52
*
* @param array $keys Distinct meta keys from DB
*/
public static function remove_custom_columns( $keys ) {
// Find the fields already present in the submenu table
$mla_columns = apply_filters( 'mla_list_table_get_columns', MLAQuery::$default_columns );
$mla_custom = array();
foreach ( $mla_columns as $slug => $heading ) {
if ( 'c_' === substr( $slug, 0, 2 ) ) {
$mla_custom[] = $heading;
}
}
// Remove the fields already present in the submenu table
foreach ( $keys as $index => $value ) {
if ( in_array( esc_html( $value ), $mla_custom ) ) {
unset( $keys[ $index ] );
}
}
return $keys;
}
/**
* Currently the MLA_List_Table prepare query is loaded after the <head>.
*
* When exporting the same page is being requested by an ajax request and triggers the filter 'the_posts'.
* The callback for this filter will print a json string. This needs to be done before any rendering of the page.
*
* Also, export needs the $GLOBALS['wp_list_table'] to be populated for displaying the export button.
*
* @param AC\ListScreen $list_screen
*/
public function export_table_global( AC\ListScreen $list_screen ) {
if ( ! $list_screen instanceof AC_Addon_MLA_ListScreen_Pro ) {
return;
}
global $wp_list_table;
require_once( MLA_PLUGIN_PATH . 'includes/class-mla-list-table.php' );
$wp_list_table = new MLA_List_Table();
$wp_list_table->prepare_items();
}
}
new AC_Addon_MLA;