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