From b2872bc2eeec0360b75228b5e91b1220b987fc31 Mon Sep 17 00:00:00 2001
From: Kevin Behrens <43488774+agapetry@users.noreply.github.com>
Date: Fri, 17 Nov 2023 22:52:38 -0500
Subject: [PATCH] Remove obsolete module
---
modules/dashboard/dashboard.php | 469 ------------------
modules/dashboard/lib/dashboard.css | 131 -----
.../dashboard/widgets/dashboard-notepad.php | 184 -------
3 files changed, 784 deletions(-)
delete mode 100644 modules/dashboard/dashboard.php
delete mode 100644 modules/dashboard/lib/dashboard.css
delete mode 100644 modules/dashboard/widgets/dashboard-notepad.php
diff --git a/modules/dashboard/dashboard.php b/modules/dashboard/dashboard.php
deleted file mode 100644
index 39979ded0..000000000
--- a/modules/dashboard/dashboard.php
+++ /dev/null
@@ -1,469 +0,0 @@
-.
- */
-
-if (! class_exists('PP_Dashboard')) {
- /**
- * class PP_Dashboard
- * All of the code for the dashboard widgets from PublishPress
- *
- * Dashboard widgets currently:
- * - Post Status Widget - Shows numbers for all (custom|post) statuses
- * - My Content Notifications Widget - Show the headlines with edit links for My Content Notifications
- *
- * @todo for 0.7
- * - Update the My Content Notifications widget to use new activity class
- */
- #[\AllowDynamicProperties]
- class PP_Dashboard extends PP_Module
- {
- public $widgets;
-
- /**
- * Load the PP_Dashboard class as an PublishPress module
- */
- public function __construct()
- {
- // Register the module with PublishPress
- $this->module_url = $this->get_module_url(__FILE__);
- $args = [
- 'title' => __('Dashboard', 'publishpress'),
- 'short_description' => false,
- 'extended_description' => false,
- 'module_url' => $this->module_url,
- 'icon_class' => 'dashicons dashicons-layout',
- 'slug' => 'dashboard',
- 'post_type_support' => 'pp_dashboard',
- 'default_options' => [
- 'enabled' => 'on',
- 'post_status_widget' => 'on',
- 'my_posts_widget' => 'on',
- 'notepad_widget' => 'on',
- ],
- 'configure_page_cb' => 'print_configure_view',
- 'configure_link_text' => __('Widget Options', 'publishpress'),
- 'autoload' => true,
- ];
- $this->module = PublishPress()->register_module('dashboard', $args);
- }
-
- /**
- * Initialize all of the class' functionality if its enabled
- */
- public function init()
- {
- if (false === is_admin()) {
- return;
- }
-
- $this->widgets = new stdClass;
-
- if ('on' == $this->module->options->notepad_widget) {
- require_once dirname(__FILE__) . '/widgets/dashboard-notepad.php';
- $this->widgets->notepad_widget = new PP_Dashboard_Notepad_Widget;
- $this->widgets->notepad_widget->init();
- }
-
- // Add the widgets to the dashboard
- add_action('wp_dashboard_setup', [$this, 'add_dashboard_widgets']);
-
- // Register our settings
- add_action('admin_init', [$this, 'register_settings']);
- }
-
- /**
- * Upgrade our data in case we need to
- *
- * @since 0.7
- */
- public function upgrade($previous_version)
- {
- global $publishpress;
-
- // Upgrade path to v0.7
- if (version_compare($previous_version, '0.7', '<')) {
- // Migrate whether dashboard widgets were enabled or not
- if ($enabled = get_option('publishpress_dashboard_widgets_enabled')) {
- $enabled = 'on';
- } else {
- $enabled = 'off';
- }
- $publishpress->update_module_option($this->module->name, 'enabled', $enabled);
- delete_option('publishpress_dashboard_widgets_enabled');
- // Migrate whether the post status widget was on
- if ($post_status_widget = get_option('publishpress_post_status_widget_enabled')) {
- $post_status_widget = 'on';
- } else {
- $post_status_widget = 'off';
- }
- $publishpress->update_module_option($this->module->name, 'post_status_widget', $post_status_widget);
- delete_option('publishpress_post_status_widget_enabled');
- // Migrate whether the my posts widget was on
- if ($my_posts_widget = get_option('publishpress_myposts_widget_enabled')) {
- $my_posts_widget = 'on';
- } else {
- $my_posts_widget = 'off';
- }
- $publishpress->update_module_option($this->module->name, 'post_status_widget', $my_posts_widget);
- delete_option('publishpress_myposts_widget_enabled');
- // Delete legacy option
- delete_option('publishpress_quickpitch_widget_enabled');
-
- // Technically we've run this code before so we don't want to auto-install new data
- $publishpress->update_module_option($this->module->name, 'loaded_once', true);
- }
- }
-
- /**
- * Add PublishPress 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(
- 'publishpress-dashboard-css',
- $this->module_url . 'lib/dashboard.css',
- false,
- PUBLISHPRESS_VERSION,
- 'all'
- );
-
- // Set up Post Status widget but, first, check to see if it's enabled
- if ($this->module->options->post_status_widget == 'on') {
- wp_add_dashboard_widget(
- 'post_status_widget',
- __('Unpublished Content', 'publishpress'),
- [$this, 'post_status_widget']
- );
- }
-
- // Set up the Notepad widget if it's enabled
- if ('on' == $this->module->options->notepad_widget) {
- wp_add_dashboard_widget(
- 'notepad_widget',
- __('Notepad', 'publishpress'),
- [$this->widgets->notepad_widget, 'notepad_widget']
- );
- }
-
- // Add the MyPosts widget, if enabled
- if ($this->module->options->my_posts_widget == 'on' && $this->module_enabled('notifications')) {
- wp_add_dashboard_widget(
- 'myposts_widget',
- __('My Content Notifications', 'publishpress'),
- [$this, 'myposts_widget']
- );
- }
- }
-
- /**
- * Creates Post Status widget
- * Display an at-a-glance view of post counts for all (post|custom) statuses in the system
- *
- * @todo Support custom post types
- */
- public function post_status_widget()
- {
- global $publishpress;
-
- $statuses = $this->get_unpublished_post_statuses();
- $statuses = apply_filters('pp_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',
- 'pp-custom-status-settings',
- get_admin_url(null, 'admin.php')
- );
- } ?>
-
-
-
- get_post_statuses();
-
- $newList = [];
- foreach ($statuses as $status) {
- if (! in_array($status->slug, ['publish', 'private'])) {
- $newList[] = $status;
- }
- }
-
- $statuses = $newList;
-
- return $statuses;
- }
-
- /**
- * Creates My Posts widget
- * Shows a list of the "posts you're following" sorted by most recent activity.
- */
- public function myposts_widget()
- {
- global $publishpress;
-
- $myposts = $publishpress->notifications->get_user_to_notify_posts(); ?>
-
-
-
-
- ID);
- ?>
-
-
-
-
-
-
-
-
-
- module->options_group_name . '_general',
- false,
- '__return_false',
- $this->module->options_group_name
- );
- add_settings_field(
- 'post_status_widget',
- __('Post Status Widget', 'publishpress'),
- [$this, 'settings_post_status_widget_option'],
- $this->module->options_group_name,
- $this->module->options_group_name . '_general'
- );
- add_settings_field(
- 'my_posts_widget',
- __('My Content Notifications', 'publishpress'),
- [$this, 'settings_my_posts_widget_option'],
- $this->module->options_group_name,
- $this->module->options_group_name . '_general'
- );
- add_settings_field(
- 'notepad_widget',
- __('Notepad', 'publishpress'),
- [$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 = [
- 'off' => __('Disabled', 'publishpress'),
- 'on' => __('Enabled', 'publishpress'),
- ];
- echo '';
- }
-
- /**
- * Enable or disable the My Content Notifications Widget for the WP dashboard
- *
- * @since 0.7
- */
- public function settings_my_posts_widget_option()
- {
- global $publishpress;
- $options = [
- 'off' => __('Disabled', 'publishpress'),
- 'on' => __('Enabled', 'publishpress'),
- ];
- echo '';
- if (! $this->module_enabled('notifications')) {
- echo ' ' . esc_html__(
- 'The notifications module will need to be enabled for this widget to display.',
- 'publishpress'
- );
- }
- }
-
- /**
- * Enable or disable the Notepad widget for the dashboard
- *
- * @since 0.8
- */
- public function settings_notepad_widget_option()
- {
- $options = [
- 'off' => __('Disabled', 'publishpress'),
- 'on' => __('Enabled', 'publishpress'),
- ];
- echo '';
- }
-
- /**
- * Validate the field submitted by the user
- *
- * @since 0.7
- */
- public function settings_validate($new_options)
- {
- // Follow whitelist validation for modules
- if (array_key_exists('post_status_widget', $new_options) && $new_options['post_status_widget'] != 'on') {
- $new_options['post_status_widget'] = 'off';
- }
-
- if (array_key_exists('my_posts_widget', $new_options) && $new_options['my_posts_widget'] != 'on') {
- $new_options['my_posts_widget'] = 'off';
- }
-
- return $new_options;
- }
-
- /**
- * Settings page for the dashboard
- *
- * @since 0.7
- */
- public function print_configure_view()
- {
- settings_fields($this->module->options_group_name);
- do_settings_sections($this->module->options_group_name);
- }
- }
-}
diff --git a/modules/dashboard/lib/dashboard.css b/modules/dashboard/lib/dashboard.css
deleted file mode 100644
index c9c47fb23..000000000
--- a/modules/dashboard/lib/dashboard.css
+++ /dev/null
@@ -1,131 +0,0 @@
-/* Post Status Widget - Dashboard */
-
-#post_status_widget .sub {
- margin-bottom: 10px;
- font-size: 20px;
- margin-top: 5px;
-}
-
-#post_status_widget a {
- font-size: 14px;
- font-weight: bold;
-}
-
-#post_status_widget .table table tbody tr {
- line-height: 22px;
- border-bottom: 1px solid #e5e5e5;
-}
-
-#post_status_widget td.b a {
- color: #ba2000;
- margin-right: 10px;
- font-size: 18px;
- padding-right: 6px;
- text-align: right;
-}
-
-#post_status_widget span.small a {
- color: #989898;
- font-weight: normal;
- font-style: normal;
- line-height: 22px;
-}
-
-#post_status_widget span.small a:hover {
- border-bottom: 1px dotted #989898;
-}
-
-/* QuickPitch */
-
-.quick-pitch-notice {
- background-color: #ffffe0;
- padding: 5px 10px;
- margin-top: 5px;
- margin-bottom: 10px;
- border: 1px solid #e6db55;
- -moz-border-radius: 3px;
- -khtml-border-radius: 3px;
- -webkit-border-radius: 3px;
- border-radius: 3px;
-}
-
-#quick-pitch-notification h3 {
- background: none;
- text-shadow: none;
- font: italic normal normal 16px/20px;
- padding-bottom: 0;
-}
-
-#quick-pitch-notification p {
- padding-left: 10px;
-}
-
-#quick_pitch_widget h4 {
- float: left;
- width: 5.5em;
- clear: both;
- font-weight: normal;
- text-align: right;
- padding-top: 3px !important;
- font-size: 12px !important;
- line-height: 1.2em;
-}
-
-#quick_pitch_widget h4 label {
- margin-right: 10px;
-}
-
-#pp_author_div {
- padding-bottom: 9px;
- padding-right: 3px;
-}
-
-#quick_pitch_widget .input-text-wrap,
-#quick_pitch_widget .textarea-wrap {
- margin: 0 0 1em 5em;
-}
-
-#pp_description_div {
- width: 200px;
-}
-
-.pp_location_div input {
- padding: 2px !important;
-}
-
-.pp-submit {
- height: 20px;
- text-align: right;
-}
-
-/* Posts I'm Following */
-
-.pp-myposts li {
- list-style-type: none;
- padding-bottom: 5px;
-}
-
-.pp-myposts li a {
- font-weight: normal;
-}
-
-.pp-myposts li .pp-myposts-timestamp {
- color: #999;
- font-style: italic;
- font-size: 10px;
-}
-
-/** Dashboard Notepad **/
-#dashboard-notepad #dashboard-notepad-submit-buttons {
- float: right;
-}
-
-#dashboard-notepad #dashboard-notepad-last-updated {
- font-size: 12px;
- line-height: 18px;
- color: #999;
-}
-
-#dashboard-notepad .submit #dashboard-notepad-last-updated {
- float: left;
-}
diff --git a/modules/dashboard/widgets/dashboard-notepad.php b/modules/dashboard/widgets/dashboard-notepad.php
deleted file mode 100644
index 3d6b7198b..000000000
--- a/modules/dashboard/widgets/dashboard-notepad.php
+++ /dev/null
@@ -1,184 +0,0 @@
-.
- */
-
-/**
- * A notepad for the dashboard
- */
-class PP_Dashboard_Notepad_Widget
-{
- const notepad_post_type = 'dashboard-note';
-
- public $edit_cap = 'edit_others_posts';
-
- public function __construct()
- {
- // Silence is golden
- }
-
- public function init()
- {
- register_post_type(
- self::notepad_post_type,
- [
- 'label' => __('Dashboard Note', 'publishpress'),
- 'public' => false,
- 'publicly_queryable' => false,
- 'has_archive' => false,
- 'rewrite' => false,
- 'show_ui' => false,
- 'query_var' => false,
- 'hierarchical' => false,
- 'can_export' => true,
- 'exclude_from_search' => true,
- ]
- );
-
- $this->edit_cap = apply_filters('pp_dashboard_notepad_edit_cap', $this->edit_cap);
-
- add_action('admin_init', [$this, 'handle_notepad_update']);
- }
-
- /**
- * Handle a dashboard note being created or updated
- *
- * @since 0.8
- */
- public function handle_notepad_update()
- {
- global $pagenow;
-
- if ('index.php' != $pagenow
- || (empty($_REQUEST['action']) || 'dashboard-notepad' != $_REQUEST['action'])) {
- return;
- }
-
- check_admin_referer('dashboard-notepad');
-
- if (! isset($_REQUEST['notepad-id'])) {
- return;
- }
-
- if (! current_user_can($this->edit_cap)) {
- wp_die(esc_html(PublishPress()->dashboard->messages['invalid-permissions']));
- }
-
- if (isset($_REQUEST['note'])) {
- $note_content = wp_filter_nohtml_kses($_REQUEST['note']);
- } else {
- $note_content = '';
- }
-
- $current_id = (int)$_REQUEST['notepad-id'];
- $current_notepad = get_post($current_id);
- $new_note = [
- 'post_content' => $note_content,
- 'post_type' => self::notepad_post_type,
- 'post_status' => 'draft',
- 'post_author' => get_current_user_id(),
- ];
-
- if ($current_notepad
- && self::notepad_post_type == $current_notepad->post_type
- && ! isset($_REQUEST['create-note'])) {
- $new_note['ID'] = $current_id;
- wp_update_post($new_note);
- } else {
- wp_insert_post($new_note);
- }
-
- wp_safe_redirect(wp_get_referer());
- exit;
- }
-
- /**
- * Notepad Widget
- * Editors can leave notes in the dashboard for authors and contributors
- *
- * @since 0.8
- */
- public function notepad_widget()
- {
- $args = [
- 'posts_per_page' => 1,
- 'post_status' => 'draft',
- 'post_type' => self::notepad_post_type,
- ];
- $posts = get_posts($args);
- $current_note = (! empty($posts[0]->post_content)) ? $posts[0]->post_content : '';
- $current_id = (! empty($posts[0]->ID)) ? $posts[0]->ID : 0;
- $current_post = (! empty($posts[0])) ? $posts[0] : false;
-
- if ($current_post) {
- $last_updated_escaped = '' . sprintf(
- esc_html__(
- '%1$s last updated on %2$s',
- 'publishpress'
- ),
- esc_html(get_user_by('id', $current_post->post_author)->display_name),
- esc_html(
- get_the_time(
- get_option('date_format') . ' ' . get_option('time_format'),
- $current_post
- )
- )
- ) . '';
- } else {
- $last_updated_escaped = '';
- }
-
- if (current_user_can($this->edit_cap)) {
- echo '';
- } else {
- echo '';
- }
- }
-}