| @@ -1,48 +1,127 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | /** |
| 3 | 4 | * The main plugin file for Posts Table with Search & Sort. |
| 4 | 5 | * |
| 5 | - * @package Barn2\posts-table-search-sort | |
| 6 | - * @author Barn2 Plugins <support@barn2.com> | |
| 7 | - * @license GPL-3.0 | |
| 8 | - * @copyright Barn2 Media Ltd | |
| 9 | - * | |
| 10 | 6 | * @wordpress-plugin |
| 11 | 7 | * Plugin Name: Posts Table with Search & Sort |
| 12 | 8 | * Plugin URI: https://wordpress.org/plugins/posts-data-table/ |
| 13 | - * Description: List your posts in an instantly searchable & sortable table. | |
| 14 | - * Version: 1.3.7 | |
| 15 | - * Author: Barn2 Plugins | |
| 16 | - * Author URI: https://barn2.com | |
| 9 | + * Description: Provides a shortcode to show a list of your posts in an instantly searchable & sortable table. | |
| 10 | + * Version: 1.2 | |
| 11 | + * Author: Barn2 Media | |
| 12 | + * Author URI: https://barn2.co.uk | |
| 17 | 13 | * Text Domain: posts-data-table |
| 18 | 14 | * Domain Path: /languages |
| 19 | 15 | * |
| 20 | - * Copyright: Barn2 Media Ltd | |
| 21 | - * License: GNU General Public License v3.0 | |
| 22 | - * License URI: https://www.gnu.org/licenses/gpl.html | |
| 16 | + * Copyright: Barn2 Media Ltd | |
| 17 | + * License: GNU General Public License v3.0 | |
| 18 | + * License URI: https://www.gnu.org/licenses/gpl.html | |
| 23 | 19 | */ |
| 24 | 20 | |
| 25 | -namespace Barn2\Plugin\Posts_Table_Search_Sort; | |
| 21 | +namespace Barn2\Plugin\Posts_Table_Search_Sort { | |
| 26 | 22 | |
| 27 | -// Prevent direct file access | |
| 28 | -if ( ! defined( '\ABSPATH' ) ) { | |
| 29 | - exit; | |
| 23 | + // Prevent direct file access | |
| 24 | + if ( ! defined( '\ABSPATH' ) ) { | |
| 25 | + exit; | |
| 26 | + } | |
| 27 | + | |
| 28 | + use Barn2\Lib\Util; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * The main plugin class. | |
| 32 | + * | |
| 33 | + * @author Barn2 Media <info@barn2.co.uk> | |
| 34 | + * @license GPL-3.0 | |
| 35 | + * @copyright Barn2 Media Ltd | |
| 36 | + */ | |
| 37 | + final class Plugin { | |
| 38 | + | |
| 39 | + const VERSION = '1.2'; | |
| 40 | + const FILE = __FILE__; | |
| 41 | + | |
| 42 | + private $helpers; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * The singleton instance | |
| 46 | + */ | |
| 47 | + private static $_instance = null; | |
| 48 | + | |
| 49 | + public static function instance() { | |
| 50 | + if ( is_null( self::$_instance ) ) { | |
| 51 | + self::$_instance = new self(); | |
| 52 | + } | |
| 53 | + return self::$_instance; | |
| 54 | + } | |
| 55 | + | |
| 56 | + public function load() { | |
| 57 | + add_action( 'plugins_loaded', array( $this, 'maybe_load_plugin' ) ); | |
| 58 | + } | |
| 59 | + | |
| 60 | + private function includes() { | |
| 61 | + require_once __DIR__ . '/includes/lib/interface-attachable.php'; | |
| 62 | + require_once __DIR__ . '/includes/lib/class-util.php'; | |
| 63 | + require_once __DIR__ . '/includes/lib/class-wp-settings-api-helper.php'; | |
| 64 | + | |
| 65 | + require_once __DIR__ . '/includes/class-settings.php'; | |
| 66 | + require_once __DIR__ . '/includes/class-simple-posts-table.php'; | |
| 67 | + require_once __DIR__ . '/includes/class-frontend-scripts.php'; | |
| 68 | + require_once __DIR__ . '/includes/class-table-shortcode.php'; | |
| 69 | + require_once __DIR__ . '/includes/deprecated.php'; | |
| 70 | + | |
| 71 | + require_once __DIR__ . '/includes/admin/class-admin-controller.php'; | |
| 72 | + require_once __DIR__ . '/includes/admin/class-admin-settings-page.php'; | |
| 73 | + } | |
| 74 | + | |
| 75 | + private function define_constants() { | |
| 76 | + define( 'PTSS_PLUGIN_BASENAME', plugin_basename( self::FILE ) ); | |
| 77 | + } | |
| 78 | + | |
| 79 | + public function maybe_load_plugin() { | |
| 80 | + // Don't load plugin if Pro version active | |
| 81 | + if ( class_exists( '\Posts_Table_Pro_Plugin' ) ) { | |
| 82 | + return; | |
| 83 | + } | |
| 84 | + | |
| 85 | + add_action( 'init', array( $this, 'init' ) ); | |
| 86 | + } | |
| 87 | + | |
| 88 | + public function init() { | |
| 89 | + $this->includes(); | |
| 90 | + $this->define_constants(); | |
| 91 | + $this->load_textdomain(); | |
| 92 | + | |
| 93 | + $this->helpers = array(); | |
| 94 | + | |
| 95 | + if ( Util::is_admin() ) { | |
| 96 | + $this->helpers['admin'] = new Admin_Controller(); | |
| 97 | + } | |
| 98 | + | |
| 99 | + if ( Util::is_front_end() ) { | |
| 100 | + // Register the posts table shortcode | |
| 101 | + $this->helpers['shortcode'] = new Table_Shortcode(); | |
| 102 | + $this->helpers['scripts'] = new Frontend_Scripts(); | |
| 103 | + } | |
| 104 | + | |
| 105 | + foreach ( $this->helpers as $attachable ) { | |
| 106 | + $attachable->attach(); | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + private function load_textdomain() { | |
| 111 | + load_plugin_textdomain( 'posts-data-table', false, dirname( plugin_basename( self::FILE ) ) . '/languages' ); | |
| 112 | + } | |
| 113 | + } | |
| 114 | + | |
| 115 | + // Load the plugin | |
| 116 | + Plugin::instance()->load(); | |
| 30 | 117 | } |
| 31 | 118 | |
| 32 | -const PLUGIN_VERSION = '1.3.7'; | |
| 33 | -const PLUGIN_FILE = __FILE__; | |
| 119 | +namespace { | |
| 34 | 120 | |
| 35 | -// Autoloader. | |
| 36 | -require_once __DIR__ . '/vendor/autoload.php'; | |
| 121 | + if ( ! function_exists( 'posts_table_search_sort' ) ) { | |
| 37 | 122 | |
| 38 | -/** | |
| 39 | - * Helper function to access the shared plugin instance. | |
| 40 | - * | |
| 41 | - * @return Plugin | |
| 42 | - */ | |
| 43 | -function posts_table_search_sort() { | |
| 44 | - return Plugin_Factory::create( PLUGIN_FILE, PLUGIN_VERSION ); | |
| 123 | + function posts_table_search_sort() { | |
| 124 | + return \Barn2\Plugin\Posts_Table_Search_Sort\Plugin::instance(); | |
| 125 | + } | |
| 126 | + } | |
| 45 | 127 | } |
| 46 | - | |
| 47 | -// Load the plugin. | |
| 48 | -posts_table_search_sort()->register(); | |