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 +98 -132 0.8.20.9.2 View file →
@@ -5,20 +5,41 @@
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 11
12 - var $published_statuses = array(
13 - 'publish',
14 - 'future',
15 - 'private',
16 - );
17 -
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 +
18 28 function __construct() {}
19 29
20 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';
39 + }
40 +
41 + /**
21 42 * Returns whether the module with the given name is enabled.
22 43 *
23 44 * @since 0.7
24 45 *
@@ -27,14 +48,14 @@
27 48 */
28 49 function module_enabled( $slug ) {
29 50 global $edit_flow;
30 51
31 - return isset( $edit_flow->$slug ) && $edit_flow->$slug->module->options->enabled == 'on';
52 + return isset( $edit_flow->$slug ) && $edit_flow->$slug->is_enabled();
32 53 }
33 54
34 55 /**
35 56 * Gets an array of allowed post types for a module
36 - *
57 + *
37 58 * @return array post-type-slug => post-type-label
38 59 */
39 60 function get_all_post_types() {
40 61
@@ -42,9 +63,9 @@
42 63 'post' => __( 'Post' ),
43 64 'page' => __( 'Page' ),
44 65 );
45 66 $custom_post_types = $this->get_supported_post_types_for_module();
46 -
67 +
47 68 foreach( $custom_post_types as $custom_post_type => $args ) {
48 69 $allowed_post_types[$custom_post_type] = $args->label;
49 70 }
50 71 return $allowed_post_types;
@@ -89,9 +110,9 @@
89 110 );
90 111 $pt_args = apply_filters( 'edit_flow_supported_module_post_types_args', $pt_args, $module );
91 112 return get_post_types( $pt_args, 'objects' );
92 113 }
93 -
114 +
94 115 /**
95 116 * Collect all of the active post types for a given module
96 117 *
97 118 * @param object $module Module's data
@@ -99,9 +120,9 @@
99 120 *
100 121 * @since 0.7
101 122 */
102 123 function get_post_types_for_module( $module ) {
103 -
124 +
104 125 $post_types = array();
105 126 if ( isset( $module->options->post_types ) && is_array( $module->options->post_types ) ) {
106 127 foreach( $module->options->post_types as $post_type => $value )
107 128 if ( 'on' == $value )
@@ -108,9 +129,9 @@
108 129 $post_types[] = $post_type;
109 130 }
110 131 return $post_types;
111 132 }
112 -
133 +
113 134 /**
114 135 * Get all of the currently available post statuses
115 136 * This should be used in favor of calling $edit_flow->custom_status->get_custom_statuses() directly
116 137 *
@@ -119,9 +140,9 @@
119 140 * @since 0.7
120 141 */
121 142 function get_post_statuses() {
122 143 global $edit_flow;
123 -
144 +
124 145 if ( $this->module_enabled('custom_status') ) {
125 146 return $edit_flow->custom_status->get_custom_statuses();
126 147 } else {
127 148 return $this->get_core_post_statuses();
@@ -129,15 +150,15 @@
129 150 }
130 151
131 152 /**
132 153 * Get core's 'draft' and 'pending' post statuses, but include our special attributes
133 - *
154 + *
134 155 * @since 0.8.1
135 - *
156 + *
136 157 * @return array
137 158 */
138 159 protected function get_core_post_statuses() {
139 -
160 +
140 161 return array(
141 162 (object)array(
142 163 'name' => __( 'Draft' ),
143 164 'description' => '',
@@ -148,9 +169,9 @@
148 169 'name' => __( 'Pending Review' ),
149 170 'description' => '',
150 171 'slug' => 'pending',
151 172 'position' => 2,
152 - ),
173 + ),
153 174 );
154 175 }
155 176
156 177 /**
@@ -155,9 +176,9 @@
155 176
156 177 /**
157 178 * Gets the name of the default custom status. If custom statuses are disabled,
158 179 * returns 'draft'.
159 - *
180 + *
160 181 * @return str Name of the status
161 182 */
162 183 function get_default_post_status(){
163 184
@@ -162,9 +183,9 @@
162 183 function get_default_post_status(){
163 184
164 185 // Check if custom status module is enabled
165 186 $custom_status_module = EditFlow()->custom_status->module->options;
166 -
187 +
167 188 if( $custom_status_module->enabled == 'on' )
168 189 return $custom_status_module->default_status;
169 190 else
170 191 return 'draft';
@@ -185,59 +206,23 @@
185 206 if ( $post_type != 'post' && in_array( $post_type, get_post_types( '', 'names' ) ) )
186 207 $filter_link = add_query_arg( 'post_type', $post_type, $filter_link );
187 208 return $filter_link;
188 209 }
189 -
210 +
190 211 /**
191 - * Returns the friendly name for a given status
192 - *
193 - * @since 0.7
194 - *
195 - * @param string $status The status slug
196 - * @return string $status_friendly_name The friendly name for the status
197 - */
198 - function get_post_status_friendly_name( $status ) {
199 - global $edit_flow;
200 -
201 - $status_friendly_name = '';
202 -
203 - $builtin_stati = array(
204 - 'publish' => __( 'Published', 'edit-flow' ),
205 - 'draft' => __( 'Draft', 'edit-flow' ),
206 - 'future' => __( 'Scheduled', 'edit-flow' ),
207 - 'private' => __( 'Private', 'edit-flow' ),
208 - 'pending' => __( 'Pending Review', 'edit-flow' ),
209 - 'trash' => __( 'Trash', 'edit-flow' ),
210 - );
211 -
212 - // Custom statuses only handles workflow statuses
213 - if ( $this->module_enabled( 'custom_status' )
214 - && !in_array( $status, array( 'publish', 'future', 'private', 'trash' ) ) ) {
215 - $status_object = $edit_flow->custom_status->get_custom_status_by( 'slug', $status );
216 - if( $status_object && !is_wp_error( $status_object ) ) {
217 - $status_friendly_name = $status_object->name;
218 - }
219 - } else if ( array_key_exists( $status, $builtin_stati ) ) {
220 - $status_friendly_name = $builtin_stati[$status];
221 - }
222 - return $status_friendly_name;
223 - }
224 -
225 - /**
226 212 * Enqueue any resources (CSS or JS) associated with datepicker functionality
227 213 *
228 214 * @since 0.7
229 215 */
230 216 function enqueue_datepicker_resources() {
231 -
217 +
232 218 // Add the first day of the week as an available variable to wp_head
233 - 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>";
234 220
235 - // Datepicker is available WordPress 3.3. We have to register it ourselves for previous versions of WordPress
236 221 wp_enqueue_script( 'jquery-ui-datepicker' );
237 222
238 223 //Timepicker needs to come after jquery-ui-datepicker and jquery
239 - 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 );
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 );
240 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 );
241 226
242 227 // Now styles
243 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' );
@@ -242,9 +227,9 @@
242 227 // Now styles
243 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' );
244 229 wp_enqueue_style( 'jquery-ui-theme', EDIT_FLOW_URL . 'common/css/jquery.ui.theme.css', false, EDIT_FLOW_VERSION, 'screen' );
245 230 }
246 -
231 +
247 232 /**
248 233 * Checks for the current post type
249 234 *
250 235 * @since 0.7
@@ -274,9 +259,9 @@
274 259 }
275 260
276 261 return $post_type;
277 262 }
278 -
263 +
279 264 /**
280 265 * Wrapper for the get_user_meta() function so we can replace it if we need to
281 266 *
282 267 * @since 0.7
@@ -286,18 +271,18 @@
286 271 * @param bool $single Whether or not to return just one value
287 272 * @return string|bool|array $value Whatever the stored value was
288 273 */
289 274 function get_user_meta( $user_id, $key, $string = true ) {
290 -
275 +
291 276 $response = null;
292 277 $response = apply_filters( 'ef_get_user_meta', $response, $user_id, $key, $string );
293 278 if ( !is_null( $response ) )
294 279 return $response;
295 -
280 +
296 281 return get_user_meta( $user_id, $key, $string );
297 -
282 +
298 283 }
299 -
284 +
300 285 /**
301 286 * Wrapper for the update_user_meta() function so we can replace it if we need to
302 287 *
303 288 * @since 0.7
@@ -308,18 +293,18 @@
308 293 * @param string|bool|array $previous (optional) Previous value to replace
309 294 * @return bool $success Whether we were successful in saving
310 295 */
311 296 function update_user_meta( $user_id, $key, $value, $previous = null ) {
312 -
297 +
313 298 $response = null;
314 299 $response = apply_filters( 'ef_update_user_meta', $response, $user_id, $key, $value, $previous );
315 300 if ( !is_null( $response ) )
316 301 return $response;
317 -
302 +
318 303 return update_user_meta( $user_id, $key, $value, $previous );
319 -
320 - }
321 -
304 +
305 + }
306 +
322 307 /**
323 308 * Take a status and a message, JSON encode and print
324 309 *
325 310 * @since 0.7
@@ -330,9 +315,9 @@
330 315 header( 'Content-type: application/json;' );
331 316 echo json_encode( array( 'status' => $status, 'message' => $message ) );
332 317 exit;
333 318 }
334 -
319 +
335 320 /**
336 321 * Whether or not the current page is a user-facing Edit Flow View
337 322 * @todo Think of a creative way to make this work
338 323 *
@@ -340,14 +325,14 @@
340 325 *
341 326 * @param string $module_name (Optional) Module name to check against
342 327 */
343 328 function is_whitelisted_functional_view( $module_name = null ) {
344 -
329 +
345 330 // @todo complete this method
346 -
331 +
347 332 return true;
348 333 }
349 -
334 +
350 335 /**
351 336 * Whether or not the current page is an Edit Flow settings view (either main or module)
352 337 * Determination is based on $pagenow, $_GET['page'], and the module's $settings_slug
353 338 * If there's no module name specified, it will return true against all Edit Flow settings views
@@ -358,66 +343,30 @@
358 343 * @return bool $is_settings_view Return true if it is
359 344 */
360 345 function is_whitelisted_settings_view( $module_name = null ) {
361 346 global $pagenow, $edit_flow;
362 -
347 +
363 348 // All of the settings views are based on admin.php and a $_GET['page'] parameter
364 349 if ( $pagenow != 'admin.php' || !isset( $_GET['page'] ) )
365 350 return false;
366 -
351 +
367 352 // Load all of the modules that have a settings slug/ callback for the settings page
368 353 foreach ( $edit_flow->modules as $mod_name => $mod_data ) {
369 354 if ( isset( $mod_data->options->enabled ) && $mod_data->options->enabled == 'on' && $mod_data->configure_page_cb )
370 355 $settings_view_slugs[] = $mod_data->settings_slug;
371 356 }
372 -
357 +
373 358 // The current page better be in the array of registered settings view slugs
374 359 if ( !in_array( $_GET['page'], $settings_view_slugs ) )
375 360 return false;
376 -
361 +
377 362 if ( $module_name && $edit_flow->modules->$module_name->settings_slug != $_GET['page'] )
378 363 return false;
379 -
364 +
380 365 return true;
381 366 }
382 -
383 - /**
384 - * Remove term(s) associated with a given object(s). Core doesn't have this as of 3.2
385 - * @see http://core.trac.wordpress.org/ticket/15475
386 - *
387 - * @author ericmann
388 - * @compat 3.3?
389 - *
390 - * @param int|array $object_ids The ID(s) of the object(s) to retrieve.
391 - * @param int|array $terms The ids of the terms to remove.
392 - * @param string|array $taxonomies The taxonomies to retrieve terms from.
393 - * @return bool|WP_Error Affected Term IDs
394 - */
395 - function remove_object_terms( $object_id, $terms, $taxonomy ) {
396 - global $wpdb;
397 367
398 - if ( !taxonomy_exists( $taxonomy ) )
399 - return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) );
400 368
401 - if ( !is_array( $object_id ) )
402 - $object_id = array( $object_id );
403 -
404 - if ( !is_array($terms) )
405 - $terms = array( $terms );
406 -
407 - $delete_objects = array_map( 'intval', $object_id );
408 - $delete_terms = array_map( 'intval', $terms );
409 -
410 - if ( $delete_terms ) {
411 - $in_delete_terms = "'" . implode( "', '", $delete_terms ) . "'";
412 - $in_delete_objects = "'" . implode( "', '", $delete_objects ) . "'";
413 - $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 ) );
414 - wp_update_term_count( $delete_terms, $taxonomy );
415 - return true;
416 - }
417 - return false;
418 - }
419 -
420 369 /**
421 370 * This is a hack, Hack, HACK!!!
422 371 * Encode all of the given arguments as a serialized array, and then base64_encode
423 372 * Used to store extra data in a term's description field
@@ -429,9 +378,9 @@
429 378 */
430 379 function get_encoded_description( $args = array() ) {
431 380 return base64_encode( maybe_serialize( $args ) );
432 381 }
433 -
382 +
434 383 /**
435 384 * If given an encoded string from a term's description field,
436 385 * return an array of values. Otherwise, return the original string
437 386 *
@@ -442,9 +391,9 @@
442 391 */
443 392 function get_unencoded_description( $string_to_unencode ) {
444 393 return maybe_unserialize( base64_decode( $string_to_unencode ) );
445 394 }
446 -
395 +
447 396 /**
448 397 * Get the publicly accessible URL for the module based on the filename
449 398 *
450 399 * @since 0.7
@@ -455,9 +404,9 @@
455 404 function get_module_url( $file ) {
456 405 $module_url = plugins_url( '/', $file );
457 406 return trailingslashit( $module_url );
458 407 }
459 -
408 +
460 409 /**
461 410 * Produce a human-readable version of the time since a timestamp
462 411 *
463 412 * @param int $original The UNIX timestamp we're producing a relative time for
@@ -501,9 +450,9 @@
501 450 }
502 451
503 452 return sprintf( _n( "1 $name ago", "$count ${name}s ago", $count), $count);
504 453 }
505 -
454 +
506 455 /**
507 456 * Displays a list of users that can be selected!
508 457 *
509 458 * @since 0.7
@@ -516,9 +465,9 @@
516 465 function users_select_form( $selected = null, $args = null ) {
517 466
518 467 // Set up arguments
519 468 $defaults = array(
520 - 'list_class' => 'ef-users-select-form',
469 + 'list_class' => 'ef-users-select-form',
521 470 'input_id' => 'ef-selected-users'
522 471 );
523 472 $parsed_args = wp_parse_args( $args, $defaults );
524 473 extract($parsed_args, EXTR_SKIP);
@@ -532,8 +481,9 @@
532 481 ),
533 482 'orderby' => 'display_name',
534 483 );
535 484 $args = apply_filters( 'ef_users_select_form_get_users_args', $args );
485 +
536 486 $users = get_users( $args );
537 487
538 488 if ( !is_array($selected) ) $selected = array();
539 489 ?>
@@ -539,13 +489,20 @@
539 489 ?>
540 490
541 491 <?php if( !empty($users) ) : ?>
542 492 <ul class="<?php echo esc_attr( $list_class ) ?>">
543 - <?php foreach( $users as $user ) : ?>
544 - <?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 + ?>
545 498 <li>
546 499 <label for="<?php echo esc_attr( $input_id .'-'. $user->ID ) ?>">
547 - <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 +
548 505 <span class="ef-user_displayname"><?php echo esc_html( $user->display_name ); ?></span>
549 506 <span class="ef-user_useremail"><?php echo esc_html( $user->user_email ); ?></span>
550 507 </label>
551 508 </li>
@@ -569,9 +526,9 @@
569 526 if ( apply_filters( 'ef_kill_add_caps_to_role', false, $role, $caps ) )
570 527 return;
571 528
572 529 global $wp_roles;
573 -
530 +
574 531 if ( $wp_roles->is_role( $role ) ) {
575 532 $role = get_role( $role );
576 533 foreach ( $caps as $cap ) {
577 534 $role->add_cap( $cap );
@@ -585,21 +542,21 @@
585 542 *
586 543 * @since 0.7
587 544 */
588 545 function action_settings_help_menu() {
589 -
546 +
590 547 $screen = get_current_screen();
591 -
592 - if ( !method_exists( $screen, 'add_help_tab' ) )
548 +
549 + if ( !method_exists( $screen, 'add_help_tab' ) )
593 550 return;
594 -
595 - if ( $screen->id != 'edit-flow_page_' . $this->module->settings_slug )
551 +
552 + if ( $screen->id != 'edit-flow_page_' . $this->module->settings_slug )
596 553 return;
597 554
598 555 // Make sure we have all of the required values for our tab
599 556 if ( isset( $this->module->settings_help_tab['id'], $this->module->settings_help_tab['title'], $this->module->settings_help_tab['content'] ) ) {
600 557 $screen->add_help_tab( $this->module->settings_help_tab );
601 -
558 +
602 559 if ( isset( $this->module->settings_help_sidebar ) ) {
603 560 $screen->set_help_sidebar( $this->module->settings_help_sidebar );
604 561 }
605 562 }
@@ -640,7 +597,16 @@
640 597 $new_description = $this->get_encoded_description( $description_args );
641 598 wp_update_term( $term->term_id, $taxonomy, array( 'description' => $new_description ) );
642 599 }
643 600 }
644 -
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 +
645 611 }
646 612 }