PluginProbe
Edit Flow / 0.9.9
Edit Flow v0.9.9
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.9, at edit_flow.php

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