module_url = $this->get_module_url( __FILE__ ); $args = array( 'title' => __( 'Dashboard Widgets', 'edit-flow' ), 'short_description' => __( 'Track your content from the WordPress dashboard.', 'edit-flow' ), 'extended_description' => __( 'Enable dashboard widgets to quickly get an overview of what state your content is in.', 'edit-flow' ), 'module_url' => $this->module_url, 'img_url' => $this->module_url . 'lib/dashboard_s128.png', 'slug' => 'dashboard', 'post_type_support' => 'ef_dashboard', 'default_options' => array( 'enabled' => 'on', 'post_status_widget' => 'on', 'my_posts_widget' => 'on', 'notepad_widget' => 'on', ), 'configure_page_cb' => 'print_configure_view', 'configure_link_text' => __( 'Widget Options', 'edit-flow' ), ); $this->module = EditFlow()->register_module( 'dashboard', $args ); } /** * Initialize all of the class' functionality if its enabled. */ public function init() { $this->widgets = new stdClass(); if ( 'on' == $this->module->options->notepad_widget ) { require_once __DIR__ . '/widgets/dashboard-notepad.php'; $this->widgets->notepad_widget = new EF_Dashboard_Notepad_Widget(); $this->widgets->notepad_widget->init(); } // Add the widgets to the dashboard. add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widgets' ) ); // Register our settings. add_action( 'admin_init', array( $this, 'register_settings' ) ); } /** * Upgrade our data in case we need to. * * @since 0.7 * * @param string $previous_version Previous plugin version. */ public function upgrade( $previous_version ) { global $edit_flow; // Upgrade path to v0.7. if ( version_compare( $previous_version, '0.7', '<' ) ) { // Migrate whether dashboard widgets were enabled or not. $enabled = get_option( 'edit_flow_dashboard_widgets_enabled' ) ? 'on' : 'off'; $edit_flow->update_module_option( $this->module->name, 'enabled', $enabled ); delete_option( 'edit_flow_dashboard_widgets_enabled' ); // Migrate whether the post status widget was on. $post_status_widget = get_option( 'edit_flow_post_status_widget_enabled' ) ? 'on' : 'off'; $edit_flow->update_module_option( $this->module->name, 'post_status_widget', $post_status_widget ); delete_option( 'edit_flow_post_status_widget_enabled' ); // Migrate whether the my posts widget was on. $my_posts_widget = get_option( 'edit_flow_myposts_widget_enabled' ) ? 'on' : 'off'; $edit_flow->update_module_option( $this->module->name, 'post_status_widget', $my_posts_widget ); delete_option( 'edit_flow_myposts_widget_enabled' ); // Delete legacy option. delete_option( 'edit_flow_quickpitch_widget_enabled' ); // Technically we've run this code before so we don't want to auto-install new data. $edit_flow->update_module_option( $this->module->name, 'loaded_once', true ); } } /** * Add Edit Flow dashboard widgets to the WordPress admin dashboard. */ public function add_dashboard_widgets() { // Only show dashboard widgets for Contributor or higher. if ( ! current_user_can( 'edit_posts' ) ) { return; } wp_enqueue_style( 'edit-flow-dashboard-css', $this->module_url . 'lib/dashboard.css', false, EDIT_FLOW_VERSION, 'all' ); // Set up Post Status widget but, first, check to see if it's enabled. if ( 'on' == $this->module->options->post_status_widget ) { $status_widget_post_types = apply_filters( 'ef_dashboard_psw_post_types', $this->get_all_post_types() ); foreach ( $status_widget_post_types as $post_type => $label ) { $this->add_dashboard_status_widget( $post_type ); } } // Set up the Notepad widget if it's enabled. if ( 'on' == $this->module->options->notepad_widget ) { wp_add_dashboard_widget( 'notepad_widget', __( 'Notepad', 'edit-flow' ), array( $this->widgets->notepad_widget, 'notepad_widget' ) ); } // Add the MyPosts widget, if enabled. if ( 'on' == $this->module->options->my_posts_widget && $this->module_enabled( 'notifications' ) ) { wp_add_dashboard_widget( 'myposts_widget', __( 'Posts I\'m Following', 'edit-flow' ), array( $this, 'myposts_widget' ) ); } } /** * Dynamically add a "Unpublished Content" post status widget for any post type. * * @param string $post_type_slug Post type slug. */ public function add_dashboard_status_widget( $post_type_slug ) { $post_type_labels = get_post_type_labels( get_post_type_object( $post_type_slug ) ); if ( 'post' !== $post_type_slug ) { $widget_id = 'post_status_widget_' . $post_type_slug; // translators: %s is the post type name. $widget_title = sprintf( esc_html__( 'Unpublished Content: %s', 'edit-flow' ), $post_type_labels->name ); } else { $widget_id = 'post_status_widget'; $widget_title = __( 'Unpublished Content', 'edit-flow' ); } $widget_title = apply_filters( 'ef_dashboard_psw_title', $widget_title, $post_type_slug ); $args = array( 'post_type' => $post_type_slug, 'labels' => $post_type_labels, ); wp_add_dashboard_widget( $widget_id, $widget_title, array( $this, 'post_status_widget' ), null, $args ); } /** * Creates Post Status widget. * * Display an at-a-glance view of post counts for all (post|custom) statuses in the system. * * @param mixed $unused Unused parameter. * @param array $args Widget arguments. */ public function post_status_widget( $unused, $args ) { $labels = $args['args']['labels']; $post_type = $args['args']['post_type']; $statuses = $this->get_post_statuses(); $statuses[] = (object) array( 'name' => __( 'Scheduled', 'edit-flow' ), 'description' => '', 'slug' => 'future', ); $statuses = apply_filters( 'ef_dashboard_post_status_widget_statuses', $statuses ); // If custom statuses are enabled, we'll output a link to edit the terms just below the post counts. if ( $this->module_enabled( 'custom_status' ) ) { $edit_custom_status_url = add_query_arg( 'page', 'ef-custom-status-settings', get_admin_url( null, 'admin.php' ) ); } ?>

name ) ); ?>

