module_url = $this->get_module_url( __FILE__ ); $args = array( 'title' => __( 'Edit Flow', 'edit-flow' ), 'short_description' => __( 'Edit Flow redefines your WordPress publishing workflow.', 'edit-flow' ), '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' ), 'module_url' => $this->module_url, 'img_url' => $this->module_url . 'lib/eflogo_s128.png', 'slug' => 'settings', 'settings_slug' => 'ef-settings', 'default_options' => array( 'enabled' => 'on', ), 'configure_page_cb' => 'print_default_settings', 'autoload' => true, ); $this->module = EditFlow()->register_module( 'settings', $args ); } /** * Initialize the rest of the stuff in the class if the module is active. */ public function init() { add_action( 'admin_init', array( $this, 'helper_settings_validate_and_save' ), 100 ); add_action( 'admin_print_styles', array( $this, 'action_admin_print_styles' ) ); add_action( 'admin_print_scripts', array( $this, 'action_admin_print_scripts' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'action_admin_enqueue_scripts' ) ); add_action( 'admin_menu', array( $this, 'action_admin_menu' ) ); add_action( 'wp_ajax_change_edit_flow_module_state', array( $this, 'ajax_change_edit_flow_module_state' ) ); } /** * Add necessary things to the admin menu. */ public function action_admin_menu() { global $edit_flow; $ef_logo = 'lib/eflogo_s32w.png'; 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 ); // Add "Features" as the first submenu item (replaces the duplicate "Edit Flow" item). add_submenu_page( $this->module->settings_slug, __( 'Features', 'edit-flow' ), __( 'Features', 'edit-flow' ), 'manage_options', $this->module->settings_slug, array( $this, 'settings_page_controller' ) ); foreach ( $edit_flow->modules as $mod_name => $mod_data ) { if ( isset( $mod_data->options->enabled ) && 'on' == $mod_data->options->enabled && $mod_data->configure_page_cb && $mod_name != $this->module->name ) { add_submenu_page( $this->module->settings_slug, $mod_data->title, $mod_data->title, 'manage_options', $mod_data->settings_slug, array( $this, 'settings_page_controller' ) ); } } } /** * Enqueue scripts for the settings page. */ public function action_admin_enqueue_scripts() { if ( $this->is_whitelisted_settings_view() ) { wp_enqueue_script( 'edit-flow-settings-js', $this->module_url . 'lib/settings.js', array( 'jquery' ), EDIT_FLOW_VERSION, true ); } } /** * Add settings styles to the settings page. */ public function action_admin_print_styles() { if ( $this->is_whitelisted_settings_view() ) { wp_enqueue_style( 'edit_flow-settings-css', $this->module_url . 'lib/settings.css', false, EDIT_FLOW_VERSION ); } } /** * Extra data we need on the page for transitions, etc. * * @since 0.7 */ public function action_admin_print_scripts() { ?> get_module_by( 'slug', $slug ); if ( ! $module ) { wp_die( '-1' ); } $return = false; if ( 'enable' === $module_action ) { $return = $edit_flow->update_module_option( $module->name, 'enabled', 'on' ); } elseif ( 'disable' === $module_action ) { $return = $edit_flow->update_module_option( $module->name, 'enabled', 'off' ); } if ( $return ) { wp_die( '1' ); } else { wp_die( '-1' ); } } /** * Handles all settings and configuration page requests. Required element for Edit Flow. * * phpcs:disable WordPress.Security.NonceVerification.Recommended -- Rendering only, no data modification. */ public function settings_page_controller() { global $edit_flow; $page_requested = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : 'settings'; // phpcs:enable WordPress.Security.NonceVerification $requested_module = $edit_flow->get_module_by( 'settings_slug', $page_requested ); if ( ! $requested_module ) { wp_die( esc_html__( 'Not a registered Edit Flow module', 'edit-flow' ) ); } $configure_callback = $requested_module->configure_page_cb; $requested_module_name = $requested_module->name; // Don't show the settings page for the module if the module isn't activated. if ( ! $this->module_enabled( $requested_module_name ) ) { /* translators: 1: link to the settings page for Edit Flow */ echo '
'; return; } $this->print_default_header( $requested_module ); $edit_flow->$requested_module_name->$configure_callback(); $this->print_default_footer( $requested_module ); } /** * Print the default header for the settings page. * * Nonce verification is not available here - it's just rendering. The actual save * is done in helper_settings_validate_and_save and that's guarded well. * * @param object $current_module The current module being displayed. * * phpcs:disable WordPress.Security.NonceVerification */ public function print_default_header( $current_module ) { // Register admin notices for standard WordPress display. if ( isset( $_GET['message'] ) ) { $message = sanitize_key( $_GET['message'] ); } elseif ( isset( $_REQUEST['message'] ) ) { $message = sanitize_key( $_REQUEST['message'] ); } elseif ( isset( $_POST['message'] ) ) { $message = sanitize_key( $_POST['message'] ); } else { $message = false; } if ( $message && isset( $current_module->messages[ $message ] ) ) { add_settings_error( 'edit-flow', 'edit-flow-' . $message, $current_module->messages[ $message ], 'success' ); } // If there's been an error, register it as an admin notice. if ( isset( $_GET['error'] ) ) { $error = sanitize_key( $_GET['error'] ); } elseif ( isset( $_REQUEST['error'] ) ) { $error = sanitize_key( $_REQUEST['error'] ); } elseif ( isset( $_POST['error'] ) ) { $error = sanitize_key( $_POST['error'] ); } else { $error = false; } if ( $error && isset( $current_module->messages[ $error ] ) ) { add_settings_error( 'edit-flow', 'edit-flow-' . $error, $current_module->messages[ $error ], 'error' ); } // Build the page title. if ( 'settings' !== $current_module->name ) { $page_title = sprintf( /* translators: %s: module title */ __( 'Edit Flow: %s', 'edit-flow' ), $current_module->title ); } else { $page_title = __( 'Edit Flow: Features', 'edit-flow' ); } ?>short_description ); ?>
extended_description ) : ?>extended_description ); ?>
form_errors[ $field ] ); ?>