| @@ -1,482 +1,377 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * Settings module for Edit Flow. | |
| 4 | - * | |
| 5 | - * @package EditFlow | |
| 6 | - */ | |
| 7 | 2 | |
| 8 | -if ( ! class_exists( 'EF_Settings' ) ) { | |
| 3 | +if ( !class_exists('EF_Settings') ) { | |
| 9 | 4 | |
| 5 | +class EF_Settings extends EF_Module { | |
| 6 | + | |
| 7 | + var $module; | |
| 8 | + | |
| 10 | 9 | /** |
| 11 | - * Settings module class for Edit Flow. | |
| 10 | + * Register the module with Edit Flow but don't do anything else | |
| 12 | 11 | */ |
| 13 | - class EF_Settings extends EF_Module { | |
| 12 | + function __construct() { | |
| 13 | + | |
| 14 | + // Register the module with Edit Flow | |
| 15 | + $this->module_url = $this->get_module_url( __FILE__ ); | |
| 16 | + $args = array( | |
| 17 | + 'title' => __( 'Edit Flow', 'edit-flow' ), | |
| 18 | + 'short_description' => __( 'Edit Flow redefines your WordPress publishing workflow.', 'edit-flow' ), | |
| 19 | + 'extended_description' => __( 'Enable any of the features below to take control of your workflow. Custom statuses, email notifications, editorial comments, and more help you and your team save time so everyone can focus on what matters most: the content.', 'edit-flow' ), | |
| 20 | + 'module_url' => $this->module_url, | |
| 21 | + 'img_url' => $this->module_url . 'lib/eflogo_s128.png', | |
| 22 | + 'slug' => 'settings', | |
| 23 | + 'settings_slug' => 'ef-settings', | |
| 24 | + 'default_options' => array( | |
| 25 | + 'enabled' => 'on', | |
| 26 | + ), | |
| 27 | + 'configure_page_cb' => 'print_default_settings', | |
| 28 | + 'autoload' => true, | |
| 29 | + ); | |
| 30 | + $this->module = EditFlow()->register_module( 'settings', $args ); | |
| 31 | + } | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * Initialize the rest of the stuff in the class if the module is active | |
| 35 | + */ | |
| 36 | + function init() { | |
| 37 | + | |
| 38 | + add_action( 'admin_init', array( $this, 'helper_settings_validate_and_save' ), 100 ); | |
| 39 | + | |
| 40 | + add_action( 'admin_print_styles', array( $this, 'action_admin_print_styles' ) ); | |
| 41 | + add_action( 'admin_print_scripts', array( $this, 'action_admin_print_scripts' ) ); | |
| 42 | + add_action( 'admin_enqueue_scripts', array( $this, 'action_admin_enqueue_scripts' ) ); | |
| 43 | + add_action( 'admin_menu', array( $this, 'action_admin_menu' ) ); | |
| 44 | + | |
| 45 | + add_action( 'wp_ajax_change_edit_flow_module_state', array( $this, 'ajax_change_edit_flow_module_state' ) ); | |
| 46 | + | |
| 47 | + } | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * Add necessary things to the admin menu | |
| 51 | + */ | |
| 52 | + function action_admin_menu() { | |
| 53 | + global $edit_flow; | |
| 14 | 54 | |
| 15 | - /** | |
| 16 | - * The module object. | |
| 17 | - * | |
| 18 | - * @var object | |
| 19 | - */ | |
| 20 | - public $module; | |
| 21 | - | |
| 22 | - /** | |
| 23 | - * Validation errors for the settings and term forms, keyed by field name. | |
| 24 | - * | |
| 25 | - * The module form handlers populate this on a failed submission and | |
| 26 | - * helper_print_error_or_description() reads it back when the form re-renders in the | |
| 27 | - * same request. Holding it here rather than on $_REQUEST means a crafted query string | |
| 28 | - * cannot inject fake inline error messages onto the settings screens. | |
| 29 | - * | |
| 30 | - * @var array | |
| 31 | - */ | |
| 32 | - public $form_errors = array(); | |
| 33 | - | |
| 34 | - /** | |
| 35 | - * Register the module with Edit Flow but don't do anything else. | |
| 36 | - */ | |
| 37 | - public function __construct() { | |
| 38 | - // Register the module with Edit Flow. | |
| 39 | - $this->module_url = $this->get_module_url( __FILE__ ); | |
| 40 | - $args = array( | |
| 41 | - 'title' => __( 'Edit Flow', 'edit-flow' ), | |
| 42 | - 'short_description' => __( 'Edit Flow redefines your WordPress publishing workflow.', 'edit-flow' ), | |
| 43 | - 'extended_description' => __( 'Enable any of the features below to take control of your workflow. Custom statuses, email notifications, editorial comments, and more help you and your team save time so everyone can focus on what matters most: the content.', 'edit-flow' ), | |
| 44 | - 'module_url' => $this->module_url, | |
| 45 | - 'img_url' => $this->module_url . 'lib/eflogo_s128.png', | |
| 46 | - 'slug' => 'settings', | |
| 47 | - 'settings_slug' => 'ef-settings', | |
| 48 | - 'default_options' => array( | |
| 49 | - 'enabled' => 'on', | |
| 50 | - ), | |
| 51 | - 'configure_page_cb' => 'print_default_settings', | |
| 52 | - 'autoload' => true, | |
| 53 | - ); | |
| 54 | - $this->module = EditFlow()->register_module( 'settings', $args ); | |
| 55 | + $ef_logo = 'lib/eflogo_s32w.png'; | |
| 56 | + | |
| 57 | + add_menu_page( $this->module->title, $this->module->title, 'manage_options', $this->module->settings_slug, array( $this, 'settings_page_controller' ), $this->module->module_url . $ef_logo ) ; | |
| 58 | + | |
| 59 | + foreach ( $edit_flow->modules as $mod_name => $mod_data ) { | |
| 60 | + if ( isset( $mod_data->options->enabled ) && $mod_data->options->enabled == 'on' | |
| 61 | + && $mod_data->configure_page_cb && $mod_name != $this->module->name ) | |
| 62 | + add_submenu_page( $this->module->settings_slug, $mod_data->title, $mod_data->title, 'manage_options', $mod_data->settings_slug, array( $this, 'settings_page_controller' ) ) ; | |
| 55 | 63 | } |
| 56 | - | |
| 57 | - /** | |
| 58 | - * Initialize the rest of the stuff in the class if the module is active. | |
| 59 | - */ | |
| 60 | - public function init() { | |
| 61 | - add_action( 'admin_init', array( $this, 'helper_settings_validate_and_save' ), 100 ); | |
| 62 | - | |
| 63 | - add_action( 'admin_print_styles', array( $this, 'action_admin_print_styles' ) ); | |
| 64 | - add_action( 'admin_print_scripts', array( $this, 'action_admin_print_scripts' ) ); | |
| 65 | - add_action( 'admin_enqueue_scripts', array( $this, 'action_admin_enqueue_scripts' ) ); | |
| 66 | - add_action( 'admin_menu', array( $this, 'action_admin_menu' ) ); | |
| 67 | - | |
| 68 | - add_action( 'wp_ajax_change_edit_flow_module_state', array( $this, 'ajax_change_edit_flow_module_state' ) ); | |
| 69 | - } | |
| 70 | - | |
| 71 | - /** | |
| 72 | - * Add necessary things to the admin menu. | |
| 73 | - */ | |
| 74 | - public function action_admin_menu() { | |
| 75 | - global $edit_flow; | |
| 76 | - | |
| 77 | - $ef_logo = 'lib/eflogo_s32w.png'; | |
| 78 | - | |
| 79 | - add_menu_page( $this->module->title, $this->module->title, 'manage_options', $this->module->settings_slug, array( $this, 'settings_page_controller' ), $this->module->module_url . $ef_logo ); | |
| 80 | - | |
| 81 | - // Add "Features" as the first submenu item (replaces the duplicate "Edit Flow" item). | |
| 82 | - add_submenu_page( $this->module->settings_slug, __( 'Features', 'edit-flow' ), __( 'Features', 'edit-flow' ), 'manage_options', $this->module->settings_slug, array( $this, 'settings_page_controller' ) ); | |
| 83 | - | |
| 84 | - foreach ( $edit_flow->modules as $mod_name => $mod_data ) { | |
| 85 | - if ( isset( $mod_data->options->enabled ) && 'on' == $mod_data->options->enabled | |
| 86 | - && $mod_data->configure_page_cb && $mod_name != $this->module->name ) { | |
| 87 | - add_submenu_page( $this->module->settings_slug, $mod_data->title, $mod_data->title, 'manage_options', $mod_data->settings_slug, array( $this, 'settings_page_controller' ) ); | |
| 88 | - } | |
| 89 | - } | |
| 90 | - } | |
| 91 | - | |
| 92 | - /** | |
| 93 | - * Enqueue scripts for the settings page. | |
| 94 | - */ | |
| 95 | - public function action_admin_enqueue_scripts() { | |
| 96 | - if ( $this->is_whitelisted_settings_view() ) { | |
| 97 | - wp_enqueue_script( 'edit-flow-settings-js', $this->module_url . 'lib/settings.js', array( 'jquery' ), EDIT_FLOW_VERSION, true ); | |
| 98 | - } | |
| 99 | - } | |
| 100 | - | |
| 101 | - /** | |
| 102 | - * Add settings styles to the settings page. | |
| 103 | - */ | |
| 104 | - public function action_admin_print_styles() { | |
| 105 | - if ( $this->is_whitelisted_settings_view() ) { | |
| 106 | - wp_enqueue_style( 'edit_flow-settings-css', $this->module_url . 'lib/settings.css', false, EDIT_FLOW_VERSION ); | |
| 107 | - } | |
| 108 | - } | |
| 109 | - | |
| 110 | - /** | |
| 111 | - * Extra data we need on the page for transitions, etc. | |
| 112 | - * | |
| 113 | - * @since 0.7 | |
| 114 | - */ | |
| 115 | - public function action_admin_print_scripts() { | |
| 116 | - ?> | |
| 64 | + } | |
| 65 | + | |
| 66 | + function action_admin_enqueue_scripts() { | |
| 67 | + | |
| 68 | + if ( $this->is_whitelisted_settings_view() ) | |
| 69 | + wp_enqueue_script( 'edit-flow-settings-js', $this->module_url . 'lib/settings.js', array( 'jquery' ), EDIT_FLOW_VERSION, true ); | |
| 70 | + | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * Add settings styles to the settings page | |
| 75 | + */ | |
| 76 | + function action_admin_print_styles() { | |
| 77 | + | |
| 78 | + if ( $this->is_whitelisted_settings_view() ) | |
| 79 | + wp_enqueue_style( 'edit_flow-settings-css', $this->module_url . 'lib/settings.css', false, EDIT_FLOW_VERSION ); | |
| 80 | + | |
| 81 | + | |
| 82 | + } | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * Extra data we need on the page for transitions, etc. | |
| 86 | + * | |
| 87 | + * @since 0.7 | |
| 88 | + */ | |
| 89 | + function action_admin_print_scripts() { | |
| 90 | + ?> | |
| 117 | 91 | <script type="text/javascript"> |
| 118 | - var ef_admin_url = '<?php echo esc_url( get_admin_url() ); ?>'; | |
| 92 | + var ef_admin_url = '<?php echo get_admin_url(); ?>'; | |
| 119 | 93 | </script> |
| 120 | - <?php | |
| 121 | - } | |
| 122 | - | |
| 123 | - /** | |
| 124 | - * AJAX handler to enable or disable an Edit Flow module. | |
| 125 | - */ | |
| 126 | - public function ajax_change_edit_flow_module_state() { | |
| 127 | - global $edit_flow; | |
| 128 | - | |
| 129 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonces don't need sanitization, just verification. | |
| 130 | - if ( ! isset( $_POST['change_module_nonce'] ) || ! wp_verify_nonce( $_POST['change_module_nonce'], 'change-edit-flow-module-nonce' ) || ! current_user_can( 'manage_options' ) ) { | |
| 131 | - wp_die( esc_html__( 'Cheatin’ uh?', 'edit-flow' ) ); | |
| 132 | - } | |
| 133 | - | |
| 134 | - if ( ! isset( $_POST['module_action'], $_POST['slug'] ) ) { | |
| 135 | - wp_die( '-1' ); | |
| 136 | - } | |
| 137 | - | |
| 138 | - $module_action = sanitize_key( $_POST['module_action'] ); | |
| 139 | - $slug = sanitize_key( $_POST['slug'] ); | |
| 140 | - | |
| 141 | - $module = $edit_flow->get_module_by( 'slug', $slug ); | |
| 142 | - | |
| 143 | - if ( ! $module ) { | |
| 144 | - wp_die( '-1' ); | |
| 145 | - } | |
| 146 | - | |
| 147 | - $return = false; | |
| 148 | - | |
| 149 | - if ( 'enable' === $module_action ) { | |
| 150 | - $return = $edit_flow->update_module_option( $module->name, 'enabled', 'on' ); | |
| 151 | - } elseif ( 'disable' === $module_action ) { | |
| 152 | - $return = $edit_flow->update_module_option( $module->name, 'enabled', 'off' ); | |
| 153 | - } | |
| 154 | - | |
| 155 | - if ( $return ) { | |
| 156 | - wp_die( '1' ); | |
| 157 | - } else { | |
| 158 | - wp_die( '-1' ); | |
| 159 | - } | |
| 160 | - } | |
| 161 | - | |
| 162 | - /** | |
| 163 | - * Handles all settings and configuration page requests. Required element for Edit Flow. | |
| 164 | - * | |
| 165 | - * phpcs:disable WordPress.Security.NonceVerification.Recommended -- Rendering only, no data modification. | |
| 166 | - */ | |
| 167 | - public function settings_page_controller() { | |
| 168 | - global $edit_flow; | |
| 169 | - | |
| 170 | - $page_requested = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : 'settings'; | |
| 171 | - // phpcs:enable WordPress.Security.NonceVerification | |
| 172 | - $requested_module = $edit_flow->get_module_by( 'settings_slug', $page_requested ); | |
| 173 | - if ( ! $requested_module ) { | |
| 174 | - wp_die( esc_html__( 'Not a registered Edit Flow module', 'edit-flow' ) ); | |
| 175 | - } | |
| 176 | - | |
| 177 | - $configure_callback = $requested_module->configure_page_cb; | |
| 178 | - $requested_module_name = $requested_module->name; | |
| 179 | - | |
| 180 | - // Don't show the settings page for the module if the module isn't activated. | |
| 181 | - if ( ! $this->module_enabled( $requested_module_name ) ) { | |
| 182 | - /* translators: 1: link to the settings page for Edit Flow */ | |
| 183 | - echo '<div class="message error"><p>' . wp_kses( sprintf( __( 'Module not enabled. Please enable it from the <a href="%1$s">Edit Flow settings page</a>.', 'edit-flow' ), esc_url( EDIT_FLOW_SETTINGS_PAGE ) ), 'a' ) . '</p></div>'; | |
| 184 | - return; | |
| 185 | - } | |
| 186 | - | |
| 187 | - $this->print_default_header( $requested_module ); | |
| 188 | - $edit_flow->$requested_module_name->$configure_callback(); | |
| 189 | - $this->print_default_footer( $requested_module ); | |
| 190 | - } | |
| 191 | - | |
| 192 | - /** | |
| 193 | - * Print the default header for the settings page. | |
| 194 | - * | |
| 195 | - * Nonce verification is not available here - it's just rendering. The actual save | |
| 196 | - * is done in helper_settings_validate_and_save and that's guarded well. | |
| 197 | - * | |
| 198 | - * @param object $current_module The current module being displayed. | |
| 199 | - * | |
| 200 | - * phpcs:disable WordPress.Security.NonceVerification | |
| 201 | - */ | |
| 202 | - public function print_default_header( $current_module ) { | |
| 203 | - // Register admin notices for standard WordPress display. | |
| 204 | - if ( isset( $_GET['message'] ) ) { | |
| 205 | - $message = sanitize_key( $_GET['message'] ); | |
| 206 | - } elseif ( isset( $_REQUEST['message'] ) ) { | |
| 207 | - $message = sanitize_key( $_REQUEST['message'] ); | |
| 208 | - } elseif ( isset( $_POST['message'] ) ) { | |
| 209 | - $message = sanitize_key( $_POST['message'] ); | |
| 210 | - } else { | |
| 211 | - $message = false; | |
| 212 | - } | |
| 213 | - if ( $message && isset( $current_module->messages[ $message ] ) ) { | |
| 214 | - add_settings_error( | |
| 215 | - 'edit-flow', | |
| 216 | - 'edit-flow-' . $message, | |
| 217 | - $current_module->messages[ $message ], | |
| 218 | - 'success' | |
| 219 | - ); | |
| 220 | - } | |
| 221 | - | |
| 222 | - // If there's been an error, register it as an admin notice. | |
| 223 | - if ( isset( $_GET['error'] ) ) { | |
| 224 | - $error = sanitize_key( $_GET['error'] ); | |
| 225 | - } elseif ( isset( $_REQUEST['error'] ) ) { | |
| 226 | - $error = sanitize_key( $_REQUEST['error'] ); | |
| 227 | - } elseif ( isset( $_POST['error'] ) ) { | |
| 228 | - $error = sanitize_key( $_POST['error'] ); | |
| 229 | - } else { | |
| 230 | - $error = false; | |
| 231 | - } | |
| 232 | - if ( $error && isset( $current_module->messages[ $error ] ) ) { | |
| 233 | - add_settings_error( | |
| 234 | - 'edit-flow', | |
| 235 | - 'edit-flow-' . $error, | |
| 236 | - $current_module->messages[ $error ], | |
| 237 | - 'error' | |
| 238 | - ); | |
| 239 | - } | |
| 240 | - | |
| 241 | - // Build the page title. | |
| 242 | - if ( 'settings' !== $current_module->name ) { | |
| 243 | - $page_title = sprintf( | |
| 244 | - /* translators: %s: module title */ | |
| 245 | - __( 'Edit Flow: %s', 'edit-flow' ), | |
| 246 | - $current_module->title | |
| 247 | - ); | |
| 248 | - } else { | |
| 249 | - $page_title = __( 'Edit Flow: Features', 'edit-flow' ); | |
| 250 | - } | |
| 251 | - ?> | |
| 94 | + <?php | |
| 95 | + } | |
| 96 | + | |
| 97 | + function ajax_change_edit_flow_module_state() { | |
| 98 | + global $edit_flow; | |
| 99 | + | |
| 100 | + if ( !wp_verify_nonce( $_POST['change_module_nonce'], 'change-edit-flow-module-nonce' ) || !current_user_can( 'manage_options') ) | |
| 101 | + wp_die( __( 'Cheatin’ uh?' ) ); | |
| 102 | + | |
| 103 | + if ( !isset( $_POST['module_action'], $_POST['slug'] ) ) | |
| 104 | + die('-1'); | |
| 105 | + | |
| 106 | + $module_action = sanitize_key( $_POST['module_action'] ); | |
| 107 | + $slug = sanitize_key( $_POST['slug'] ); | |
| 108 | + | |
| 109 | + $module = $edit_flow->get_module_by( 'slug', $slug ); | |
| 110 | + | |
| 111 | + if ( !$module ) | |
| 112 | + die('-1'); | |
| 113 | + | |
| 114 | + if ( $module_action == 'enable' ) | |
| 115 | + $return = $edit_flow->update_module_option( $module->name, 'enabled', 'on' ); | |
| 116 | + else if ( $module_action == 'disable' ) | |
| 117 | + $return = $edit_flow->update_module_option( $module->name, 'enabled', 'off' ); | |
| 118 | + | |
| 119 | + if ( $return ) | |
| 120 | + die('1'); | |
| 121 | + else | |
| 122 | + die('-1'); | |
| 123 | + } | |
| 124 | + | |
| 125 | + /** | |
| 126 | + * Handles all settings and configuration page requests. Required element for Edit Flow | |
| 127 | + */ | |
| 128 | + function settings_page_controller() { | |
| 129 | + global $edit_flow; | |
| 130 | + | |
| 131 | + $requested_module = $edit_flow->get_module_by( 'settings_slug', $_GET['page'] ); | |
| 132 | + if ( !$requested_module ) | |
| 133 | + wp_die( __( 'Not a registered Edit Flow module', 'edit-flow' ) ); | |
| 134 | + $configure_callback = $requested_module->configure_page_cb; | |
| 135 | + $requested_module_name = $requested_module->name; | |
| 136 | + | |
| 137 | + // Don't show the settings page for the module if the module isn't activated | |
| 138 | + if ( !$this->module_enabled( $requested_module_name ) ) { | |
| 139 | + echo '<div class="message error"><p>' . sprintf( __( 'Module not enabled. Please enable it from the <a href="%1$s">Edit Flow settings page</a>.', 'edit-flow' ), EDIT_FLOW_SETTINGS_PAGE ) . '</p></div>'; | |
| 140 | + return; | |
| 141 | + } | |
| 142 | + | |
| 143 | + $this->print_default_header( $requested_module ); | |
| 144 | + $edit_flow->$requested_module_name->$configure_callback(); | |
| 145 | + $this->print_default_footer( $requested_module ); | |
| 146 | + | |
| 147 | + } | |
| 148 | + | |
| 149 | + /** | |
| 150 | + * | |
| 151 | + */ | |
| 152 | + function print_default_header( $current_module ) { | |
| 153 | + | |
| 154 | + // If there's been a message, let's display it | |
| 155 | + if ( isset( $_GET['message'] ) ) | |
| 156 | + $message = $_GET['message']; | |
| 157 | + else if ( isset( $_REQUEST['message'] ) ) | |
| 158 | + $message = $_REQUEST['message']; | |
| 159 | + else if ( isset( $_POST['message'] ) ) | |
| 160 | + $message = $_POST['message']; | |
| 161 | + else | |
| 162 | + $message = false; | |
| 163 | + if ( $message && isset( $current_module->messages[$message] ) ) | |
| 164 | + $display_text = '<span class="edit-flow-updated-message edit-flow-message">' . esc_html( $current_module->messages[$message] ) . '</span>'; | |
| 165 | + | |
| 166 | + // If there's been an error, let's display it | |
| 167 | + if ( isset( $_GET['error'] ) ) | |
| 168 | + $error = $_GET['error']; | |
| 169 | + else if ( isset( $_REQUEST['error'] ) ) | |
| 170 | + $error = $_REQUEST['error']; | |
| 171 | + else if ( isset( $_POST['error'] ) ) | |
| 172 | + $error = $_POST['error']; | |
| 173 | + else | |
| 174 | + $error = false; | |
| 175 | + if ( $error && isset( $current_module->messages[$error] ) ) | |
| 176 | + $display_text = '<span class="edit-flow-error-message edit-flow-message">' . esc_html( $current_module->messages[$error] ) . '</span>'; | |
| 177 | + | |
| 178 | + if ( $current_module->img_url ) | |
| 179 | + $page_icon = '<img src="' . esc_url( $current_module->img_url ) . '" class="module-icon icon32" />'; | |
| 180 | + else | |
| 181 | + $page_icon = '<div class="icon32" id="icon-options-general"><br/></div>'; | |
| 182 | + ?> | |
| 252 | 183 | <div class="wrap edit-flow-admin"> |
| 253 | - <h1><?php echo esc_html( $page_title ); ?></h1> | |
| 254 | - <?php settings_errors( 'edit-flow' ); ?> | |
| 255 | - | |
| 256 | - <?php if ( $current_module->short_description || $current_module->extended_description ) : ?> | |
| 184 | + <?php if ( $current_module->name != 'settings' ): ?> | |
| 185 | + <?php echo $page_icon; ?> | |
| 186 | + <h2><a href="<?php echo EDIT_FLOW_SETTINGS_PAGE; ?>"><?php _e('Edit Flow', 'edit-flow') ?></a>: <?php echo $current_module->title; ?><?php if ( isset( $display_text ) ) { echo $display_text; } ?></h2> | |
| 187 | + <?php else: ?> | |
| 188 | + <?php echo $page_icon; ?> | |
| 189 | + <h2><?php _e('Edit Flow', 'edit-flow') ?><?php if ( isset( $display_text ) ) { echo $display_text; } ?></h2> | |
| 190 | + <?php endif; ?> | |
| 191 | + | |
| 257 | 192 | <div class="explanation"> |
| 258 | - <?php if ( $current_module->short_description ) : ?> | |
| 259 | - <p class="description"><?php echo wp_kses_post( $current_module->short_description ); ?></p> | |
| 193 | + <?php if ( $current_module->short_description ): ?> | |
| 194 | + <h3><?php echo $current_module->short_description; ?></h3> | |
| 260 | 195 | <?php endif; ?> |
| 261 | - <?php if ( $current_module->extended_description ) : ?> | |
| 262 | - <p><?php echo wp_kses_post( $current_module->extended_description ); ?></p> | |
| 263 | - <?php endif; ?> | |
| 196 | + <?php if ( $current_module->extended_description ): ?> | |
| 197 | + <p><?php echo $current_module->extended_description; ?></p> | |
| 198 | + <?php endif; ?> | |
| 264 | 199 | </div> |
| 265 | - <?php endif; ?> | |
| 266 | - <?php | |
| 267 | - } | |
| 268 | - // phpcs:enable WordPress.Security.NonceVerification | |
| 269 | - | |
| 270 | - /** | |
| 271 | - * Adds Settings page for Edit Flow. | |
| 272 | - */ | |
| 273 | - public function print_default_settings() { | |
| 274 | - ?> | |
| 200 | + <?php | |
| 201 | + } | |
| 202 | + | |
| 203 | + /** | |
| 204 | + * Adds Settings page for Edit Flow. | |
| 205 | + */ | |
| 206 | + function print_default_settings() { | |
| 207 | + | |
| 208 | + ?> | |
| 275 | 209 | <div class="edit-flow-modules"> |
| 276 | 210 | <?php $this->print_modules(); ?> |
| 277 | 211 | </div> |
| 278 | - <form class="basic-settings" action="<?php echo esc_url( menu_page_url( $this->module->settings_slug, false ) ); ?>" method="post"> | |
| 279 | - <?php settings_fields( $this->module->options_group_name ); ?> | |
| 280 | - <?php do_settings_sections( $this->module->options_group_name ); ?> | |
| 281 | - <input id="edit_flow_module_name" name="edit_flow_module_name" type="hidden" value="<?php echo esc_attr( $this->module->name ); ?>" /> | |
| 282 | - <?php submit_button(); ?> | |
| 283 | - </form> | |
| 284 | - <?php | |
| 285 | - } | |
| 212 | + <?php | |
| 213 | + } | |
| 214 | + | |
| 215 | + function print_default_footer( $current_module ) { | |
| 216 | + ?> | |
| 217 | + <?php if ( $current_module->slug == 'settings' ): ?> | |
| 218 | + <div class="credits"> | |
| 219 | + <p><?php echo __( '<a href="http://editflow.org/">Edit Flow</a> is produced by <a href="http://danielbachhuber.com/">Daniel Bachhuber</a>, <a href="http://digitalize.ca/">Mo Jangda</a>, and <a href="http://www.scottbressler.com/blog/">Scott Bressler</a>, with special help from <a href="http://andrewspittle.net">Andrew Spittle</a> and <a href="http://andrewwitherspoon.com/">Andrew Witherspoon</a>.', 'edit-flow' ); ?> | |
| 220 | + <br /><?php echo sprintf( __( 'You\'re using Edit Flow version %s.', 'edit-flow' ), EDIT_FLOW_VERSION ); ?> | |
| 221 | + <br /><?php echo __( 'Icons courtesy of the <a href="http://thenounproject.com/">Noun Project</a>.', 'edit-flow' ); ?> | |
| 222 | + <br /><?php echo __( '<a href="http://wordpress.org/tags/edit-flow?forum_id=10">Please give us your feedback, ideas, bug reports and comments</a> in the WordPress.org forums.', 'edit-flow' ); ?> | |
| 223 | + </div> | |
| 224 | + </div> | |
| 225 | + <?php endif; ?> | |
| 226 | + <?php | |
| 227 | + } | |
| 286 | 228 | |
| 287 | - /** | |
| 288 | - * Print the default footer for the settings page. | |
| 289 | - * | |
| 290 | - * @param object $current_module The current module being displayed. | |
| 291 | - */ | |
| 292 | - public function print_default_footer( $current_module ) { | |
| 293 | - ?> | |
| 294 | - </div> | |
| 295 | - <?php | |
| 296 | - } | |
| 229 | + function print_modules() { | |
| 230 | + global $edit_flow; | |
| 297 | 231 | |
| 298 | - /** | |
| 299 | - * Print the list of Edit Flow modules on the settings page. | |
| 300 | - */ | |
| 301 | - public function print_modules() { | |
| 302 | - global $edit_flow; | |
| 232 | + if ( ! $edit_flow->modules_count ) { | |
| 233 | + echo '<div class="message error">' . __( 'There are no Edit Flow modules registered', 'edit-flow' ) . '</div>'; | |
| 234 | + } else { | |
| 303 | 235 | |
| 304 | - if ( ! $edit_flow->modules_count ) { | |
| 305 | - echo '<div class="message error">' . esc_html__( 'There are no Edit Flow modules registered', 'edit-flow' ) . '</div>'; | |
| 306 | - } else { | |
| 307 | - foreach ( $edit_flow->modules as $mod_name => $mod_data ) { | |
| 308 | - if ( $mod_data->autoload ) { | |
| 309 | - continue; | |
| 310 | - } | |
| 236 | + foreach ( $edit_flow->modules as $mod_name => $mod_data ) { | |
| 237 | + if ( $mod_data->autoload ) | |
| 238 | + continue; | |
| 311 | 239 | |
| 312 | - $classes = array( | |
| 313 | - 'edit-flow-module', | |
| 314 | - ); | |
| 315 | - if ( 'on' == $mod_data->options->enabled ) { | |
| 316 | - $classes[] = 'module-enabled'; | |
| 317 | - } elseif ( 'off' == $mod_data->options->enabled ) { | |
| 318 | - $classes[] = 'module-disabled'; | |
| 319 | - } | |
| 320 | - if ( $mod_data->configure_page_cb ) { | |
| 321 | - $classes[] = 'has-configure-link'; | |
| 322 | - } | |
| 323 | - echo '<div class="' . esc_attr( implode( ' ', $classes ) ) . '" id="' . esc_attr( $mod_data->slug ) . '">'; | |
| 324 | - if ( $mod_data->img_url ) { | |
| 325 | - echo '<img src="' . esc_url( $mod_data->img_url ) . '" height="24px" width="24px" class="float-right module-icon" />'; | |
| 326 | - } | |
| 327 | - echo '<form method="get" action="' . esc_url( get_admin_url( null, 'options.php' ) ) . '">'; | |
| 328 | - echo '<h4>' . esc_html( $mod_data->title ) . '</h4>'; | |
| 329 | - echo '<p>' . wp_kses( $mod_data->short_description, 'post' ) . '</p>'; | |
| 330 | - echo '<p class="edit-flow-module-actions">'; | |
| 331 | - if ( $mod_data->configure_page_cb ) { | |
| 332 | - $configure_url = add_query_arg( 'page', $mod_data->settings_slug, get_admin_url( null, 'admin.php' ) ); | |
| 333 | - echo '<a href="' . esc_url( $configure_url ) . '" class="configure-edit-flow-module'; | |
| 334 | - if ( 'off' == $mod_data->options->enabled ) { | |
| 335 | - echo ' hidden" style="display:none;'; | |
| 336 | - } | |
| 337 | - // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText -- Dynamic configure link text. | |
| 338 | - echo '">' . esc_html__( $mod_data->configure_link_text, 'edit-flow' ) . '</a>'; | |
| 339 | - } | |
| 340 | - echo '<input type="submit" class="button-primary button enable-disable-edit-flow-module"'; | |
| 341 | - if ( 'on' == $mod_data->options->enabled ) { | |
| 342 | - echo ' style="display:none;"'; | |
| 343 | - } | |
| 344 | - echo ' value="' . esc_textarea( __( 'Enable', 'edit-flow' ) ) . '" />'; | |
| 345 | - echo '<input type="submit" class="button-secondary button-remove button enable-disable-edit-flow-module"'; | |
| 346 | - if ( 'off' == $mod_data->options->enabled ) { | |
| 347 | - echo ' style="display:none;"'; | |
| 348 | - } | |
| 349 | - echo ' value="' . esc_textarea( __( 'Disable', 'edit-flow' ) ) . '" />'; | |
| 350 | - echo '</p>'; | |
| 351 | - wp_nonce_field( 'change-edit-flow-module-nonce', 'change-module-nonce-' . $mod_data->slug, false ); | |
| 352 | - echo '</form>'; | |
| 353 | - echo '</div>'; | |
| 240 | + $classes = array( | |
| 241 | + 'edit-flow-module', | |
| 242 | + ); | |
| 243 | + if ( $mod_data->options->enabled == 'on' ) | |
| 244 | + $classes[] = 'module-enabled'; | |
| 245 | + elseif ( $mod_data->options->enabled == 'off' ) | |
| 246 | + $classes[] = 'module-disabled'; | |
| 247 | + if ( $mod_data->configure_page_cb ) | |
| 248 | + $classes[] = 'has-configure-link'; | |
| 249 | + echo '<div class="' . implode( ' ', $classes ) . '" id="' . $mod_data->slug . '">'; | |
| 250 | + if ( $mod_data->img_url ) | |
| 251 | + echo '<img src="' . esc_url( $mod_data->img_url ) . '" height="24px" width="24px" class="float-right module-icon" />'; | |
| 252 | + echo '<form method="get" action="' . get_admin_url( null, 'options.php' ) . '">'; | |
| 253 | + echo '<h4>' . esc_html( $mod_data->title ) . '</h4>'; | |
| 254 | + if ( 'on' == $mod_data->options->enabled ) | |
| 255 | + echo '<p>' . wp_kses($mod_data->short_description, 'a') . '</p>'; | |
| 256 | + else | |
| 257 | + echo '<p>' . strip_tags( $mod_data->short_description ) . '</p>'; | |
| 258 | + echo '<p class="edit-flow-module-actions">'; | |
| 259 | + if ( $mod_data->configure_page_cb ) { | |
| 260 | + $configure_url = add_query_arg( 'page', $mod_data->settings_slug, get_admin_url( null, 'admin.php' ) ); | |
| 261 | + echo '<a href="' . $configure_url . '" class="configure-edit-flow-module button button-primary'; | |
| 262 | + if ( $mod_data->options->enabled == 'off' ) echo ' hidden" style="display:none;'; | |
| 263 | + echo '">' . $mod_data->configure_link_text . '</a>'; | |
| 354 | 264 | } |
| 265 | + echo '<input type="submit" class="button-primary button enable-disable-edit-flow-module"'; | |
| 266 | + if ( $mod_data->options->enabled == 'on' ) echo ' style="display:none;"'; | |
| 267 | + echo ' value="' . __( 'Enable', 'edit-flow' ) . '" />'; | |
| 268 | + echo '<input type="submit" class="button-secondary button-remove button enable-disable-edit-flow-module"'; | |
| 269 | + if ( $mod_data->options->enabled == 'off' ) echo ' style="display:none;"'; | |
| 270 | + echo ' value="' . __( 'Disable', 'edit-flow' ) . '" />'; | |
| 271 | + echo '</p>'; | |
| 272 | + wp_nonce_field( 'change-edit-flow-module-nonce', 'change-module-nonce', false ); | |
| 273 | + echo '</form>'; | |
| 274 | + echo '</div>'; | |
| 355 | 275 | } |
| 276 | + | |
| 356 | 277 | } |
| 357 | - | |
| 358 | - /** | |
| 359 | - * Given a form field and a description, prints either the error associated with the field or the description. | |
| 360 | - * | |
| 361 | - * @since 0.7 | |
| 362 | - * | |
| 363 | - * @param string $field The form field for which to check for an error. | |
| 364 | - * @param string $description Unlocalized string to display if there was no error with the given field. | |
| 365 | - */ | |
| 366 | - public function helper_print_error_or_description( $field, $description ) { | |
| 367 | - if ( isset( $this->form_errors[ $field ] ) ) : | |
| 368 | - ?> | |
| 278 | + | |
| 279 | + } | |
| 280 | + | |
| 281 | + /** | |
| 282 | + * Given a form field and a description, prints either the error associated with the field or the description. | |
| 283 | + * | |
| 284 | + * @since 0.7 | |
| 285 | + * | |
| 286 | + * @param string $field The form field for which to check for an error | |
| 287 | + * @param string $description Unlocalized string to display if there was no error with the given field | |
| 288 | + */ | |
| 289 | + function helper_print_error_or_description( $field, $description ) { | |
| 290 | + if ( isset( $_REQUEST['form-errors'][$field] ) ): ?> | |
| 369 | 291 | <div class="form-error"> |
| 370 | - <p><?php echo esc_html( $this->form_errors[ $field ] ); ?></p> | |
| 292 | + <p><?php echo esc_html( $_REQUEST['form-errors'][$field] ); ?></p> | |
| 371 | 293 | </div> |
| 372 | - <?php else : ?> | |
| 294 | + <?php else: ?> | |
| 373 | 295 | <p class="description"><?php echo esc_html( $description ); ?></p> |
| 374 | - <?php | |
| 375 | - endif; | |
| 296 | + <?php endif; | |
| 297 | + } | |
| 298 | + | |
| 299 | + /** | |
| 300 | + * Generate an option field to turn post type support on/off for a given module | |
| 301 | + * | |
| 302 | + * @param object $module Edit Flow module we're generating the option field for | |
| 303 | + * @param {missing} | |
| 304 | + * | |
| 305 | + * @since 0.7 | |
| 306 | + */ | |
| 307 | + function helper_option_custom_post_type( $module, $args = array() ) { | |
| 308 | + | |
| 309 | + $all_post_types = array( | |
| 310 | + 'post' => __( 'Posts' ), | |
| 311 | + 'page' => __( 'Pages' ), | |
| 312 | + ); | |
| 313 | + $custom_post_types = $this->get_supported_post_types_for_module(); | |
| 314 | + if ( count( $custom_post_types ) ) { | |
| 315 | + foreach( $custom_post_types as $custom_post_type => $args ) { | |
| 316 | + $all_post_types[$custom_post_type] = $args->label; | |
| 317 | + } | |
| 376 | 318 | } |
| 377 | 319 | |
| 378 | - /** | |
| 379 | - * Generate an option field to turn post type support on/off for a given module. | |
| 380 | - * | |
| 381 | - * @since 0.7 | |
| 382 | - * | |
| 383 | - * @param object $module Edit Flow module we're generating the option field for. | |
| 384 | - * @param array $args Optional. Additional arguments. | |
| 385 | - */ | |
| 386 | - public function helper_option_custom_post_type( $module, $args = array() ) { | |
| 387 | - | |
| 388 | - $all_post_types = array( | |
| 389 | - 'post' => __( 'Posts', 'edit-flow' ), | |
| 390 | - 'page' => __( 'Pages', 'edit-flow' ), | |
| 391 | - ); | |
| 392 | - $custom_post_types = $this->get_supported_post_types_for_module(); | |
| 393 | - if ( count( $custom_post_types ) ) { | |
| 394 | - foreach ( $custom_post_types as $custom_post_type => $args ) { | |
| 395 | - $all_post_types[ $custom_post_type ] = $args->label; | |
| 396 | - } | |
| 397 | - } | |
| 398 | - | |
| 399 | - foreach ( $all_post_types as $post_type => $title ) { | |
| 400 | - echo '<label for="' . esc_attr( $post_type ) . '">'; | |
| 401 | - echo '<input id="' . esc_attr( $post_type ) . '" name="' | |
| 402 | - . esc_attr( $module->options_group_name ) . '[post_types][' . esc_attr( $post_type ) . ']"'; | |
| 403 | - if ( isset( $module->options->post_types[ $post_type ] ) ) { | |
| 404 | - checked( $module->options->post_types[ $post_type ], 'on' ); | |
| 405 | - } | |
| 406 | - // Defining post_type_supports in the functions.php file or similar should disable the checkbox. | |
| 407 | - disabled( post_type_supports( $post_type, $module->post_type_support ), true ); | |
| 408 | - echo ' type="checkbox" /> ' . esc_html( $title ) . '</label>'; | |
| 409 | - // Leave a note to the admin as a reminder that add_post_type_support has been used somewhere in their code. | |
| 410 | - if ( post_type_supports( $post_type, $module->post_type_support ) ) { | |
| 411 | - /* translators: 1: post type, 2: post type support */ | |
| 412 | - echo '  <span class="description">' . esc_html( sprintf( __( 'Disabled because add_post_type_support( \'%1$s\', \'%2$s\' ) is included in a loaded file.', 'edit-flow' ), $post_type, $module->post_type_support ) ) . '</span>'; | |
| 413 | - } | |
| 414 | - echo '<br />'; | |
| 415 | - } | |
| 320 | + foreach( $all_post_types as $post_type => $title ) { | |
| 321 | + echo '<label for="' . esc_attr( $post_type ) . '">'; | |
| 322 | + echo '<input id="' . esc_attr( $post_type ) . '" name="' | |
| 323 | + . $module->options_group_name . '[post_types][' . esc_attr( $post_type ) . ']"'; | |
| 324 | + if ( isset( $module->options->post_types[$post_type] ) ) | |
| 325 | + checked( $module->options->post_types[$post_type], 'on' ); | |
| 326 | + // Defining post_type_supports in the functions.php file or similar should disable the checkbox | |
| 327 | + disabled( post_type_supports( $post_type, $module->post_type_support ), true ); | |
| 328 | + echo ' type="checkbox" /> ' . esc_html( $title ) . '</label>'; | |
| 329 | + // Leave a note to the admin as a reminder that add_post_type_support has been used somewhere in their code | |
| 330 | + if ( post_type_supports( $post_type, $module->post_type_support ) ) | |
| 331 | + echo '  <span class="description">' . sprintf( __( 'Disabled because add_post_type_support( \'%1$s\', \'%2$s\' ) is included in a loaded file.', 'edit-flow' ), $post_type, $module->post_type_support ) . '</span>'; | |
| 332 | + echo '<br />'; | |
| 416 | 333 | } |
| 334 | + | |
| 335 | + } | |
| 336 | + | |
| 337 | + /** | |
| 338 | + * Validation and sanitization on the settings field | |
| 339 | + * This method is called automatically/ doesn't need to be registered anywhere | |
| 340 | + * | |
| 341 | + * @since 0.7 | |
| 342 | + */ | |
| 343 | + function helper_settings_validate_and_save() { | |
| 344 | + | |
| 345 | + if ( !isset( $_POST['action'], $_POST['_wpnonce'], $_POST['option_page'], $_POST['_wp_http_referer'], $_POST['edit_flow_module_name'], $_POST['submit'] ) || !is_admin() ) | |
| 346 | + return false; | |
| 347 | + | |
| 348 | + global $edit_flow; | |
| 349 | + $module_name = sanitize_key( $_POST['edit_flow_module_name'] ); | |
| 350 | + | |
| 351 | + if ( $_POST['action'] != 'update' | |
| 352 | + || $_POST['option_page'] != $edit_flow->$module_name->module->options_group_name ) | |
| 353 | + return false; | |
| 354 | + | |
| 355 | + if ( !current_user_can( 'manage_options' ) || !wp_verify_nonce( $_POST['_wpnonce'], $edit_flow->$module_name->module->options_group_name . '-options' ) ) | |
| 356 | + wp_die( __( 'Cheatin’ uh?' ) ); | |
| 357 | + | |
| 358 | + $new_options = ( isset( $_POST[$edit_flow->$module_name->module->options_group_name] ) ) ? $_POST[$edit_flow->$module_name->module->options_group_name] : array(); | |
| 417 | 359 | |
| 418 | - /** | |
| 419 | - * Validation and sanitization on the settings field. | |
| 420 | - * | |
| 421 | - * This method is called automatically and doesn't need to be registered anywhere. | |
| 422 | - * | |
| 423 | - * @since 0.7 | |
| 424 | - * | |
| 425 | - * @return false|void Returns false if validation fails, otherwise redirects. | |
| 426 | - */ | |
| 427 | - public function helper_settings_validate_and_save() { | |
| 360 | + // Only call the validation callback if it exists? | |
| 361 | + if ( method_exists( $edit_flow->$module_name, 'settings_validate' ) ) | |
| 362 | + $new_options = $edit_flow->$module_name->settings_validate( $new_options ); | |
| 363 | + | |
| 364 | + // Cast our object and save the data. | |
| 365 | + $new_options = (object)array_merge( (array)$edit_flow->$module_name->module->options, $new_options ); | |
| 366 | + $edit_flow->update_all_module_options( $edit_flow->$module_name->module->name, $new_options ); | |
| 367 | + | |
| 368 | + // Redirect back to the settings page that was submitted without any previous messages | |
| 369 | + $goback = add_query_arg( 'message', 'settings-updated', remove_query_arg( array( 'message'), wp_get_referer() ) ); | |
| 370 | + wp_safe_redirect( $goback ); | |
| 371 | + exit; | |
| 428 | 372 | |
| 429 | - if ( ! isset( $_POST['action'], $_POST['_wpnonce'], $_POST['option_page'], $_POST['_wp_http_referer'], $_POST['edit_flow_module_name'], $_POST['submit'] ) || ! is_admin() ) { | |
| 430 | - return false; | |
| 431 | - } | |
| 432 | - | |
| 433 | - global $edit_flow; | |
| 434 | - $module_name = sanitize_key( $_POST['edit_flow_module_name'] ); | |
| 435 | - | |
| 436 | - // Validate the submitted module name resolves to a real module before | |
| 437 | - // dereferencing it; this runs ahead of the capability check below, so a bogus | |
| 438 | - // name must not reach a property access on a non-object. | |
| 439 | - if ( ! isset( $edit_flow->$module_name ) || ! is_object( $edit_flow->$module_name ) ) { | |
| 440 | - return false; | |
| 441 | - } | |
| 442 | - | |
| 443 | - if ( 'update' != $_POST['action'] | |
| 444 | - || $_POST['option_page'] != $edit_flow->$module_name->module->options_group_name ) { | |
| 445 | - return false; | |
| 446 | - } | |
| 447 | - | |
| 448 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonces don't need sanitization, just verification. | |
| 449 | - if ( ! current_user_can( 'manage_options' ) || ! wp_verify_nonce( $_POST['_wpnonce'], $edit_flow->$module_name->module->options_group_name . '-options' ) ) { | |
| 450 | - wp_die( esc_html__( 'Cheatin’ uh?', 'edit-flow' ) ); | |
| 451 | - } | |
| 452 | - | |
| 453 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitization is handled by each module's settings_validate method. | |
| 454 | - $new_options = ( isset( $_POST[ $edit_flow->$module_name->module->options_group_name ] ) ) ? $_POST[ $edit_flow->$module_name->module->options_group_name ] : array(); | |
| 455 | - | |
| 456 | - // Only call the validation callback if it exists. | |
| 457 | - if ( method_exists( $edit_flow->$module_name, 'settings_validate' ) ) { | |
| 458 | - $new_options = $edit_flow->$module_name->settings_validate( $new_options ); | |
| 459 | - } else { | |
| 460 | - // Without a module validator, accept only keys that already exist in the | |
| 461 | - // module's options and sanitise their values, rather than persisting | |
| 462 | - // arbitrary submitted keys into the autoloaded options row. | |
| 463 | - $existing = (array) $edit_flow->$module_name->module->options; | |
| 464 | - $new_options = map_deep( array_intersect_key( (array) $new_options, $existing ), 'sanitize_text_field' ); | |
| 465 | - } | |
| 466 | - | |
| 467 | - // Cast our object and save the data. | |
| 468 | - $new_options = (object) array_merge( (array) $edit_flow->$module_name->module->options, $new_options ); | |
| 469 | - $edit_flow->update_all_module_options( $edit_flow->$module_name->module->name, $new_options ); | |
| 470 | - | |
| 471 | - // Redirect back to the settings page that was submitted without any previous messages. | |
| 472 | - $referer = wp_get_referer(); | |
| 473 | - if ( ! $referer ) { | |
| 474 | - $referer = admin_url( 'admin.php?page=' . $edit_flow->$module_name->module->settings_slug ); | |
| 475 | - } | |
| 476 | - $goback = add_query_arg( 'message', 'settings-updated', remove_query_arg( array( 'message' ), $referer ) ); | |
| 477 | - wp_safe_redirect( $goback ); | |
| 478 | - exit; | |
| 479 | - } | |
| 480 | 373 | } |
| 374 | + | |
| 375 | +} | |
| 481 | 376 | |
| 482 | 377 | } |