PluginProbe
Edit Flow / 0.9.6
Edit Flow v0.9.6
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
edit-flow / edit_flow.php

edit_flow.php in Edit Flow 0.9.6, at edit_flow.php

410 lines 13.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Edit Flow
4 Plugin URI: http://editflow.org/
5 Description: Remixing the WordPress admin for better editorial workflow options.
6 Author: Daniel Bachhuber, Scott Bressler, Mohammad Jangda, Automattic, and others
7 Version: 0.9.6
8 Author URI: http://editflow.org/
9
10 Copyright 2009-2019 Mohammad Jangda, Daniel Bachhuber, Automattic, et al.
11
12 GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
28 */
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
48 // Define contants
49 define( 'EDIT_FLOW_VERSION' , '0.9.6' );
50 define( 'EDIT_FLOW_ROOT' , dirname(__FILE__) );
51 define( 'EDIT_FLOW_FILE_PATH' , EDIT_FLOW_ROOT . '/' . basename(__FILE__) );
52 define( 'EDIT_FLOW_URL' , plugins_url( '/', __FILE__ ) );
53 define( 'EDIT_FLOW_SETTINGS_PAGE' , add_query_arg( 'page', 'ef-settings', get_admin_url( null, 'admin.php' ) ) );
54
55 // Core class
56 class edit_flow {
57
58 // Unique identified added as a prefix to all options
59 var $options_group = 'edit_flow_';
60 var $options_group_name = 'edit_flow_options';
61
62 /**
63 * @var EditFlow The one true EditFlow
64 */
65 private static $instance;
66
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 }
92
93 private function __construct() {
94 /** Do nothing **/
95 }
96
97 private function setup_globals() {
98 $this->modules = new stdClass();
99 $this->modules_count = 0;
100 }
101
102 /**
103 * Include the common resources to Edit Flow and dynamically load the modules
104 */
105 private function load_modules() {
106
107 // We use the WP_List_Table API for some of the table gen
108 if ( !class_exists( 'WP_List_Table' ) )
109 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
110
111 // Edit Flow base module
112 require_once( EDIT_FLOW_ROOT . '/common/php/class-module.php' );
113
114 // Edit Flow Block Editor Compat trait
115 require_once( EDIT_FLOW_ROOT . '/common/php/trait-block-editor-compatible.php' );
116
117 // Scan the modules directory and include any modules that exist there
118 $module_dirs = scandir( EDIT_FLOW_ROOT . '/modules/' );
119 $class_names = array();
120 foreach( $module_dirs as $module_dir ) {
121 if ( file_exists( EDIT_FLOW_ROOT . "/modules/{$module_dir}/$module_dir.php" ) ) {
122 include_once( EDIT_FLOW_ROOT . "/modules/{$module_dir}/$module_dir.php" );
123
124 // Prepare the class name because it should be standardized
125 $tmp = explode( '-', $module_dir );
126 $class_name = '';
127 $slug_name = '';
128 foreach( $tmp as $word ) {
129 $class_name .= ucfirst( $word ) . '_';
130 $slug_name .= $word . '_';
131 }
132 $slug_name = rtrim( $slug_name, '_' );
133 $class_names[$slug_name] = 'EF_' . rtrim( $class_name, '_' );
134 }
135 }
136
137 // Instantiate EF_Module as $helpers for back compat and so we can
138 // use it in this class
139 $this->helpers = new EF_Module();
140
141 // Other utils
142 require_once( EDIT_FLOW_ROOT . '/common/php/util.php' );
143
144 // Instantiate all of our classes onto the Edit Flow object
145 // but make sure they exist too
146 foreach( $class_names as $slug => $class_name ) {
147 if ( class_exists( $class_name ) ) {
148 $this->$slug = new $class_name();
149 }
150 }
151
152 /**
153 * Fires after edit_flow has loaded all Edit Flow internal modules.
154 *
155 * Plugin authors can hook into this action, include their own modules add them to the $edit_flow object
156 *
157 */
158 do_action( 'ef_modules_loaded' );
159
160 }
161
162 /**
163 * Setup the default hooks and actions
164 *
165 * @since EditFlow 0.7.4
166 * @access private
167 * @uses add_action() To add various actions
168 */
169 private function setup_actions() {
170 add_action( 'init', array( $this, 'action_init' ) );
171 add_action( 'init', array( $this, 'action_init_after' ), 1000 );
172
173 add_action( 'admin_init', array( $this, 'action_admin_init' ) );
174
175 /**
176 * Fires after setup of all edit_flow actions.
177 *
178 * Plugin authors can hook into this action to manipulate the edit_flow class after initial actions have been registered.
179 *
180 * @param edit_flow $this The core edit flow class
181 */
182 do_action_ref_array( 'editflow_after_setup_actions', array( &$this ) );
183 }
184
185 /**
186 * Inititalizes the Edit Flows!
187 * Loads options for each registered module and then initializes it if it's active
188 */
189 function action_init() {
190
191 load_plugin_textdomain( 'edit-flow', null, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
192
193 $this->load_modules();
194
195 // Load all of the module options
196 $this->load_module_options();
197
198 // Load all of the modules that are enabled.
199 // Modules won't have an options value if they aren't enabled
200 foreach ( $this->modules as $mod_name => $mod_data )
201 if ( isset( $mod_data->options->enabled ) && $mod_data->options->enabled == 'on' )
202 $this->$mod_name->init();
203
204 /**
205 * Fires after edit_flow has loaded all modules and module options.
206 *
207 * Plugin authors can hook into this action to trigger functionaltiy after all Edit Flow module's have been loaded.
208 *
209 */
210 do_action( 'ef_init' );
211 }
212
213 /**
214 * Initialize the plugin for the admin
215 */
216 function action_admin_init() {
217
218 // Upgrade if need be but don't run the upgrade if the plugin has never been used
219 $previous_version = get_option( $this->options_group . 'version' );
220 if ( $previous_version && version_compare( $previous_version, EDIT_FLOW_VERSION, '<' ) ) {
221 foreach ( $this->modules as $mod_name => $mod_data ) {
222 if ( method_exists( $this->$mod_name, 'upgrade' ) )
223 $this->$mod_name->upgrade( $previous_version );
224 }
225 update_option( $this->options_group . 'version', EDIT_FLOW_VERSION );
226 } else if ( !$previous_version ) {
227 update_option( $this->options_group . 'version', EDIT_FLOW_VERSION );
228 }
229
230 // For each module that's been loaded, auto-load data if it's never been run before
231 foreach ( $this->modules as $mod_name => $mod_data ) {
232 // If the module has never been loaded before, run the install method if there is one
233 if ( !isset( $mod_data->options->loaded_once ) || !$mod_data->options->loaded_once ) {
234 if ( method_exists( $this->$mod_name, 'install' ) )
235 $this->$mod_name->install();
236 $this->update_module_option( $mod_name, 'loaded_once', true );
237 }
238 }
239
240 $this->register_scripts_and_styles();
241
242 }
243
244 /**
245 * Register a new module with Edit Flow
246 */
247 public function register_module( $name, $args = array() ) {
248
249 // A title and name is required for every module
250 if ( !isset( $args['title'], $name ) )
251 return false;
252
253 $defaults = array(
254 'title' => '',
255 'short_description' => '',
256 'extended_description' => '',
257 'img_url' => false,
258 'slug' => '',
259 'post_type_support' => '',
260 'default_options' => array(),
261 'options' => false,
262 'configure_page_cb' => false,
263 'configure_link_text' => __( 'Configure', 'edit-flow' ),
264 // These messages are applied to modules and can be overridden if custom messages are needed
265 'messages' => array(
266 'settings-updated' => __( 'Settings updated.', 'edit-flow' ),
267 'form-error' => __( 'Please correct your form errors below and try again.', 'edit-flow' ),
268 'nonce-failed' => __( 'Cheatin&#8217; uh?', 'edit-flow' ),
269 'invalid-permissions' => __( 'You do not have necessary permissions to complete this action.', 'edit-flow' ),
270 'missing-post' => __( 'Post does not exist', 'edit-flow' ),
271 ),
272 'autoload' => false, // autoloading a module will remove the ability to enable or disable it
273 );
274 if ( isset( $args['messages'] ) )
275 $args['messages'] = array_merge( (array)$args['messages'], $defaults['messages'] );
276 $args = array_merge( $defaults, $args );
277 $args['name'] = $name;
278 $args['options_group_name'] = $this->options_group . $name . '_options';
279 if ( !isset( $args['settings_slug'] ) )
280 $args['settings_slug'] = 'ef-' . $args['slug'] . '-settings';
281 if ( empty( $args['post_type_support'] ) )
282 $args['post_type_support'] = 'ef_' . $name;
283 // If there's a Help Screen registered for the module, make sure we
284 // auto-load it
285 if ( !empty( $args['settings_help_tab'] ) )
286 add_action( 'load-edit-flow_page_' . $args['settings_slug'], array( &$this->$name, 'action_settings_help_menu' ) );
287
288 $this->modules->$name = (object) $args;
289
290 $this->modules_count++;
291
292 /**
293 * Fires after edit_flow has registered a module.
294 *
295 * Plugin authors can hook into this action to trigger functionaltiy after a module has been loaded.
296 *
297 * @param string $name The name of the registered module
298 */
299 do_action( 'ef_module_registered', $name );
300 return $this->modules->$name;
301 }
302
303 /**
304 * Load all of the module options from the database
305 * If a given option isn't yet set, then set it to the module's default (upgrades, etc.)
306 */
307 function load_module_options() {
308
309 foreach ( $this->modules as $mod_name => $mod_data ) {
310
311 $this->modules->$mod_name->options = get_option( $this->options_group . $mod_name . '_options', new stdClass );
312 foreach ( $mod_data->default_options as $default_key => $default_value ) {
313 if ( !isset( $this->modules->$mod_name->options->$default_key ) )
314 $this->modules->$mod_name->options->$default_key = $default_value;
315 }
316
317 $this->$mod_name->module = $this->modules->$mod_name;
318 }
319
320 /**
321 * Fires after edit_flow has loaded all of the module options from the database.
322 *
323 * Plugin authors can hook into this action to read and manipulate module settings.
324 *
325 */
326 do_action( 'ef_module_options_loaded' );
327 }
328
329 /**
330 * Load the post type options again so we give add_post_type_support() a chance to work
331 *
332 * @see http://dev.editflow.org/2011/11/17/edit-flow-v0-7-alpha2-notes/#comment-232
333 */
334 function action_init_after() {
335 foreach ( $this->modules as $mod_name => $mod_data ) {
336
337 if ( isset( $this->modules->$mod_name->options->post_types ) )
338 $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 );
339
340 $this->$mod_name->module = $this->modules->$mod_name;
341 }
342 }
343
344 /**
345 * Get a module by one of its descriptive values
346 *
347 * @param string $key The property to use for searching a module (ex: 'name')
348 * @param string|int|array $value The value to compare (using ==)
349 */
350 function get_module_by( $key, $value ) {
351 $module = false;
352 foreach ( $this->modules as $mod_name => $mod_data ) {
353
354 if ( $key == 'name' && $value == $mod_name ) {
355 $module = $this->modules->$mod_name;
356 } else {
357 foreach( $mod_data as $mod_data_key => $mod_data_value ) {
358 if ( $mod_data_key == $key && $mod_data_value == $value )
359 $module = $this->modules->$mod_name;
360 }
361 }
362 }
363 return $module;
364 }
365
366 /**
367 * Update the $edit_flow object with new value and save to the database
368 */
369 function update_module_option( $mod_name, $key, $value ) {
370 $this->modules->$mod_name->options->$key = $value;
371 $this->$mod_name->module = $this->modules->$mod_name;
372 return update_option( $this->options_group . $mod_name . '_options', $this->modules->$mod_name->options );
373 }
374
375 function update_all_module_options( $mod_name, $new_options ) {
376 if ( is_array( $new_options ) )
377 $new_options = (object)$new_options;
378 $this->modules->$mod_name->options = $new_options;
379 $this->$mod_name->module = $this->modules->$mod_name;
380 return update_option( $this->options_group . $mod_name . '_options', $this->modules->$mod_name->options );
381 }
382
383 /**
384 * Registers commonly used scripts + styles for easy enqueueing
385 */
386 function register_scripts_and_styles() {
387 wp_enqueue_style( 'ef-admin-css', EDIT_FLOW_URL . 'common/css/edit-flow-admin.css', false, EDIT_FLOW_VERSION, 'all' );
388
389 wp_register_script( 'jquery-listfilterizer', EDIT_FLOW_URL . 'common/js/jquery.listfilterizer.js', array( 'jquery' ), EDIT_FLOW_VERSION, true );
390 wp_register_style( 'jquery-listfilterizer', EDIT_FLOW_URL . 'common/css/jquery.listfilterizer.css', false, EDIT_FLOW_VERSION, 'all' );
391
392
393 wp_localize_script( 'jquery-listfilterizer',
394 '__i18n_jquery_filterizer',
395 array(
396 'all' => esc_html__( 'All', 'edit-flow' ),
397 'selected' => esc_html__( 'Selected', 'edit-flow' ),
398 ) );
399
400 wp_register_script( 'jquery-quicksearch', EDIT_FLOW_URL . 'common/js/jquery.quicksearch.js', array( 'jquery' ), EDIT_FLOW_VERSION, true );
401
402 }
403
404 }
405
406 function EditFlow() {
407 return edit_flow::instance();
408 }
409 add_action( 'plugins_loaded', 'EditFlow' );
410