| 1 |
<?php |
| 2 |
|
| 3 |
namespace Barn2\Plugin\Posts_Table_Search_Sort; |
| 4 |
|
| 5 |
use Barn2\Plugin\Posts_Table_Search_Sort\Admin\Settings_Page; |
| 6 |
use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Plugin\Simple_Plugin; |
| 7 |
use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Registerable; |
| 8 |
use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Service_Provider; |
| 9 |
use Barn2\Plugin\Posts_Table_Search_Sort\Dependencies\Lib\Util; |
| 10 |
|
| 11 |
/** |
| 12 |
* The main plugin class. |
| 13 |
* |
| 14 |
* @package Barn2\posts-table-search-sort |
| 15 |
* @author Barn2 Plugins <support@barn2.com> |
| 16 |
* @license GPL-3.0 |
| 17 |
* @copyright Barn2 Media Ltd |
| 18 |
*/ |
| 19 |
class Plugin extends Simple_Plugin implements Registerable, Service_Provider { |
| 20 |
|
| 21 |
const NAME = 'Posts Table with Search and Sort'; |
| 22 |
const ITEM_ID = 8006; |
| 23 |
|
| 24 |
/** |
| 25 |
* @var array $services |
| 26 |
*/ |
| 27 |
private $services; |
| 28 |
|
| 29 |
/** |
| 30 |
* Constructs and initializes an EDD VAT plugin instance. |
| 31 |
* |
| 32 |
* @param string $file The main plugin __FILE__ |
| 33 |
* @param string $version The current plugin version |
| 34 |
*/ |
| 35 |
public function __construct( $file = null, $version = '1.0' ) { |
| 36 |
parent::__construct( |
| 37 |
[ |
| 38 |
'id' => self::ITEM_ID, |
| 39 |
'name' => self::NAME, |
| 40 |
'version' => $version, |
| 41 |
'file' => $file, |
| 42 |
'settings_path' => 'options-general.php?page=' . Settings_Page::MENU_SLUG |
| 43 |
] |
| 44 |
); |
| 45 |
|
| 46 |
$this->add_service( 'plugin_setup', new Plugin_Setup( $this->get_file(), $this ), true ); |
| 47 |
} |
| 48 |
|
| 49 |
public function register() { |
| 50 |
parent::register(); |
| 51 |
add_action( 'plugins_loaded', [ $this, 'add_services' ] ); |
| 52 |
|
| 53 |
add_action( 'init', [ $this, 'register_services' ] ); |
| 54 |
add_action( 'init', [ $this, 'load_textdomain' ], 5 ); |
| 55 |
} |
| 56 |
|
| 57 |
public function maybe_load_plugin() { |
| 58 |
// Don't load plugin if Pro version active |
| 59 |
if ( Util::is_barn2_plugin_active('\\Barn2\\Plugin\\Posts_Table_Pro\\ptp') ) { |
| 60 |
return; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
public function load_textdomain() { |
| 65 |
load_plugin_textdomain( 'posts-data-table', false, $this->get_slug() . '/languages' ); |
| 66 |
} |
| 67 |
|
| 68 |
public function add_services() { |
| 69 |
if ( Util::is_barn2_plugin_active('\\Barn2\\Plugin\\Posts_Table_Pro\\ptp') ) { |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
$this->add_service( 'shortcode', new Table_Shortcode() ); |
| 74 |
$this->add_service( 'scripts', new Frontend_Scripts( $this ) ); |
| 75 |
$this->add_service( 'setup_wizard', new Admin\Wizard\Setup_Wizard( $this ) ); |
| 76 |
|
| 77 |
// Admin only services |
| 78 |
if ( Util::is_admin() ) { |
| 79 |
$this->add_service( 'admin', new Admin\Admin_Controller( $this ) ); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
} |
| 84 |
|