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 +132 -154 0.80.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,32 +140,45 @@
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 - $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(
128 162 (object)array(
129 - 'name' => __( 'Draft' ),
130 - 'description' => '',
131 - 'slug' => 'draft',
163 + 'name' => __( 'Draft' ),
164 + 'description' => '',
165 + 'slug' => 'draft',
166 + 'position' => 1,
132 167 ),
133 168 (object)array(
134 - 'name' => __( 'Pending Review' ),
135 - 'description' => '',
136 - 'slug' => 'pending',
137 - ),
169 + 'name' => __( 'Pending Review' ),
170 + 'description' => '',
171 + 'slug' => 'pending',
172 + 'position' => 2,
173 + ),
138 174 );
139 - return $post_statuses;
140 - }
141 175 }
142 176
143 177 /**
144 178 * Gets the name of the default custom status. If custom statuses are disabled,
145 179 * returns 'draft'.
146 - *
180 + *
147 181 * @return str Name of the status
148 182 */
149 183 function get_default_post_status(){
150 184
@@ -149,9 +183,9 @@
149 183 function get_default_post_status(){
150 184
151 185 // Check if custom status module is enabled
152 186 $custom_status_module = EditFlow()->custom_status->module->options;
153 -
187 +
154 188 if( $custom_status_module->enabled == 'on' )
155 189 return $custom_status_module->default_status;
156 190 else
157 191 return 'draft';
@@ -172,59 +206,23 @@
172 206 if ( $post_type != 'post' && in_array( $post_type, get_post_types( '', 'names' ) ) )
173 207 $filter_link = add_query_arg( 'post_type', $post_type, $filter_link );
174 208 return $filter_link;
175 209 }
176 -
210 +
177 211 /**
178 - * Returns the friendly name for a given status
179 - *
180 - * @since 0.7
181 - *
182 - * @param string $status The status slug
183 - * @return string $status_friendly_name The friendly name for the status
184 - */
185 - function get_post_status_friendly_name( $status ) {
186 - global $edit_flow;
187 -
188 - $status_friendly_name = '';
189 -
190 - $builtin_stati = array(
191 - 'publish' => __( 'Published', 'edit-flow' ),
192 - 'draft' => __( 'Draft', 'edit-flow' ),
193 - 'future' => __( 'Scheduled', 'edit-flow' ),
194 - 'private' => __( 'Private', 'edit-flow' ),
195 - 'pending' => __( 'Pending Review', 'edit-flow' ),
196 - 'trash' => __( 'Trash', 'edit-flow' ),
197 - );
198 -
199 - // Custom statuses only handles workflow statuses
200 - if ( $this->module_enabled( 'custom_status' )
201 - && !in_array( $status, array( 'publish', 'future', 'private', 'trash' ) ) ) {
202 - $status_object = $edit_flow->custom_status->get_custom_status_by( 'slug', $status );
203 - if( $status_object && !is_wp_error( $status_object ) ) {
204 - $status_friendly_name = $status_object->name;
205 - }
206 - } else if ( array_key_exists( $status, $builtin_stati ) ) {
207 - $status_friendly_name = $builtin_stati[$status];
208 - }
209 - return $status_friendly_name;
210 - }
211 -
212 - /**
213 212 * Enqueue any resources (CSS or JS) associated with datepicker functionality
214 213 *
215 214 * @since 0.7
216 215 */
217 216 function enqueue_datepicker_resources() {
218 -
217 +
219 218 // Add the first day of the week as an available variable to wp_head
220 - 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>";
221 220
222 - // Datepicker is available WordPress 3.3. We have to register it ourselves for previous versions of WordPress
223 221 wp_enqueue_script( 'jquery-ui-datepicker' );
224 222
225 223 //Timepicker needs to come after jquery-ui-datepicker and jquery
226 - 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 );
227 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 );
228 226
229 227 // Now styles
230 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' );
@@ -229,9 +227,9 @@
229 227 // Now styles
230 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' );
231 229 wp_enqueue_style( 'jquery-ui-theme', EDIT_FLOW_URL . 'common/css/jquery.ui.theme.css', false, EDIT_FLOW_VERSION, 'screen' );
232 230 }
233 -
231 +
234 232 /**
235 233 * Checks for the current post type
236 234 *
237 235 * @since 0.7
@@ -239,33 +237,31 @@
239 237 */
240 238 function get_current_post_type() {
241 239 global $post, $typenow, $pagenow, $current_screen;
242 240 //get_post() needs a variable
243 - $post_int;
244 - if( isset( $_REQUEST['post'] ) )
245 - $post_int = (int)$_REQUEST['post'];
241 + $post_id = isset( $_REQUEST['post'] ) ? (int)$_REQUEST['post'] : false;
246 242
247 - if ( $post && $post->post_type )
243 + if ( $post && $post->post_type ) {
248 244 $post_type = $post->post_type;
249 - elseif ( $typenow )
245 + } elseif ( $typenow ) {
250 246 $post_type = $typenow;
251 - elseif ( $current_screen && isset( $current_screen->post_type ) )
247 + } elseif ( $current_screen && !empty( $current_screen->post_type ) ) {
252 248 $post_type = $current_screen->post_type;
253 - elseif ( isset( $_REQUEST['post_type'] ) )
249 + } elseif ( isset( $_REQUEST['post_type'] ) ) {
254 250 $post_type = sanitize_key( $_REQUEST['post_type'] );
255 - elseif ( 'post.php' == $pagenow
256 - && isset( $_REQUEST['post'] )
257 - && isset( $post_int )
258 - && ! empty( get_post( $post_int )->post_type ) )
259 - $post_type = get_post( $post_int )->post_type;
260 - 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'] ) ) {
261 256 $post_type = 'post';
262 - else
257 + } else {
263 258 $post_type = null;
259 + }
264 260
265 261 return $post_type;
266 262 }
267 -
263 +
268 264 /**
269 265 * Wrapper for the get_user_meta() function so we can replace it if we need to
270 266 *
271 267 * @since 0.7
@@ -275,18 +271,18 @@
275 271 * @param bool $single Whether or not to return just one value
276 272 * @return string|bool|array $value Whatever the stored value was
277 273 */
278 274 function get_user_meta( $user_id, $key, $string = true ) {
279 -
275 +
280 276 $response = null;
281 277 $response = apply_filters( 'ef_get_user_meta', $response, $user_id, $key, $string );
282 278 if ( !is_null( $response ) )
283 279 return $response;
284 -
280 +
285 281 return get_user_meta( $user_id, $key, $string );
286 -
282 +
287 283 }
288 -
284 +
289 285 /**
290 286 * Wrapper for the update_user_meta() function so we can replace it if we need to
291 287 *
292 288 * @since 0.7
@@ -297,18 +293,18 @@
297 293 * @param string|bool|array $previous (optional) Previous value to replace
298 294 * @return bool $success Whether we were successful in saving
299 295 */
300 296 function update_user_meta( $user_id, $key, $value, $previous = null ) {
301 -
297 +
302 298 $response = null;
303 299 $response = apply_filters( 'ef_update_user_meta', $response, $user_id, $key, $value, $previous );
304 300 if ( !is_null( $response ) )
305 301 return $response;
306 -
302 +
307 303 return update_user_meta( $user_id, $key, $value, $previous );
308 -
309 - }
310 -
304 +
305 + }
306 +
311 307 /**
312 308 * Take a status and a message, JSON encode and print
313 309 *
314 310 * @since 0.7
@@ -319,9 +315,9 @@
319 315 header( 'Content-type: application/json;' );
320 316 echo json_encode( array( 'status' => $status, 'message' => $message ) );
321 317 exit;
322 318 }
323 -
319 +
324 320 /**
325 321 * Whether or not the current page is a user-facing Edit Flow View
326 322 * @todo Think of a creative way to make this work
327 323 *
@@ -329,14 +325,14 @@
329 325 *
330 326 * @param string $module_name (Optional) Module name to check against
331 327 */
332 328 function is_whitelisted_functional_view( $module_name = null ) {
333 -
329 +
334 330 // @todo complete this method
335 -
331 +
336 332 return true;
337 333 }
338 -
334 +
339 335 /**
340 336 * Whether or not the current page is an Edit Flow settings view (either main or module)
341 337 * Determination is based on $pagenow, $_GET['page'], and the module's $settings_slug
342 338 * If there's no module name specified, it will return true against all Edit Flow settings views
@@ -347,66 +343,30 @@
347 343 * @return bool $is_settings_view Return true if it is
348 344 */
349 345 function is_whitelisted_settings_view( $module_name = null ) {
350 346 global $pagenow, $edit_flow;
351 -
347 +
352 348 // All of the settings views are based on admin.php and a $_GET['page'] parameter
353 349 if ( $pagenow != 'admin.php' || !isset( $_GET['page'] ) )
354 350 return false;
355 -
351 +
356 352 // Load all of the modules that have a settings slug/ callback for the settings page
357 353 foreach ( $edit_flow->modules as $mod_name => $mod_data ) {
358 354 if ( isset( $mod_data->options->enabled ) && $mod_data->options->enabled == 'on' && $mod_data->configure_page_cb )
359 355 $settings_view_slugs[] = $mod_data->settings_slug;
360 356 }
361 -
357 +
362 358 // The current page better be in the array of registered settings view slugs
363 359 if ( !in_array( $_GET['page'], $settings_view_slugs ) )
364 360 return false;
365 -
361 +
366 362 if ( $module_name && $edit_flow->modules->$module_name->settings_slug != $_GET['page'] )
367 363 return false;
368 -
364 +
369 365 return true;
370 366 }
371 -
372 - /**
373 - * Remove term(s) associated with a given object(s). Core doesn't have this as of 3.2
374 - * @see http://core.trac.wordpress.org/ticket/15475
375 - *
376 - * @author ericmann
377 - * @compat 3.3?
378 - *
379 - * @param int|array $object_ids The ID(s) of the object(s) to retrieve.
380 - * @param int|array $terms The ids of the terms to remove.
381 - * @param string|array $taxonomies The taxonomies to retrieve terms from.
382 - * @return bool|WP_Error Affected Term IDs
383 - */
384 - function remove_object_terms( $object_id, $terms, $taxonomy ) {
385 - global $wpdb;
386 367
387 - if ( !taxonomy_exists( $taxonomy ) )
388 - return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) );
389 368
390 - if ( !is_array( $object_id ) )
391 - $object_id = array( $object_id );
392 -
393 - if ( !is_array($terms) )
394 - $terms = array( $terms );
395 -
396 - $delete_objects = array_map( 'intval', $object_id );
397 - $delete_terms = array_map( 'intval', $terms );
398 -
399 - if ( $delete_terms ) {
400 - $in_delete_terms = "'" . implode( "', '", $delete_terms ) . "'";
401 - $in_delete_objects = "'" . implode( "', '", $delete_objects ) . "'";
402 - $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 ) );
403 - wp_update_term_count( $delete_terms, $taxonomy );
404 - return true;
405 - }
406 - return false;
407 - }
408 -
409 369 /**
410 370 * This is a hack, Hack, HACK!!!
411 371 * Encode all of the given arguments as a serialized array, and then base64_encode
412 372 * Used to store extra data in a term's description field
@@ -418,9 +378,9 @@
418 378 */
419 379 function get_encoded_description( $args = array() ) {
420 380 return base64_encode( maybe_serialize( $args ) );
421 381 }
422 -
382 +
423 383 /**
424 384 * If given an encoded string from a term's description field,
425 385 * return an array of values. Otherwise, return the original string
426 386 *
@@ -431,9 +391,9 @@
431 391 */
432 392 function get_unencoded_description( $string_to_unencode ) {
433 393 return maybe_unserialize( base64_decode( $string_to_unencode ) );
434 394 }
435 -
395 +
436 396 /**
437 397 * Get the publicly accessible URL for the module based on the filename
438 398 *
439 399 * @since 0.7
@@ -444,9 +404,9 @@
444 404 function get_module_url( $file ) {
445 405 $module_url = plugins_url( '/', $file );
446 406 return trailingslashit( $module_url );
447 407 }
448 -
408 +
449 409 /**
450 410 * Produce a human-readable version of the time since a timestamp
451 411 *
452 412 * @param int $original The UNIX timestamp we're producing a relative time for
@@ -490,9 +450,9 @@
490 450 }
491 451
492 452 return sprintf( _n( "1 $name ago", "$count ${name}s ago", $count), $count);
493 453 }
494 -
454 +
495 455 /**
496 456 * Displays a list of users that can be selected!
497 457 *
498 458 * @since 0.7
@@ -505,9 +465,9 @@
505 465 function users_select_form( $selected = null, $args = null ) {
506 466
507 467 // Set up arguments
508 468 $defaults = array(
509 - 'list_class' => 'ef-users-select-form',
469 + 'list_class' => 'ef-users-select-form',
510 470 'input_id' => 'ef-selected-users'
511 471 );
512 472 $parsed_args = wp_parse_args( $args, $defaults );
513 473 extract($parsed_args, EXTR_SKIP);
@@ -521,8 +481,9 @@
521 481 ),
522 482 'orderby' => 'display_name',
523 483 );
524 484 $args = apply_filters( 'ef_users_select_form_get_users_args', $args );
485 +
525 486 $users = get_users( $args );
526 487
527 488 if ( !is_array($selected) ) $selected = array();
528 489 ?>
@@ -528,13 +489,20 @@
528 489 ?>
529 490
530 491 <?php if( !empty($users) ) : ?>
531 492 <ul class="<?php echo esc_attr( $list_class ) ?>">
532 - <?php foreach( $users as $user ) : ?>
533 - <?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 + ?>
534 498 <li>
535 499 <label for="<?php echo esc_attr( $input_id .'-'. $user->ID ) ?>">
536 - <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 +
537 505 <span class="ef-user_displayname"><?php echo esc_html( $user->display_name ); ?></span>
538 506 <span class="ef-user_useremail"><?php echo esc_html( $user->user_email ); ?></span>
539 507 </label>
540 508 </li>
@@ -558,13 +526,14 @@
558 526 if ( apply_filters( 'ef_kill_add_caps_to_role', false, $role, $caps ) )
559 527 return;
560 528
561 529 global $wp_roles;
562 -
530 +
563 531 if ( $wp_roles->is_role( $role ) ) {
564 - $role = &get_role( $role );
565 - foreach ( $caps as $cap )
532 + $role = get_role( $role );
533 + foreach ( $caps as $cap ) {
566 534 $role->add_cap( $cap );
535 + }
567 536 }
568 537 }
569 538
570 539 /**
@@ -573,21 +542,21 @@
573 542 *
574 543 * @since 0.7
575 544 */
576 545 function action_settings_help_menu() {
577 -
546 +
578 547 $screen = get_current_screen();
579 -
580 - if ( !method_exists( $screen, 'add_help_tab' ) )
548 +
549 + if ( !method_exists( $screen, 'add_help_tab' ) )
581 550 return;
582 -
583 - if ( $screen->id != 'edit-flow_page_' . $this->module->settings_slug )
551 +
552 + if ( $screen->id != 'edit-flow_page_' . $this->module->settings_slug )
584 553 return;
585 554
586 555 // Make sure we have all of the required values for our tab
587 556 if ( isset( $this->module->settings_help_tab['id'], $this->module->settings_help_tab['title'], $this->module->settings_help_tab['content'] ) ) {
588 557 $screen->add_help_tab( $this->module->settings_help_tab );
589 -
558 +
590 559 if ( isset( $this->module->settings_help_sidebar ) ) {
591 560 $screen->set_help_sidebar( $this->module->settings_help_sidebar );
592 561 }
593 562 }
@@ -628,7 +597,16 @@
628 597 $new_description = $this->get_encoded_description( $description_args );
629 598 wp_update_term( $term->term_id, $taxonomy, array( 'description' => $new_description ) );
630 599 }
631 600 }
632 -
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 +
633 611 }
634 612 }