filter_posts_link( $status->slug, $post_type ); ?>
slug; echo esc_html( $post_count->$slug ); ?> name ); ?>
notifications->get_user_following_posts(); ?>
ID ) ); $title = esc_html( $post->post_title ); ?>
  • module->options_group_name . '_general', false, '__return_false', $this->module->options_group_name ); add_settings_field( 'post_status_widget', __( 'Post Status Widget', 'edit-flow' ), array( $this, 'settings_post_status_widget_option' ), $this->module->options_group_name, $this->module->options_group_name . '_general' ); add_settings_field( 'my_posts_widget', __( 'Posts I\'m Following', 'edit-flow' ), array( $this, 'settings_my_posts_widget_option' ), $this->module->options_group_name, $this->module->options_group_name . '_general' ); add_settings_field( 'notepad_widget', __( 'Notepad', 'edit-flow' ), array( $this, 'settings_notepad_widget_option' ), $this->module->options_group_name, $this->module->options_group_name . '_general' ); } /** * Enable or disable the Post Status Widget for the WP dashboard * * @since 0.7 */ public function settings_post_status_widget_option() { $options = array( 'off' => __( 'Disabled', 'edit-flow' ), 'on' => __( 'Enabled', 'edit-flow' ), ); echo ''; } /** * Enable or disable the Posts I'm Following Widget for the WP dashboard. * * @since 0.7 */ public function settings_my_posts_widget_option() { global $edit_flow; $options = array( 'off' => __( 'Disabled', 'edit-flow' ), 'on' => __( 'Enabled', 'edit-flow' ), ); echo ''; if ( ! $this->module_enabled( 'notifications' ) ) { echo '   ' . esc_html__( 'The notifications module will need to be enabled for this widget to display.', 'edit-flow' ); } } /** * Enable or disable the Notepad widget for the dashboard. * * @since 0.8 */ public function settings_notepad_widget_option() { $options = array( 'off' => __( 'Disabled', 'edit-flow' ), 'on' => __( 'Enabled', 'edit-flow' ), ); echo ''; } /** * Validate the field submitted by the user. * * @since 0.7 * * @param array $new_options The new options to validate. * @return array The validated options. */ public function settings_validate( $new_options ) { // Follow whitelist validation for modules. if ( array_key_exists( 'post_status_widget', $new_options ) && 'on' != $new_options['post_status_widget'] ) { $new_options['post_status_widget'] = 'off'; } if ( array_key_exists( 'my_posts_widget', $new_options ) && 'on' != $new_options['my_posts_widget'] ) { $new_options['my_posts_widget'] = 'off'; } return $new_options; } /** * Settings page for the dashboard. * * @since 0.7 */ public function print_configure_view() { ?>
    module->options_group_name ); ?> module->options_group_name ); ?> module->name ) . '" />'; ?>