| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The main plugin file for Posts Table with Search & Sort. |
| 5 |
* |
| 6 |
* @wordpress-plugin |
| 7 |
* Plugin Name: Posts Table with Search & Sort |
| 8 |
* Plugin URI: https://wordpress.org/plugins/posts-data-table/ |
| 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 |
| 13 |
* Text Domain: posts-data-table |
| 14 |
* Domain Path: /languages |
| 15 |
* |
| 16 |
* Copyright: Barn2 Media Ltd |
| 17 |
* License: GNU General Public License v3.0 |
| 18 |
* License URI: https://www.gnu.org/licenses/gpl.html |
| 19 |
*/ |
| 20 |
|
| 21 |
namespace Barn2\Plugin\Posts_Table_Search_Sort { |
| 22 |
|
| 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(); |
| 117 |
} |
| 118 |
|
| 119 |
namespace { |
| 120 |
|
| 121 |
if ( ! function_exists( 'posts_table_search_sort' ) ) { |
| 122 |
|
| 123 |
function posts_table_search_sort() { |
| 124 |
return \Barn2\Plugin\Posts_Table_Search_Sort\Plugin::instance(); |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
|