This repository has been archived by the owner on Jun 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mercury.php
executable file
·146 lines (128 loc) · 3.49 KB
/
mercury.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
145
<?php
/**
* Plugin Name: Mercury
* Plugin URI: https://github.com/alleyinteractive/mercury
* Description: Advanced editorial workflows.
* Author: Alley, jameswalterburke
* Author URI: https://alley.co
* Text Domain: mercury
* Domain Path: /languages
* Version: 1.1.14
*
* @package Mercury
*/
namespace Mercury;
/**
* Current version of Mercury.
*/
define( 'MERCURY_VERSION', '1.1.14' );
/**
* Filesystem path to Mercury.
*/
define( 'MERCURY_PATH', dirname( __FILE__ ) );
// Traits.
require_once MERCURY_PATH . '/inc/traits/trait-table-helpers.php';
// Base functionality.
require_once MERCURY_PATH . '/inc/class-assignments.php';
require_once MERCURY_PATH . '/inc/class-endpoints.php';
require_once MERCURY_PATH . '/inc/class-post-type.php';
require_once MERCURY_PATH . '/inc/class-users.php';
// GUI workflow management.
require_once MERCURY_PATH . '/inc/gui/class-assignments-table.php';
require_once MERCURY_PATH . '/inc/gui/class-group-assignments-queue.php';
require_once MERCURY_PATH . '/inc/gui/class-enabled-posts.php';
require_once MERCURY_PATH . '/inc/gui/class-settings.php';
require_once MERCURY_PATH . '/inc/gui/class-task.php';
require_once MERCURY_PATH . '/inc/gui/class-workflow.php';
// Helpers.
require_once MERCURY_PATH . '/inc/helpers.php';
// Init.
add_action(
'init',
function() {
new Assignments();
new Endpoints();
new Post_Type();
// GUI for managing workflows.
new GUI\Settings();
new GUI\Task();
new GUI\Enabled_Posts();
new GUI\Workflow();
},
15
);
/**
* Get post types for which Mercury is enabled.
*
* @return array
*/
function get_mercury_post_types() {
$settings = get_option( 'mercury', [] );
return $settings['post_types']['post_types'] ?? [ 'post' ];
}
/**
* Add custom query var for webpack hot-reloading.
*
* @param array $vars Array of current query vars.
* @return array $vars Array of query vars.
*/
function webpack_query_vars( $vars ) {
// Add a query var to enable hot reloading.
$vars[] = 'mercury-dev';
return $vars;
}
add_filter( 'query_vars', __NAMESPACE__ . '\webpack_query_vars' );
/**
* Enqueue admin scripts.
*/
function enqueue_scripts() {
global $post;
$screen = get_current_screen();
// Bail if this isn't the edit screen of an enabled post type.
if (
! in_array( $post->post_type ?? '', get_mercury_post_types(), true ) ||
'post' !== ( $screen->base ?? '' )
) {
return;
}
if (
( ! empty( $_GET['mercury-dev'] ) && true === $_GET['mercury-dev'] ) ||
( defined( 'MERCURY_DEBUG' ) && true === MERCURY_DEBUG )
) {
wp_enqueue_script(
'mercury-workflow-js',
'https://localhost:8080/build/js/workflow.js',
[ 'wp-api-fetch' ],
MERCURY_VERSION,
true
);
} else {
wp_enqueue_script(
'mercury-workflow-js',
plugins_url( '/build/js/workflow.js', __FILE__ ),
[ 'wp-api-fetch' ],
MERCURY_VERSION,
true
);
}
// Localize any settings configured in WP.
$settings = get_option( 'mercury', [] );
$colors = $settings['colors'] ?? [];
wp_localize_script(
'mercury-workflow-js',
'mercurySettings',
[
'colors' => [
'primary' => $colors['primary'] ?? false,
'primaryDark' => $colors['primary_dark'] ?? false,
'secondary' => $colors['secondary'] ?? false,
],
// phpcs:disable
// Note: this can be removed in WP 5.3, and replaced with
// `wp.data.select('core').getCurrentUser()`
// phpcs:enable
'currentUser' => wp_get_current_user(),
]
);
}
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\enqueue_scripts' );