PluginProbe
Edit Flow / 0.9.2
Edit Flow v0.9.2
0.11.1 0.11.0 0.7.2 0.7.3 0.7.4 0.7.5 0.7.6 0.8 0.8.1 0.8.2 0.9 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 trunk 0.1.5 0.10.0 0.10.1 0.10.2 All 44 releases
← All changes | common/php/class-module.php +171 -145 0.7.50.9.2 View file →
@@ -5,12 +5,38 @@
5 5 * @desc Base class any Edit Flow module should extend
6 6 */
7 7
8 8 if ( !class_exists( 'EF_Module' ) ) {
9 -
9 +
10 10 class EF_Module {
11 -
12 - function __construct() {
11 +
12 + public $published_statuses = array(
13 + 'publish',
14 + 'future',
15 + 'private',
16 + );
17 +
18 + /**
19 + * Associative array of hook_name => callback_name
20 + * This is used for Gutenberg-compat initialization
21 + * [
22 + * 'init' => 'init_callback_on_module_instance'
23 + * ]
24 + * @var array
25 + */
26 + protected $compat_hooks = [];
27 +
28 + function __construct() {}
29 +
30 + /**
31 + * Returns whether the current module is enabled.
32 + *
33 + * @since 0.9.1
34 + *
35 + * @return <code>true</code> if the module is enabled, <code>false</code> otherwise
36 + */
37 + public function is_enabled() {
38 + return $this->module->options->enabled === 'on';
13 39 }
14 40
15 41 /**
16 42 * Returns whether the module with the given name is enabled.
@@ -22,12 +48,31 @@
22 48 */
23 49 function module_enabled( $slug ) {
24 50 global $edit_flow;
25 51
26 - return isset( $edit_flow->$slug ) && $edit_flow->$slug->module->options->enabled == 'on';
52 + return isset( $edit_flow->$slug ) && $edit_flow->$slug->is_enabled();
27 53 }
28 54
29 55 /**
56 + * Gets an array of allowed post types for a module
57 + *
58 + * @return array post-type-slug => post-type-label
59 + */
60 + function get_all_post_types() {
61 +
62 + $allowed_post_types = array(
63 + 'post' => __( 'Post' ),
64 + 'page' => __( 'Page' ),
65 + );
66 + $custom_post_types = $this->get_supported_post_types_for_module();
67 +
68 + foreach( $custom_post_types as $custom_post_type => $args ) {
69 + $allowed_post_types[$custom_post_type] = $args->label;
70 + }
71 + return $allowed_post_types;
72 + }
73 +
74 + /**
30 75 * Cleans up the 'on' and 'off' for post types on a given module (so we don't get warnings all over)
31 76 * For every post type that doesn't explicitly have the 'on' value, turn it 'off'
32 77 * If add_post_type_support() has been used anywhere (legacy support), inherit the state
33 78 *
@@ -38,11 +83,9 @@
38 83 * @since 0.7
39 84 */
40 85 function clean_post_type_options( $module_post_types = array(), $post_type_support = null ) {
41 86 $normalized_post_type_options = array();
42 - $all_post_types = wp_list_pluck( $this->get_supported_post_types_for_module(), 'name' );
43 - array_push( $all_post_types, 'post', 'page' );
44 - $all_post_types = array_merge( $all_post_types, array_keys( $module_post_types ) );
87 + $all_post_types = array_keys( $this->get_all_post_types() );
45 88 foreach( $all_post_types as $post_type ) {
46 89 if ( ( isset( $module_post_types[$post_type] ) && $module_post_types[$post_type] == 'on' ) || post_type_supports( $post_type, $post_type_support ) )
47 90 $normalized_post_type_options[$post_type] = 'on';
48 91 else
@@ -67,9 +110,9 @@
67 110 );
68 111 $pt_args = apply_filters( 'edit_flow_supported_module_post_types_args', $pt_args, $module );
69 112 return get_post_types( $pt_args, 'objects' );
70 113 }
71 -
114 +
72 115 /**
73 116 * Collect all of the active post types for a given module
74 117 *
75 118 * @param object $module Module's data
@@ -77,9 +120,9 @@
77 120 *
78 121 * @since 0.7
79 122 */
80 123 function get_post_types_for_module( $module ) {
81 -
124 +
82 125 $post_types = array();
83 126 if ( isset( $module->options->post_types ) && is_array( $module->options->post_types ) ) {
84 127 foreach( $module->options->post_types as $post_type => $value )
85 128 if ( 'on' == $value )
@@ -86,9 +129,9 @@
86 129 $post_types[] = $post_type;
87 130 }
88 131 return $post_types;
89 132 }
90 -
133 +
91 134 /**
92 135 * Get all of the currently available post statuses
93 136 * This should be used in favor of calling $edit_flow->custom_status->get_custom_statuses() directly
94 137 *
@@ -97,29 +140,60 @@
97 140 * @since 0.7
98 141 */
99 142 function get_post_statuses() {
100 143 global $edit_flow;
101 -
144 +
102 145 if ( $this->module_enabled('custom_status') ) {
103 146 return $edit_flow->custom_status->get_custom_statuses();
104 147 } else {
105 - $post_statuses = array(
148 + return $this->get_core_post_statuses();
149 + }
150 + }
151 +
152 + /**
153 + * Get core's 'draft' and 'pending' post statuses, but include our special attributes
154 + *
155 + * @since 0.8.1
156 + *
157 + * @return array
158 + */
159 + protected function get_core_post_statuses() {
160 +
161 + return array(
106 162 (object)array(
107 - 'name' => __( 'Draft' ),
108 - 'description' => '',
109 - 'slug' => 'draft',
163 + 'name' => __( 'Draft' ),
164 + 'description' => '',
165 + 'slug' => 'draft',
166 + 'position' => 1,
110 167 ),
111 168 (object)array(
112 - 'name' => __( 'Pending Review' ),
113 - 'description' => '',
114 - 'slug' => 'pending',
115 - ),
169 + 'name' => __( 'Pending Review' ),
170 + 'description' => '',
171 + 'slug' => 'pending',
172 + 'position' => 2,
173 + ),
116 174 );
117 - return $post_statuses;
118 - }
119 175 }
120 176
121 177 /**
178 + * Gets the name of the default custom status. If custom statuses are disabled,
179 + * returns 'draft'.
180 + *
181 + * @return str Name of the status
182 + */
183 + function get_default_post_status(){
184 +
185 + // Check if custom status module is enabled
186 + $custom_status_module = EditFlow()->custom_status->module->options;
187 +
188 + if( $custom_status_module->enabled == 'on' )
189 + return $custom_status_module->default_status;
190 + else
191 + return 'draft';
192 +
193 + }
194 +
195 + /**
122 196 * Filter to all posts with a given post status (can be a custom status or a built-in status) and optional custom post type.
123 197 *
124 198 * @since 0.7
125 199 *
@@ -132,63 +206,30 @@
132 206 if ( $post_type != 'post' && in_array( $post_type, get_post_types( '', 'names' ) ) )
133 207 $filter_link = add_query_arg( 'post_type', $post_type, $filter_link );
134 208 return $filter_link;
135 209 }
136 -
210 +
137 211 /**
138 - * Returns the friendly name for a given status
139 - *
140 - * @since 0.7
141 - *
142 - * @param string $status The status slug
143 - * @return string $status_friendly_name The friendly name for the status
144 - */
145 - function get_post_status_friendly_name( $status ) {
146 - global $edit_flow;
147 -
148 - $status_friendly_name = '';
149 -
150 - $builtin_stati = array(
151 - 'publish' => __( 'Published', 'edit-flow' ),
152 - 'draft' => __( 'Draft', 'edit-flow' ),
153 - 'future' => __( 'Scheduled', 'edit-flow' ),
154 - 'private' => __( 'Private', 'edit-flow' ),
155 - 'pending' => __( 'Pending Review', 'edit-flow' ),
156 - 'trash' => __( 'Trash', 'edit-flow' ),
157 - );
158 -
159 - // Custom statuses only handles workflow statuses
160 - if ( $this->module_enabled( 'custom_status' )
161 - && !in_array( $status, array( 'publish', 'future', 'private', 'trash' ) ) ) {
162 - $status_object = $edit_flow->custom_status->get_custom_status_by( 'slug', $status );
163 - if( $status_object && !is_wp_error( $status_object ) ) {
164 - $status_friendly_name = $status_object->name;
165 - }
166 - } else if ( array_key_exists( $status, $builtin_stati ) ) {
167 - $status_friendly_name = $builtin_stati[$status];
168 - }
169 - return $status_friendly_name;
170 - }
171 -
172 - /**
173 212 * Enqueue any resources (CSS or JS) associated with datepicker functionality
174 213 *
175 214 * @since 0.7
176 215 */
177 216 function enqueue_datepicker_resources() {
178 -
217 +
179 218 // Add the first day of the week as an available variable to wp_head
180 - echo "<script type=\"text/javascript\">var ef_week_first_day=\"" . get_option( 'start_of_week' ) . "\";</script>";
219 + echo "<script type=\"text/javascript\">var ef_week_first_day=\"" . get_option( 'start_of_week' ) . "\";</script>";
181 220
182 - // Datepicker is available WordPress 3.3. We have to register it ourselves for previous versions of WordPress
183 221 wp_enqueue_script( 'jquery-ui-datepicker' );
184 - wp_enqueue_script( 'edit_flow-date_picker', EDIT_FLOW_URL . 'common/js/ef_date.js', array( 'jquery', 'jquery-ui-datepicker' ), EDIT_FLOW_VERSION, true );
185 222
223 + //Timepicker needs to come after jquery-ui-datepicker and jquery
224 + wp_enqueue_script( 'edit_flow-timepicker', EDIT_FLOW_URL . 'common/js/jquery-ui-timepicker-addon.js', array( 'jquery', 'jquery-ui-datepicker' ), EDIT_FLOW_VERSION, true );
225 + wp_enqueue_script( 'edit_flow-date_picker', EDIT_FLOW_URL . 'common/js/ef_date.js', array( 'jquery', 'jquery-ui-datepicker', 'edit_flow-timepicker' ), EDIT_FLOW_VERSION, true );
226 +
186 227 // Now styles
187 228 wp_enqueue_style( 'jquery-ui-datepicker', EDIT_FLOW_URL . 'common/css/jquery.ui.datepicker.css', array( 'wp-jquery-ui-dialog' ), EDIT_FLOW_VERSION, 'screen' );
188 229 wp_enqueue_style( 'jquery-ui-theme', EDIT_FLOW_URL . 'common/css/jquery.ui.theme.css', false, EDIT_FLOW_VERSION, 'screen' );
189 230 }
190 -
231 +
191 232 /**
192 233 * Checks for the current post type
193 234 *
194 235 * @since 0.7
@@ -195,29 +236,32 @@
195 236 * @return string|null $post_type The post type we've found, or null if no post type
196 237 */
197 238 function get_current_post_type() {
198 239 global $post, $typenow, $pagenow, $current_screen;
240 + //get_post() needs a variable
241 + $post_id = isset( $_REQUEST['post'] ) ? (int)$_REQUEST['post'] : false;
199 242
200 - if ( $post && $post->post_type )
243 + if ( $post && $post->post_type ) {
201 244 $post_type = $post->post_type;
202 - elseif ( $typenow )
245 + } elseif ( $typenow ) {
203 246 $post_type = $typenow;
204 - elseif ( $current_screen && isset( $current_screen->post_type ) )
247 + } elseif ( $current_screen && !empty( $current_screen->post_type ) ) {
205 248 $post_type = $current_screen->post_type;
206 - elseif ( isset( $_REQUEST['post_type'] ) )
249 + } elseif ( isset( $_REQUEST['post_type'] ) ) {
207 250 $post_type = sanitize_key( $_REQUEST['post_type'] );
208 - elseif ( 'post.php' == $pagenow
209 - && isset( $_REQUEST['post'] )
210 - && ! empty( get_post( (int)$_REQUEST['post'] )->post_type ) )
211 - $post_type = get_post( (int)$_REQUEST['post'] )->post_type;
212 - elseif ( 'edit.php' == $pagenow && empty( $_REQUEST['post_type'] ) )
251 + } elseif ( 'post.php' == $pagenow
252 + && $post_id
253 + && !empty( get_post( $post_id )->post_type ) ) {
254 + $post_type = get_post( $post_id )->post_type;
255 + } elseif ( 'edit.php' == $pagenow && empty( $_REQUEST['post_type'] ) ) {
213 256 $post_type = 'post';
214 - else
257 + } else {
215 258 $post_type = null;
259 + }
216 260
217 261 return $post_type;
218 262 }
219 -
263 +
220 264 /**
221 265 * Wrapper for the get_user_meta() function so we can replace it if we need to
222 266 *
223 267 * @since 0.7
@@ -227,18 +271,18 @@
227 271 * @param bool $single Whether or not to return just one value
228 272 * @return string|bool|array $value Whatever the stored value was
229 273 */
230 274 function get_user_meta( $user_id, $key, $string = true ) {
231 -
275 +
232 276 $response = null;
233 277 $response = apply_filters( 'ef_get_user_meta', $response, $user_id, $key, $string );
234 278 if ( !is_null( $response ) )
235 279 return $response;
236 -
280 +
237 281 return get_user_meta( $user_id, $key, $string );
238 -
282 +
239 283 }
240 -
284 +
241 285 /**
242 286 * Wrapper for the update_user_meta() function so we can replace it if we need to
243 287 *
244 288 * @since 0.7
@@ -249,18 +293,18 @@
249 293 * @param string|bool|array $previous (optional) Previous value to replace
250 294 * @return bool $success Whether we were successful in saving
251 295 */
252 296 function update_user_meta( $user_id, $key, $value, $previous = null ) {
253 -
297 +
254 298 $response = null;
255 299 $response = apply_filters( 'ef_update_user_meta', $response, $user_id, $key, $value, $previous );
256 300 if ( !is_null( $response ) )
257 301 return $response;
258 -
302 +
259 303 return update_user_meta( $user_id, $key, $value, $previous );
260 -
261 - }
262 -
304 +
305 + }
306 +
263 307 /**
264 308 * Take a status and a message, JSON encode and print
265 309 *
266 310 * @since 0.7
@@ -271,9 +315,9 @@
271 315 header( 'Content-type: application/json;' );
272 316 echo json_encode( array( 'status' => $status, 'message' => $message ) );
273 317 exit;
274 318 }
275 -
319 +
276 320 /**
277 321 * Whether or not the current page is a user-facing Edit Flow View
278 322 * @todo Think of a creative way to make this work
279 323 *
@@ -281,14 +325,14 @@
281 325 *
282 326 * @param string $module_name (Optional) Module name to check against
283 327 */
284 328 function is_whitelisted_functional_view( $module_name = null ) {
285 -
329 +
286 330 // @todo complete this method
287 -
331 +
288 332 return true;
289 333 }
290 -
334 +
291 335 /**
292 336 * Whether or not the current page is an Edit Flow settings view (either main or module)
293 337 * Determination is based on $pagenow, $_GET['page'], and the module's $settings_slug
294 338 * If there's no module name specified, it will return true against all Edit Flow settings views
@@ -299,66 +343,30 @@
299 343 * @return bool $is_settings_view Return true if it is
300 344 */
301 345 function is_whitelisted_settings_view( $module_name = null ) {
302 346 global $pagenow, $edit_flow;
303 -
347 +
304 348 // All of the settings views are based on admin.php and a $_GET['page'] parameter
305 349 if ( $pagenow != 'admin.php' || !isset( $_GET['page'] ) )
306 350 return false;
307 -
351 +
308 352 // Load all of the modules that have a settings slug/ callback for the settings page
309 353 foreach ( $edit_flow->modules as $mod_name => $mod_data ) {
310 354 if ( isset( $mod_data->options->enabled ) && $mod_data->options->enabled == 'on' && $mod_data->configure_page_cb )
311 355 $settings_view_slugs[] = $mod_data->settings_slug;
312 356 }
313 -
357 +
314 358 // The current page better be in the array of registered settings view slugs
315 359 if ( !in_array( $_GET['page'], $settings_view_slugs ) )
316 360 return false;
317 -
361 +
318 362 if ( $module_name && $edit_flow->modules->$module_name->settings_slug != $_GET['page'] )
319 363 return false;
320 -
364 +
321 365 return true;
322 366 }
323 -
324 - /**
325 - * Remove term(s) associated with a given object(s). Core doesn't have this as of 3.2
326 - * @see http://core.trac.wordpress.org/ticket/15475
327 - *
328 - * @author ericmann
329 - * @compat 3.3?
330 - *
331 - * @param int|array $object_ids The ID(s) of the object(s) to retrieve.
332 - * @param int|array $terms The ids of the terms to remove.
333 - * @param string|array $taxonomies The taxonomies to retrieve terms from.
334 - * @return bool|WP_Error Affected Term IDs
335 - */
336 - function remove_object_terms( $object_id, $terms, $taxonomy ) {
337 - global $wpdb;
338 367
339 - if ( !taxonomy_exists( $taxonomy ) )
340 - return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) );
341 368
342 - if ( !is_array( $object_id ) )
343 - $object_id = array( $object_id );
344 -
345 - if ( !is_array($terms) )
346 - $terms = array( $terms );
347 -
348 - $delete_objects = array_map( 'intval', $object_id );
349 - $delete_terms = array_map( 'intval', $terms );
350 -
351 - if ( $delete_terms ) {
352 - $in_delete_terms = "'" . implode( "', '", $delete_terms ) . "'";
353 - $in_delete_objects = "'" . implode( "', '", $delete_objects ) . "'";
354 - $return = $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_relationships WHERE object_id IN ($in_delete_objects) AND term_taxonomy_id IN ($in_delete_terms)", $object_id ) );
355 - wp_update_term_count( $delete_terms, $taxonomy );
356 - return true;
357 - }
358 - return false;
359 - }
360 -
361 369 /**
362 370 * This is a hack, Hack, HACK!!!
363 371 * Encode all of the given arguments as a serialized array, and then base64_encode
364 372 * Used to store extra data in a term's description field
@@ -370,9 +378,9 @@
370 378 */
371 379 function get_encoded_description( $args = array() ) {
372 380 return base64_encode( maybe_serialize( $args ) );
373 381 }
374 -
382 +
375 383 /**
376 384 * If given an encoded string from a term's description field,
377 385 * return an array of values. Otherwise, return the original string
378 386 *
@@ -383,9 +391,9 @@
383 391 */
384 392 function get_unencoded_description( $string_to_unencode ) {
385 393 return maybe_unserialize( base64_decode( $string_to_unencode ) );
386 394 }
387 -
395 +
388 396 /**
389 397 * Get the publicly accessible URL for the module based on the filename
390 398 *
391 399 * @since 0.7
@@ -396,9 +404,9 @@
396 404 function get_module_url( $file ) {
397 405 $module_url = plugins_url( '/', $file );
398 406 return trailingslashit( $module_url );
399 407 }
400 -
408 +
401 409 /**
402 410 * Produce a human-readable version of the time since a timestamp
403 411 *
404 412 * @param int $original The UNIX timestamp we're producing a relative time for
@@ -442,9 +450,9 @@
442 450 }
443 451
444 452 return sprintf( _n( "1 $name ago", "$count ${name}s ago", $count), $count);
445 453 }
446 -
454 +
447 455 /**
448 456 * Displays a list of users that can be selected!
449 457 *
450 458 * @since 0.7
@@ -457,9 +465,9 @@
457 465 function users_select_form( $selected = null, $args = null ) {
458 466
459 467 // Set up arguments
460 468 $defaults = array(
461 - 'list_class' => 'ef-users-select-form',
469 + 'list_class' => 'ef-users-select-form',
462 470 'input_id' => 'ef-selected-users'
463 471 );
464 472 $parsed_args = wp_parse_args( $args, $defaults );
465 473 extract($parsed_args, EXTR_SKIP);
@@ -473,8 +481,9 @@
473 481 ),
474 482 'orderby' => 'display_name',
475 483 );
476 484 $args = apply_filters( 'ef_users_select_form_get_users_args', $args );
485 +
477 486 $users = get_users( $args );
478 487
479 488 if ( !is_array($selected) ) $selected = array();
480 489 ?>
@@ -480,13 +489,20 @@
480 489 ?>
481 490
482 491 <?php if( !empty($users) ) : ?>
483 492 <ul class="<?php echo esc_attr( $list_class ) ?>">
484 - <?php foreach( $users as $user ) : ?>
485 - <?php $checked = ( in_array($user->ID, $selected) ) ? 'checked="checked"' : ''; ?>
493 + <?php foreach( $users as $user ) :
494 + $checked = ( in_array($user->ID, $selected) ) ? 'checked="checked"' : '';
495 + // Add a class to checkbox of current user so we know not to add them in notified list during notifiedMessage() js function
496 + $current_user_class = ( get_current_user_id() == $user->ID ) ? 'class="post_following_list-current_user" ' : '';
497 + ?>
486 498 <li>
487 499 <label for="<?php echo esc_attr( $input_id .'-'. $user->ID ) ?>">
488 - <input type="checkbox" id="<?php echo esc_attr( $input_id .'-'. $user->ID ) ?>" name="<?php echo esc_attr( $input_id ) ?>[]" value="<?php echo esc_attr( $user->ID ); ?>" <?php echo $checked; ?> />
500 + <div class="ef-user-subscribe-actions">
501 + <?php do_action( 'ef_user_subscribe_actions', $user->ID, $checked ) ?>
502 + <input type="checkbox" id="<?php echo esc_attr( $input_id .'-'. $user->ID ) ?>" name="<?php echo esc_attr( $input_id ) ?>[]" value="<?php echo esc_attr( $user->ID ); ?>" <?php echo $checked; echo $current_user_class; ?> />
503 + </div>
504 +
489 505 <span class="ef-user_displayname"><?php echo esc_html( $user->display_name ); ?></span>
490 506 <span class="ef-user_useremail"><?php echo esc_html( $user->user_email ); ?></span>
491 507 </label>
492 508 </li>
@@ -510,13 +526,14 @@
510 526 if ( apply_filters( 'ef_kill_add_caps_to_role', false, $role, $caps ) )
511 527 return;
512 528
513 529 global $wp_roles;
514 -
530 +
515 531 if ( $wp_roles->is_role( $role ) ) {
516 - $role =& get_role( $role );
517 - foreach ( $caps as $cap )
532 + $role = get_role( $role );
533 + foreach ( $caps as $cap ) {
518 534 $role->add_cap( $cap );
535 + }
519 536 }
520 537 }
521 538
522 539 /**
@@ -525,21 +542,21 @@
525 542 *
526 543 * @since 0.7
527 544 */
528 545 function action_settings_help_menu() {
529 -
546 +
530 547 $screen = get_current_screen();
531 -
532 - if ( !method_exists( $screen, 'add_help_tab' ) )
548 +
549 + if ( !method_exists( $screen, 'add_help_tab' ) )
533 550 return;
534 -
535 - if ( $screen->id != 'edit-flow_page_' . $this->module->settings_slug )
551 +
552 + if ( $screen->id != 'edit-flow_page_' . $this->module->settings_slug )
536 553 return;
537 554
538 555 // Make sure we have all of the required values for our tab
539 556 if ( isset( $this->module->settings_help_tab['id'], $this->module->settings_help_tab['title'], $this->module->settings_help_tab['content'] ) ) {
540 557 $screen->add_help_tab( $this->module->settings_help_tab );
541 -
558 +
542 559 if ( isset( $this->module->settings_help_sidebar ) ) {
543 560 $screen->set_help_sidebar( $this->module->settings_help_sidebar );
544 561 }
545 562 }
@@ -580,7 +597,16 @@
580 597 $new_description = $this->get_encoded_description( $description_args );
581 598 wp_update_term( $term->term_id, $taxonomy, array( 'description' => $new_description ) );
582 599 }
583 600 }
584 -
601 +
602 + /**
603 + * Return compatibility hooks for the current instance
604 + *
605 + * @return array
606 + */
607 + function get_compat_hooks() {
608 + return isset( $this->compat_hooks ) && is_array( $this->compat_hooks ) ? $this->compat_hooks : [];
609 + }
610 +
585 611 }
586 612 }