From 83c01b23f5c89701d9c8772ea9ee56bc72a00d14 Mon Sep 17 00:00:00 2001 From: olatechpro Date: Fri, 19 Jul 2024 09:53:20 +0100 Subject: [PATCH] Redirect after install #1681 --- modules/calendar/calendar.php | 2 +- publishpress.php | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/modules/calendar/calendar.php b/modules/calendar/calendar.php index 2a983d58..680ee54f 100644 --- a/modules/calendar/calendar.php +++ b/modules/calendar/calendar.php @@ -3305,7 +3305,7 @@ public function getCalendarDataForMultipleWeeks($args = [], $context = 'dashboar if (isset($this->module->options->sort_by)) { add_filter('posts_orderby', [$this, 'filterPostsOrderBy'], 10); } -write_log($args); + $post_results = new WP_Query($args); $posts = []; diff --git a/publishpress.php b/publishpress.php index 1f2de70a..6a67ab70 100644 --- a/publishpress.php +++ b/publishpress.php @@ -173,6 +173,8 @@ private function setup_actions() add_filter('debug_information', [$this, 'filterDebugInformation']); add_filter('cme_plugin_capabilities', [$this, 'filterCapabilities'], 11); + // Redirect on plugin activation + add_action('admin_init', [$this, 'redirect_on_activate'], 2000); } /** @@ -1205,7 +1207,10 @@ public function filterCapabilities($pluginCaps) 'pp_delete_editorial_comment', 'pp_delete_others_editorial_comment', 'pp_edit_editorial_comment', - 'pp_edit_others_editorial_comment' + 'pp_edit_others_editorial_comment', + 'delete_pp_notif_workflow', + 'edit_pp_notif_workflow', + 'read_pp_notif_workflow', ]; $pluginCaps['PublishPress Planner'] = $caps; @@ -1288,6 +1293,20 @@ public function getCorePostStatuses() { 'position' => 3, ], ]; + } + + /** + * Redirect user on plugin activation + * + * @return void + */ + public function redirect_on_activate() + { + if (get_option('pp_planner_activated')) { + delete_option('pp_planner_activated'); + wp_safe_redirect(admin_url("admin.php?page=pp-calendar")); + exit; + } } } @@ -1366,7 +1385,8 @@ function PublishPress() if (! defined('PUBLISHPRESS_HOOKS_REGISTERED')) { PublishPress(); add_action('init', 'publishPressRegisterImprovedNotificationsPostTypes'); - register_activation_hook(__FILE__, ['publishpress', 'activation_hook']); + // currently not working inside plugins_loaded + // register_activation_hook(__FILE__, ['publishpress', 'activation_hook']); define('PUBLISHPRESS_HOOKS_REGISTERED', 1); } else { $message = __('PublishPress Planner tried to load multiple times. Please, deactivate and remove other instances of PublishPress, specially if you are using PublishPress Pro.', 'publishpress'); @@ -1389,3 +1409,10 @@ function () use ($message) { } do_action('publishpress_planner_loaded'); }, -10); + +register_activation_hook( + __FILE__, + function () { + update_option('pp_planner_activated', true); + } +); \ No newline at end of file