PluginProbe
UpStream: a Project Management Plugin for WordPress / trunk
UpStream: a Project Management Plugin for WordPress vtrunk
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / includes / admin / up-enqueues.php

up-enqueues.php in UpStream: a Project Management Plugin for WordPress trunk, at includes/admin/up-enqueues.php

269 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle admin scripts and styles enqueues
4 *
5 * @package UpStream
6 */
7
8 // Exit if accessed directly.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Enqueues the required admin scripts.
15 *
16 * @param mixed $hook Hook.
17 * @return void
18 */
19 function upstream_load_admin_scripts( $hook ) {
20 $is_admin = is_admin();
21 if ( ! $is_admin ) {
22 return;
23 }
24
25 $get_data = isset( $_GET ) ? wp_unslash( $_GET ) : array();
26
27 $post_type = get_post_type();
28 if ( empty( $post_type ) ) {
29 // checked later if in array of valid post types.
30 $post_type = isset( $get_data['post_type'] ) ? sanitize_text_field( $get_data['post_type'] ) : '';
31 }
32
33 $assets_dir = UPSTREAM_PLUGIN_URL . 'includes/admin/assets/';
34 $global_assets_path = UPSTREAM_PLUGIN_URL . 'templates/assets/';
35 $admin_deps = array( 'jquery', 'cmb2-scripts', 'allex', 'jquery-ui-datepicker' );
36
37 global $pagenow;
38
39 wp_enqueue_style( 'wp-color-picker' );
40
41 wp_enqueue_script( 'jquery-ui-datepicker' );
42 wp_enqueue_style(
43 'jquery-ui-datepicker',
44 $assets_dir . '/css/jquery.ui.datepicker.css',
45 array( 'wp-jquery-ui-dialog' ),
46 UPSTREAM_VERSION,
47 'screen'
48 );
49 wp_enqueue_style(
50 'jquery-ui-theme',
51 $assets_dir . '/css/jquery.ui.theme.css',
52 false,
53 UPSTREAM_VERSION,
54 'screen'
55 );
56
57 wp_enqueue_script(
58 'terminal',
59 $assets_dir . 'js/jquery.terminal.min.js',
60 array( 'jquery' ),
61 UPSTREAM_VERSION,
62 false
63 );
64
65 wp_enqueue_script(
66 'upstream-admin',
67 $assets_dir . 'js/admin.js',
68 array( 'jquery', 'wp-color-picker', 'allex', 'terminal' ),
69 UPSTREAM_VERSION,
70 false
71 );
72
73 wp_localize_script(
74 'upstream-admin',
75 'upstreamAdmin',
76 array(
77 'LB_RESETTING' => __( 'Resetting...', 'upstream' ),
78 'LB_REFRESHING' => __( 'Refreshing...', 'upstream' ),
79 'MSG_CONFIRM_RESET_CAPABILITIES' => __( 'Are you sure you want to reset the capabilities?', 'upstream' ),
80 'MSG_CONFIRM_REFRESH_PROJECTS_META' => __(
81 'Are you sure you want to refresh the projects meta data?',
82 'upstream'
83 ),
84 'MSG_CONFIRM_CLEANUP_UPDATE_CACHE' => __(
85 'Are you sure you want to cleanup the cached data about updates?',
86 'upstream'
87 ),
88 'MSG_CONFIRM_IMPORT' => __( 'Are you sure you want to perform an import? MAKE SURE YOU HAVE BACKED UP YOUR DATA FIRST!', 'upstream' ),
89 'MSG_CAPABILITIES_RESETED' => __( 'Success!', 'upstream' ),
90 'MSG_CAPABILITIES_ERROR' => __( 'Error!', 'upstream' ),
91 'MSG_PROJECTS_SUCCESS' => __( 'Success!', 'upstream' ),
92 'MSG_PROJECTS_META_ERROR' => __( 'Error!', 'upstream' ),
93 'MSG_CLEANUP_UPDATE_DATA_ERROR' => __( 'Error cleaning up the cached data!', 'upstream' ),
94 'MSG_IMPORT_ERROR' => __( 'Error importing data!', 'upstream' ),
95 'datepickerDateFormat' => upstream_get_date_format_for_js_datepicker(),
96 )
97 );
98
99 if ( in_array( $pagenow, array( 'edit.php', 'post.php', 'post-new.php' ), true ) ) {
100
101 $milestone_instance = \UpStream\Milestones::getInstance();
102 $milestone_post_type = $milestone_instance->get_post_type();
103 $valid_post_types = apply_filters( 'upstream_admin_script_valid_post_types', array( 'project', 'upst_milestone' ) );
104
105 wp_enqueue_style(
106 'up-select2',
107 $global_assets_path . 'css/vendor/select2.min.css',
108 array(),
109 UPSTREAM_VERSION,
110 'all'
111 );
112 wp_enqueue_script(
113 'up-select2',
114 $global_assets_path . 'js/vendor/select2.full.min.js',
115 array(),
116 UPSTREAM_VERSION,
117 true
118 );
119 unset( $global_assets_path );
120
121 if ( in_array( $post_type, $valid_post_types, true ) ) {
122 global $post_type_object;
123
124 wp_register_script(
125 'upstream-project',
126 $assets_dir . 'js/edit-project.js',
127 array_merge( $admin_deps, array( 'up-select2' ) ),
128 UPSTREAM_VERSION,
129 false
130 );
131
132 wp_enqueue_script( 'upstream-project' );
133 wp_localize_script(
134 'upstream-project',
135 'upstream_project',
136 apply_filters(
137 'upstream_project_script_vars',
138 array(
139 'version' => UPSTREAM_VERSION,
140 'user' => upstream_current_user_id(),
141 'slugBox' => ! ( get_post_status() === 'pending' && ! current_user_can( $post_type_object->cap->publish_posts ) ),
142 'l' => array(
143 'LB_CANCEL' => __( 'Cancel' ),
144 'LB_SEND_REPLY' => __( 'Add Reply', 'upstream' ),
145 'LB_REPLY' => __( 'Reply' ),
146 'LB_ADD_COMMENT' => __( 'Add Comment', 'upstream' ),
147 'LB_ADD_NEW_COMMENT' => __( 'Add new Comment' ),
148 'LB_ADD_NEW_REPLY' => __( 'Add Comment Reply', 'upstream' ),
149 'LB_ADDING' => __( 'Adding...', 'upstream' ),
150 'LB_REPLYING' => __( 'Replying...', 'upstream' ),
151 'LB_DELETE' => __( 'Delete', 'upstream' ),
152 'LB_DELETING' => __( 'Deleting...', 'upstream' ),
153 'LB_UNAPPROVE' => __( 'Unapprove' ),
154 'LB_UNAPPROVING' => __( 'Unapproving...', 'upstream' ),
155 'LB_APPROVE' => __( 'Approve', 'upstream' ),
156 'LB_APPROVING' => __( 'Approving...', 'upstream' ),
157 'MSG_ARE_YOU_SURE' => __(
158 'Are you sure? This action cannot be undone.',
159 'upstream'
160 ),
161 'MSG_COMMENT_NOT_VIS' => __(
162 'This comment is not visible by regular users.',
163 'upstream'
164 ),
165 'LB_ASSIGNED_TO' => __( 'Assigned To', 'upstream' ),
166 'MSG_TITLE_CANT_BE_EMPTY' => __( 'Title can\'t be empty', 'upstream' ),
167 'MSG_INVALID_INTERVAL_BETWEEN_DATE' => __( 'Invalid interval between dates.', 'upstream' ),
168 'MSG_NO_CLIENT_SELECTED' => __( 'No client selected', 'upstream' ),
169 'MSG_NO_RESULTS' => __( 'No results', 'upstream' ),
170 ),
171 )
172 )
173 );
174
175 if ( 'upst_milestone' === $post_type ) {
176 wp_enqueue_script(
177 'upstream-milestone',
178 $assets_dir . 'js/edit-milestone.js',
179 array( 'jquery', 'up-select2' ),
180 UPSTREAM_VERSION,
181 false
182 );
183 }
184 } elseif ( 'client' === $post_type ) {
185 wp_enqueue_script(
186 'up-metabox-client',
187 $assets_dir . 'js/metabox-client.js',
188 $admin_deps,
189 UPSTREAM_VERSION,
190 true
191 );
192 wp_localize_script(
193 'up-metabox-client',
194 'upstreamMetaboxClientLangStrings',
195 array(
196 'ERR_JQUERY_NOT_FOUND' => __( 'UpStream requires jQuery.', 'upstream' ),
197 'MSG_NO_ASSIGNED_USERS' => __( "There's no users assigned yet.", 'upstream' ),
198 'MSG_NO_USER_SELECTED' => __( 'Please, select at least one user', 'upstream' ),
199 'MSG_ADD_ONE_USER' => __( 'Add 1 User', 'upstream' ),
200 // translators: %d: user count.
201 'MSG_ADD_MULTIPLE_USERS' => __( 'Add %d Users', 'upstream' ),
202 'MSG_NO_USERS_FOUND' => __( 'No users found.', 'upstream' ),
203 'LB_ADDING_USERS' => __( 'Adding...', 'upstream' ),
204 'MSG_ARE_YOU_SURE' => __( 'Are you sure? This action cannot be undone.', 'upstream' ),
205 'MSG_FETCHING_DATA' => __( 'Fetching data...', 'upstream' ),
206 'MSG_NO_DATA_FOUND' => __( 'No data found.', 'upstream' ),
207 // translators: %s: user label.
208 'MSG_MANAGING_PERMISSIONS' => __( "Managing %s\'s Permissions", 'upstream' ),
209 )
210 );
211 } elseif ( $post_type === $milestone_post_type ) {
212 $global_assets_path = UPSTREAM_PLUGIN_URL . 'templates/assets/';
213 wp_enqueue_style(
214 'up-select2',
215 $global_assets_path . 'css/vendor/select2.min.css',
216 array(),
217 UPSTREAM_VERSION,
218 'all'
219 );
220 wp_enqueue_script(
221 'up-select2',
222 $global_assets_path . 'js/vendor/select2.full.min.js',
223 array(),
224 UPSTREAM_VERSION,
225 true
226 );
227 unset( $global_assets_path );
228 }
229
230 $milestone_instance = \UpStream\Milestones::getInstance();
231 $post_types_using_cmb2 = apply_filters(
232 'upstream:post_types_using_cmb2',
233 array( 'project', 'client', $milestone_instance->get_post_type() )
234 );
235
236 if ( in_array( $post_type, $post_types_using_cmb2 ) ) {
237 wp_enqueue_style( 'upstream-admin', $assets_dir . 'css/upstream.css', array(), UPSTREAM_VERSION );
238 }
239 } elseif ( 'admin.php' === $pagenow
240 && isset( $get_data['page'] )
241 && preg_match( '/^upstream_/i', sanitize_text_field( $get_data['page'] ) )
242 ) {
243 wp_enqueue_style( 'upstream-admin', $assets_dir . 'css/upstream.css', array(), UPSTREAM_VERSION );
244 }
245
246 wp_enqueue_style( 'terminal', $assets_dir . 'css/jquery.terminal.min.css', array(), UPSTREAM_VERSION );
247 wp_enqueue_style( 'upstream-admin-icon', $assets_dir . 'css/admin-upstream-icon.css', array(), UPSTREAM_VERSION );
248 wp_enqueue_style( 'upstream-admin-style', $assets_dir . 'css/admin.css', array( 'allex' ), UPSTREAM_VERSION );
249 wp_enqueue_style(
250 'up-fontawesome',
251 UPSTREAM_PLUGIN_URL . 'templates/assets/css/fontawesome.min.css',
252 array(),
253 UPSTREAM_VERSION,
254 'all'
255 );
256 }
257
258 add_action( 'admin_enqueue_scripts', 'upstream_load_admin_scripts', 100 );
259
260 add_filter(
261 'cmb2_script_dependencies',
262 function( $a ) {
263 $a['cmb2-wysiwyg'] = 'cmb2-wysiwyg';
264 return $a;
265 }
266 );
267
268 do_action( 'upstream_admin_enqueue' );
269