Skip to content

Commit

Permalink
Some Code?
Browse files Browse the repository at this point in the history
  • Loading branch information
officiallygod committed Oct 11, 2023
1 parent 32d7218 commit c6d0089
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions includes/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use NewfoldLabs\WP\Module\Onboarding\Compatibility\Status;
use NewfoldLabs\WP\Module\Onboarding\RestApi\RestApi;
use NewfoldLabs\WP\Module\Onboarding\Services\PluginService;
use NewfoldLabs\WP\ModuleLoader\Container;
use NewfoldLabs\WP\Module\Onboarding\Data\Options;
use function NewfoldLabs\WP\ModuleLoader\container;
Expand Down Expand Up @@ -71,6 +72,9 @@ public function __construct( Container $container ) {
new WP_Admin();
}

// Adds a transient to activate plugins in all scenarios.
PluginService::configure_activation_transient();

\do_action( 'nfd_module_onboarding_post_init' );
}
}
44 changes: 44 additions & 0 deletions includes/Services/PluginService.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
namespace NewfoldLabs\WP\Module\Onboarding\Services;

use NewfoldLabs\WP\Module\Onboarding\WP_ADMIN;
use NewfoldLabs\WP\Module\Onboarding\Data\Options;
use function NewfoldLabs\WP\ModuleLoader\container;
use NewfoldLabs\WP\Module\Installer\Services\PluginInstaller;
use NewfoldLabs\WP\Module\Installer\TaskManagers\PluginActivationTaskManager;
use NewfoldLabs\WP\Module\Installer\TaskManagers\PluginInstallTaskManager;
Expand Down Expand Up @@ -89,4 +92,45 @@ public static function activate_init_plugins() {

return true;
}

/**
* Sets up a Transient to activate plugins and filter active_plugins
*
* @return boolean
*/
public static function configure_activation_transient() {
global $pagenow;
global $current_screen;

switch ( $pagenow ) {
case 'admin.php':
\do_action( 'qm/debug', 'Here' );
delete_transient( Options::get_option_name( 'active_plugins', true ) );
self::activate_init_plugins();
break;
case 'plugins.php':
delete_transient( Options::get_option_name( 'active_plugins', true ) );
self::activate_init_plugins();
break;
case 'index.php':
// If the page is nfd-onboarding
if ( WP_ADMIN::$slug === $_GET['page'] ) {
if ( empty( get_transient( Options::get_option_name( 'active_plugins', true ) ) ) ) {
set_transient( Options::get_option_name( 'active_plugins', true ), '1', 20 * MINUTE_IN_SECONDS );
}
}
break;
}
// Add hook to activate plugins after transient is deleted
add_filter(
'option_active_plugins',
function( $plugins ) {
if ( ! empty( get_transient( Options::get_option_name( 'active_plugins', true ) ) ) ) {
return array( container()->plugin()->basename );
}
return $plugins;
}
);

}
}

0 comments on commit c6d0089

Please sign in to comment.