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 | edit_flow.php +171 -78 0.7.20.9.2 View file →
@@ -3,12 +3,12 @@
3 3 Plugin Name: Edit Flow
4 4 Plugin URI: http://editflow.org/
5 5 Description: Remixing the WordPress admin for better editorial workflow options.
6 6 Author: Daniel Bachhuber, Scott Bressler, Mohammad Jangda, Automattic, and others
7 -Version: 0.7.2
7 +Version: 0.9.2
8 8 Author URI: http://editflow.org/
9 9
10 -Copyright 2009-2012 Mohammad Jangda, Daniel Bachhuber, et al.
10 +Copyright 2009-2019 Mohammad Jangda, Daniel Bachhuber, Automattic, et al.
11 11
12 12 GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
13 13
14 14 This program is free software; you can redistribute it and/or modify
@@ -26,10 +26,28 @@
26 26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 27
28 28 */
29 29
30 +/**
31 + * Print admin notice regarding having an old version of PHP.
32 + *
33 + * @since 0.9
34 + */
35 +function _ef_print_php_version_admin_notice() {
36 + ?>
37 + <div class="notice notice-error">
38 + <p><?php esc_html_e( 'Edit Flow requires PHP 5.6+. Please contact your host to update your PHP version.', 'edit-flow' ); ?></p>
39 + </div>
40 + <?php
41 +}
42 +
43 +if ( version_compare( phpversion(), '5.6', '<' ) ) {
44 + add_action( 'admin_notices', '_ef_print_php_version_admin_notice' );
45 + return;
46 +}
47 +
30 48 // Define contants
31 -define( 'EDIT_FLOW_VERSION' , '0.7.2' );
49 +define( 'EDIT_FLOW_VERSION' , '0.9.2' );
32 50 define( 'EDIT_FLOW_ROOT' , dirname(__FILE__) );
33 51 define( 'EDIT_FLOW_FILE_PATH' , EDIT_FLOW_ROOT . '/' . basename(__FILE__) );
34 52 define( 'EDIT_FLOW_URL' , plugins_url( '/', __FILE__ ) );
35 53 define( 'EDIT_FLOW_SETTINGS_PAGE' , add_query_arg( 'page', 'ef-settings', get_admin_url( null, 'admin.php' ) ) );
@@ -41,31 +59,51 @@
41 59 var $options_group = 'edit_flow_';
42 60 var $options_group_name = 'edit_flow_options';
43 61
44 62 /**
45 - * Constructor
63 + * @var EditFlow The one true EditFlow
46 64 */
47 - function __construct() {
48 -
49 - load_plugin_textdomain( 'edit-flow', null, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
65 + private static $instance;
50 66
51 - $this->modules = (object)array();
67 + /**
68 + * Main EditFlow Instance
69 + *
70 + * Insures that only one instance of EditFlow exists in memory at any one
71 + * time. Also prevents needing to define globals all over the place.
72 + *
73 + * @since EditFlow 0.7.4
74 + * @staticvar array $instance
75 + * @uses EditFlow::setup_globals() Setup the globals needed
76 + * @uses EditFlow::includes() Include the required files
77 + * @uses EditFlow::setup_actions() Setup the hooks and actions
78 + * @see EditFlow()
79 + * @return The one true EditFlow
80 + */
81 + public static function instance() {
82 + if ( ! isset( self::$instance ) ) {
83 + self::$instance = new edit_flow;
84 + self::$instance->setup_globals();
85 + self::$instance->setup_actions();
86 + // Backwards compat for when we promoted use of the $edit_flow global
87 + global $edit_flow;
88 + $edit_flow = self::$instance;
89 + }
90 + return self::$instance;
91 + }
52 92
53 - // Load all of our modules. 'ef_loaded' happens after 'plugins_loaded' so other plugins can
54 - // hook into the action we have at the end
55 - add_action( 'ef_loaded', array( $this, 'action_ef_loaded_load_modules' ) );
56 -
57 - // Load the module options later on, and offer a function to happen way after init
58 - add_action( 'init', array( $this, 'action_init' ) );
59 - add_action( 'init', array( $this, 'action_init_after' ), 1000 );
60 - add_action( 'admin_init', array( $this, 'action_admin_init' ) );
61 -
93 + private function __construct() {
94 + /** Do nothing **/
62 95 }
63 96
97 + private function setup_globals() {
98 + $this->modules = new stdClass();
99 + $this->modules_count = 0;
100 + }
101 +
64 102 /**
65 103 * Include the common resources to Edit Flow and dynamically load the modules
66 104 */
67 - function action_ef_loaded_load_modules() {
105 + private function load_modules() {
68 106
69 107 // We use the WP_List_Table API for some of the table gen
70 108 if ( !class_exists( 'WP_List_Table' ) )
71 109 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
@@ -71,9 +109,12 @@
71 109 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
72 110
73 111 // Edit Flow base module
74 112 require_once( EDIT_FLOW_ROOT . '/common/php/class-module.php' );
75 -
113 +
114 + // Edit Flow Block Editor Compat trait
115 + require_once( EDIT_FLOW_ROOT . '/common/php/trait-block-editor-compatible.php' );
116 +
76 117 // Scan the modules directory and include any modules that exist there
77 118 $module_dirs = scandir( EDIT_FLOW_ROOT . '/modules/' );
78 119 $class_names = array();
79 120 foreach( $module_dirs as $module_dir ) {
@@ -78,8 +119,13 @@
78 119 $class_names = array();
79 120 foreach( $module_dirs as $module_dir ) {
80 121 if ( file_exists( EDIT_FLOW_ROOT . "/modules/{$module_dir}/$module_dir.php" ) ) {
81 122 include_once( EDIT_FLOW_ROOT . "/modules/{$module_dir}/$module_dir.php" );
123 +
124 + // Try to load Gutenberg compat files
125 + if ( file_exists( EDIT_FLOW_ROOT . "/modules/{$module_dir}/compat/block-editor.php" ) ) {
126 + include_once( EDIT_FLOW_ROOT . "/modules/{$module_dir}/compat/block-editor.php" );
127 + }
82 128 // Prepare the class name because it should be standardized
83 129 $tmp = explode( '-', $module_dir );
84 130 $class_name = '';
85 131 $slug_name = '';
@@ -94,49 +140,90 @@
94 140
95 141 // Instantiate EF_Module as $helpers for back compat and so we can
96 142 // use it in this class
97 143 $this->helpers = new EF_Module();
98 -
144 +
99 145 // Other utils
100 146 require_once( EDIT_FLOW_ROOT . '/common/php/util.php' );
101 -
147 +
102 148 // Instantiate all of our classes onto the Edit Flow object
103 149 // but make sure they exist too
104 150 foreach( $class_names as $slug => $class_name ) {
105 151 if ( class_exists( $class_name ) ) {
106 152 $this->$slug = new $class_name();
153 + $compat_class_name = "{$class_name}_Block_Editor_Compat";
154 + if ( class_exists( $compat_class_name ) ) {
155 + $this->$slug->compat = new $compat_class_name( $this->$slug, $this->$slug->get_compat_hooks() );
156 + }
107 157 }
108 158 }
109 -
110 - // Supplementary plugins can hook into this, include their own modules
111 - // and add them to the $edit_flow object
159 +
160 + /**
161 + * Fires after edit_flow has loaded all Edit Flow internal modules.
162 + *
163 + * Plugin authors can hook into this action, include their own modules add them to the $edit_flow object
164 + *
165 + */
112 166 do_action( 'ef_modules_loaded' );
113 -
167 +
114 168 }
115 -
169 +
116 170 /**
171 + * Setup the default hooks and actions
172 + *
173 + * @since EditFlow 0.7.4
174 + * @access private
175 + * @uses add_action() To add various actions
176 + */
177 + private function setup_actions() {
178 + add_action( 'init', array( $this, 'action_init' ) );
179 + add_action( 'init', array( $this, 'action_init_after' ), 1000 );
180 +
181 + add_action( 'admin_init', array( $this, 'action_admin_init' ) );
182 +
183 + /**
184 + * Fires after setup of all edit_flow actions.
185 + *
186 + * Plugin authors can hook into this action to manipulate the edit_flow class after initial actions have been registered.
187 + *
188 + * @param edit_flow $this The core edit flow class
189 + */
190 + do_action_ref_array( 'editflow_after_setup_actions', array( &$this ) );
191 + }
192 +
193 + /**
117 194 * Inititalizes the Edit Flows!
118 195 * Loads options for each registered module and then initializes it if it's active
119 196 */
120 197 function action_init() {
121 -
198 +
199 + load_plugin_textdomain( 'edit-flow', null, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
200 +
201 + $this->load_modules();
202 +
122 203 // Load all of the module options
123 204 $this->load_module_options();
124 -
205 +
125 206 // Load all of the modules that are enabled.
126 207 // Modules won't have an options value if they aren't enabled
127 208 foreach ( $this->modules as $mod_name => $mod_data )
128 209 if ( isset( $mod_data->options->enabled ) && $mod_data->options->enabled == 'on' )
129 210 $this->$mod_name->init();
130 -
211 +
212 + /**
213 + * Fires after edit_flow has loaded all modules and module options.
214 + *
215 + * Plugin authors can hook into this action to trigger functionaltiy after all Edit Flow module's have been loaded.
216 + *
217 + */
131 218 do_action( 'ef_init' );
132 219 }
133 -
220 +
134 221 /**
135 - * Initialize the plugin for the admin
222 + * Initialize the plugin for the admin
136 223 */
137 224 function action_admin_init() {
138 -
225 +
139 226 // Upgrade if need be but don't run the upgrade if the plugin has never been used
140 227 $previous_version = get_option( $this->options_group . 'version' );
141 228 if ( $previous_version && version_compare( $previous_version, EDIT_FLOW_VERSION, '<' ) ) {
142 229 foreach ( $this->modules as $mod_name => $mod_data ) {
@@ -146,9 +233,9 @@
146 233 update_option( $this->options_group . 'version', EDIT_FLOW_VERSION );
147 234 } else if ( !$previous_version ) {
148 235 update_option( $this->options_group . 'version', EDIT_FLOW_VERSION );
149 236 }
150 -
237 +
151 238 // For each module that's been loaded, auto-load data if it's never been run before
152 239 foreach ( $this->modules as $mod_name => $mod_data ) {
153 240 // If the module has never been loaded before, run the install method if there is one
154 241 if ( !isset( $mod_data->options->loaded_once ) || !$mod_data->options->loaded_once ) {
@@ -158,20 +245,20 @@
158 245 }
159 246 }
160 247
161 248 $this->register_scripts_and_styles();
162 -
249 +
163 250 }
164 -
251 +
165 252 /**
166 253 * Register a new module with Edit Flow
167 254 */
168 255 public function register_module( $name, $args = array() ) {
169 -
256 +
170 257 // A title and name is required for every module
171 258 if ( !isset( $args['title'], $name ) )
172 259 return false;
173 -
260 +
174 261 $defaults = array(
175 262 'title' => '',
176 263 'short_description' => '',
177 264 'extended_description' => '',
@@ -185,14 +272,13 @@
185 272 // These messages are applied to modules and can be overridden if custom messages are needed
186 273 'messages' => array(
187 274 'settings-updated' => __( 'Settings updated.', 'edit-flow' ),
188 275 'form-error' => __( 'Please correct your form errors below and try again.', 'edit-flow' ),
189 - 'nonce-failed' => __( 'Cheatin&#8217; uh?' ),
190 - 'invalid-permissions' => __( 'You do not have necessary permissions to complete this action.' ),
276 + 'nonce-failed' => __( 'Cheatin&#8217; uh?', 'edit-flow' ),
277 + 'invalid-permissions' => __( 'You do not have necessary permissions to complete this action.', 'edit-flow' ),
191 278 'missing-post' => __( 'Post does not exist', 'edit-flow' ),
192 279 ),
193 280 'autoload' => false, // autoloading a module will remove the ability to enable or disable it
194 - 'load_frontend' => false, // Whether or not the module should be loaded on the frontend too
195 281 );
196 282 if ( isset( $args['messages'] ) )
197 283 $args['messages'] = array_merge( (array)$args['messages'], $defaults['messages'] );
198 284 $args = array_merge( $defaults, $args );
@@ -205,35 +291,47 @@
205 291 // If there's a Help Screen registered for the module, make sure we
206 292 // auto-load it
207 293 if ( !empty( $args['settings_help_tab'] ) )
208 294 add_action( 'load-edit-flow_page_' . $args['settings_slug'], array( &$this->$name, 'action_settings_help_menu' ) );
209 -
295 +
210 296 $this->modules->$name = (object) $args;
297 +
298 + $this->modules_count++;
299 +
300 + /**
301 + * Fires after edit_flow has registered a module.
302 + *
303 + * Plugin authors can hook into this action to trigger functionaltiy after a module has been loaded.
304 + *
305 + * @param string $name The name of the registered module
306 + */
211 307 do_action( 'ef_module_registered', $name );
212 308 return $this->modules->$name;
213 309 }
214 -
310 +
215 311 /**
216 312 * Load all of the module options from the database
217 313 * If a given option isn't yet set, then set it to the module's default (upgrades, etc.)
218 314 */
219 315 function load_module_options() {
316 +
220 317 foreach ( $this->modules as $mod_name => $mod_data ) {
221 - // Don't load modules on the frontend unless they're explictly defined as such
222 - if ( !is_admin() && !$mod_data->load_frontend )
223 - continue;
224 -
225 - $this->modules->$mod_name->options = get_option( $this->options_group . $mod_name . '_options' );
318 +
319 + $this->modules->$mod_name->options = get_option( $this->options_group . $mod_name . '_options', new stdClass );
226 320 foreach ( $mod_data->default_options as $default_key => $default_value ) {
227 321 if ( !isset( $this->modules->$mod_name->options->$default_key ) )
228 322 $this->modules->$mod_name->options->$default_key = $default_value;
229 323 }
230 324
231 - if ( isset( $this->modules->$mod_name->options->post_types ) )
232 - $this->modules->$mod_name->options->post_types = $this->helpers->clean_post_type_options( $this->modules->$mod_name->options->post_types, $mod_data->post_type_support );
233 -
234 325 $this->$mod_name->module = $this->modules->$mod_name;
235 326 }
327 +
328 + /**
329 + * Fires after edit_flow has loaded all of the module options from the database.
330 + *
331 + * Plugin authors can hook into this action to read and manipulate module settings.
332 + *
333 + */
236 334 do_action( 'ef_module_options_loaded' );
237 335 }
238 336
239 337 /**
@@ -242,26 +340,26 @@
242 340 * @see http://dev.editflow.org/2011/11/17/edit-flow-v0-7-alpha2-notes/#comment-232
243 341 */
244 342 function action_init_after() {
245 343 foreach ( $this->modules as $mod_name => $mod_data ) {
246 - // Don't load modules on the frontend unless they're explictly defined as such
247 - if ( !is_admin() && !$mod_data->load_frontend )
248 - continue;
249 344
250 345 if ( isset( $this->modules->$mod_name->options->post_types ) )
251 - $this->modules->$mod_name->options->post_types = $this->helpers->clean_post_type_options( $this->modules->$mod_name->options->post_types, $mod_data->post_type_support );
252 -
346 + $this->modules->$mod_name->options->post_types = $this->helpers->clean_post_type_options( $this->modules->$mod_name->options->post_types, $mod_data->post_type_support );
347 +
253 348 $this->$mod_name->module = $this->modules->$mod_name;
254 349 }
255 350 }
256 -
351 +
257 352 /**
258 353 * Get a module by one of its descriptive values
354 + *
355 + * @param string $key The property to use for searching a module (ex: 'name')
356 + * @param string|int|array $value The value to compare (using ==)
259 357 */
260 358 function get_module_by( $key, $value ) {
261 359 $module = false;
262 360 foreach ( $this->modules as $mod_name => $mod_data ) {
263 -
361 +
264 362 if ( $key == 'name' && $value == $mod_name ) {
265 363 $module = $this->modules->$mod_name;
266 364 } else {
267 365 foreach( $mod_data as $mod_data_key => $mod_data_value ) {
@@ -271,9 +369,9 @@
271 369 }
272 370 }
273 371 return $module;
274 372 }
275 -
373 +
276 374 /**
277 375 * Update the $edit_flow object with new value and save to the database
278 376 */
279 377 function update_module_option( $mod_name, $key, $value ) {
@@ -280,9 +378,9 @@
280 378 $this->modules->$mod_name->options->$key = $value;
281 379 $this->$mod_name->module = $this->modules->$mod_name;
282 380 return update_option( $this->options_group . $mod_name . '_options', $this->modules->$mod_name->options );
283 381 }
284 -
382 +
285 383 function update_all_module_options( $mod_name, $new_options ) {
286 384 if ( is_array( $new_options ) )
287 385 $new_options = (object)$new_options;
288 386 $this->modules->$mod_name->options = $new_options;
@@ -291,34 +389,29 @@
291 389 }
292 390
293 391 /**
294 392 * Registers commonly used scripts + styles for easy enqueueing
295 - */
393 + */
296 394 function register_scripts_and_styles() {
395 + wp_enqueue_style( 'ef-admin-css', EDIT_FLOW_URL . 'common/css/edit-flow-admin.css', false, EDIT_FLOW_VERSION, 'all' );
396 +
297 397 wp_register_script( 'jquery-listfilterizer', EDIT_FLOW_URL . 'common/js/jquery.listfilterizer.js', array( 'jquery' ), EDIT_FLOW_VERSION, true );
298 398 wp_register_style( 'jquery-listfilterizer', EDIT_FLOW_URL . 'common/css/jquery.listfilterizer.css', false, EDIT_FLOW_VERSION, 'all' );
299 399
400 +
401 + wp_localize_script( 'jquery-listfilterizer',
402 + '__i18n_jquery_filterizer',
403 + array(
404 + 'all' => esc_html__( 'All', 'edit-flow' ),
405 + 'selected' => esc_html__( 'Selected', 'edit-flow' ),
406 + ) );
407 +
300 408 wp_register_script( 'jquery-quicksearch', EDIT_FLOW_URL . 'common/js/jquery.quicksearch.js', array( 'jquery' ), EDIT_FLOW_VERSION, true );
301 409
302 - // @compat 3.3
303 - // Register jQuery datepicker plugin if it doesn't already exist. Datepicker plugin was added in WordPress 3.3
304 - global $wp_scripts;
305 - if ( !isset( $wp_scripts->registered['jquery-ui-datepicker'] ) )
306 - wp_register_script( 'jquery-ui-datepicker', EDIT_FLOW_URL . 'common/js/jquery.ui.datepicker.min.js', array( 'jquery', 'jquery-ui-core'), '1.8.16', true );
307 410 }
308 411
309 412 }
310 413
311 -// Create new instance of the edit_flow object
312 -global $edit_flow;
313 -$edit_flow = new edit_flow();
314 -
315 -/**
316 - * ef_loaded()
317 - * Allow dependent plugins and core actions to attach themselves in a safe way
318 - */
319 -function ef_loaded() {
320 - do_action( 'ef_loaded' );
414 +function EditFlow() {
415 + return edit_flow::instance();
321 416 }
322 -add_action( 'plugins_loaded', 'ef_loaded', 20 );
323 -
324 -?>
417 +add_action( 'plugins_loaded', 'EditFlow' );