-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-augment-types.php
144 lines (92 loc) · 2.62 KB
/
class-augment-types.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* @package Augment Types
* @since 0.1.0
*/
use AugmentTypes\Archive;
use AugmentTypes\Excerpt;
use AugmentTypes\Expire;
use AugmentTypes\Feature;
use AugmentTypes\Sort;
class AugmentTypes {
private static $instance;
private static $data;
public static function instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
self::$data = get_plugin_data( AUGMENT_TYPES );
self::$data['URL'] = plugin_dir_url( AUGMENT_TYPES );
self::$data['PATH'] = plugin_dir_path( AUGMENT_TYPES );
add_action( 'plugins_loaded', array( $this, 'load_text_domain' ) );
add_action( 'wpmu_new_blog', array( $this, 'new_blog' ) );
add_filter( 'term_count', array( $this, 'per_type' ), 10, 3 );
Sort::instance();
Feature::instance();
Archive::instance();
Excerpt::instance();
Expire::instance();
}
public static function get_data( $key ) {
return self::$data[ $key ];
}
public static function activate( $network_wide ) {
if ( function_exists( 'is_multisite' ) && is_multisite() && $network_wide ) {
global $wpdb;
$current = $wpdb->blogid;
$blogs = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
foreach ( $blogs as $blog ) {
switch_to_blog( $blog );
self::_alter_table();
}
switch_to_blog( $current );
} else {
self::_alter_table();
}
}
public function load_text_domain() {
load_plugin_textdomain( 'augment-types' );
}
public static function new_blog( $id ) {
global $wpdb;
if ( is_plugin_active_for_network( plugin_basename( AUGMENT_TYPES ) ) ) {
$current = $wpdb->blogid;
switch_to_blog( $id );
self::_alter_table();
switch_to_blog( $current );
}
}
public static function _alter_table() {
global $wpdb;
if ( ! $wpdb->query( "SHOW COLUMNS FROM $wpdb->terms LIKE 'term_order'" ) ) {
$wpdb->query( "ALTER TABLE $wpdb->terms ADD `term_order` INT( 11 ) NOT NULL DEFAULT '0'" );
}
}
public function per_type( $value, $term_id, $taxonomy ) {
$screen = get_current_screen();
if ( null === $screen || 'edit-tags' !== $screen->base ) {
return $value;
}
$args = array(
'post_type' => $screen->post_type,
'post_status' => 'any',
'fields' => 'ids',
'no_found_rows' => true,
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'terms' => $term_id,
),
),
);
$query = new WP_Query( $args );
return $query->post_count;
}
}