PluginProbe
Posts Table with Search & Sort / trunk
Posts Table with Search & Sort vtrunk
trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2 1.3 1.3.1 1.3.1-v2 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 All 39 releases
posts-data-table / src / Plugin_Setup.php

Plugin_Setup.php in Posts Table with Search & Sort trunk, at src/Plugin_Setup.php

97 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Barn2\Plugin\Posts_Table_Search_Sort;
4
5 use Barn2\Plugin\Posts_Table_Search_Sort\Admin\Wizard\Starter;
6 use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Plugin\Plugin;
7 use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Plugin\Plugin_Activation_Listener;
8 use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Util as Lib_Util;
9 use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Registerable;
10 use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Service\Standard_Service;
11
12 /**
13 * Plugin Setup
14 *
15 * @package Barn2/posts-table-search-sort
16 * @author Barn2 Plugins <info@barn2.com>
17 * @license GPL-3.0
18 * @copyright Barn2 Media Ltd
19 */
20 class Plugin_Setup implements Registerable, Standard_Service, Plugin_Activation_Listener {
21 /**
22 * Plugin's entry file
23 *
24 * @var string
25 */
26 private $file;
27
28 /**
29 * Plugin instance
30 *
31 * @var Plugin
32 */
33 private $plugin;
34
35 /**
36 * Wizard starter.
37 *
38 * @var Starter
39 */
40 private $starter;
41
42 /**
43 * Constructor.
44 *
45 * @param mixed $file
46 * @param Plugin $plugin
47 */
48 public function __construct( $file, Plugin $plugin ) {
49 $this->file = $file;
50 $this->plugin = $plugin;
51 $this->starter = new Starter( $this->plugin );
52 }
53
54 /**
55 * Register the service.
56 */
57 public function register() {
58 register_activation_hook( $this->file, [ $this, 'on_activate' ] );
59 add_action( 'admin_init', [ $this, 'after_plugin_activation' ] );
60 }
61
62 /**
63 * On activation.
64 *
65 * @param mixed $network_wide
66 */
67 public function on_activate( $network_wide ) {
68 if ( $this->starter->should_start() ) {
69 $this->starter->create_transient();
70 }
71 }
72
73 /**
74 * Do nothing.
75 *
76 * @param bool $network_wide
77 */
78 public function on_deactivate( $network_wide ) {
79 }
80
81 /**
82 * Detect the transient and redirect to wizard.
83 *
84 * @return void
85 */
86 public function after_plugin_activation() {
87
88 if ( ! $this->starter->detected() ) {
89 return;
90 }
91
92 $this->starter->delete_transient();
93 $this->starter->create_option();
94 $this->starter->redirect();
95 }
96 }
97