GravityForms.php
3.99 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
namespace ACA\GravityForms;
use AC;
use AC\Asset\Script;
use AC\Asset\Style;
use AC\Registerable;
use ACA\GravityForms\Column\EntryConfigurator;
use ACA\GravityForms\Column\EntryFactory;
use ACA\GravityForms\ListScreen;
use ACA\GravityForms\Search\Query;
use ACA\GravityForms\TableScreen;
use ACP\Search\QueryFactory;
use ACP\Search\TableScreenFactory;
use ACP\Service\IntegrationStatus;
use GFAPI;
use GFCommon;
final class GravityForms implements Registerable {
const GROUP = 'gravity_forms';
private $location;
public function __construct( AC\Asset\Location\Absolute $location ) {
$this->location = $location;
}
/**
* Register hooks
*/
public function register() {
if ( ! class_exists( 'GFCommon', false ) ) {
return;
}
$minimum_gf_version = '2.5';
if ( class_exists( 'GFCommon', false ) && version_compare( GFCommon::$version, $minimum_gf_version, '<' ) ) {
return;
}
add_action( 'ac/list_screens', [ $this, 'register_list_screen' ] );
// Group labels
add_action( 'ac/column_groups', [ $this, 'register_column_group' ] );
add_action( 'ac/list_screen_groups', [ $this, 'register_list_screen_group' ] );
add_action( 'ac/admin_scripts', [ $this, 'admin_scripts' ] );
add_action( 'ac/table_scripts', [ $this, 'table_scripts' ] );
add_filter( "gform_noconflict_styles", [ $this, 'allowed_acp_styles' ] );
add_filter( "gform_noconflict_scripts", [ $this, 'allowed_acp_scripts' ] );
$services = [
new TableScreen\Entry(),
new Admin(),
new IntegrationStatus( 'ac-addon-gravityforms' ),
];
array_map( function ( Registerable $service ) {
$service->register();
}, $services );
// Enable Search
QueryFactory::register( MetaTypes::GRAVITY_FORMS_ENTRY, Query::class );
TableScreenFactory::register( ListScreen\Entry::class, Search\TableScreen\Entry::class );
}
public function register_list_screen() {
$list_screen_types = AC\ListScreenTypes::instance();
if ( ! $list_screen_types ) {
return;
}
$forms = array_merge( GFAPI::get_forms(), GFAPI::get_forms( [ 'active' => false ] ) );
foreach ( $forms as $form ) {
$fieldFactory = new FieldFactory();
$columnFactory = new EntryFactory( new FieldFactory() );
$configurator = new EntryConfigurator( (int) $form['id'], $columnFactory, $fieldFactory );
$configurator->register();
$list_screen_types->register_list_screen( new ListScreen\Entry( $form['id'], $configurator ) );
}
}
public function register_list_screen_group( AC\Groups $groups ) {
$groups->register_group( self::GROUP, __( 'Gravity Forms', 'codepress-admin-columns' ), 8 );
}
public function register_column_group( $groups ) {
$groups->register_group( self::GROUP, __( 'Gravity Forms', 'codepress-admin-columns' ), 11 );
}
/**
* @param string $key
*
* @return bool
*/
private function is_acp_asset( $key ) {
$acp_prefixes = [ 'ac-', 'acp-', 'aca-', 'editor', 'mce-view', 'quicktags', 'common', 'tinymce' ];
foreach ( $acp_prefixes as $prefix ) {
if ( strpos( $key, $prefix ) !== false ) {
return true;
}
}
return false;
}
/**
* @param array $objects
*
* @return array
*/
public function allowed_acp_styles( $objects ) {
global $wp_styles;
foreach ( $wp_styles->queue as $handle ) {
if ( ! $this->is_acp_asset( $handle ) ) {
continue;
}
$objects[] = $handle;
}
return $objects;
}
/**
* @param array $objects
*
* @return array
*/
public function allowed_acp_scripts( $objects ) {
global $wp_scripts;
foreach ( $wp_scripts->queue as $handle ) {
if ( ! $this->is_acp_asset( $handle ) ) {
continue;
}
$objects[] = $handle;
}
return $objects;
}
public function admin_scripts() {
wp_enqueue_style( 'gform_font_awesome' );
}
public function table_scripts() {
$style = new Style( 'aca-gf-table', $this->location->with_suffix( 'assets/css/table.css' ) );
$style->enqueue();
$script = new Script( 'aca-gf-table', $this->location->with_suffix( 'assets/js/table.js' ) );
$script->enqueue();
wp_enqueue_script( 'wp-tinymce' );
}
}