PluginProbe
Posts Table with Search & Sort / 1.2
Posts Table with Search & Sort v1.2
1.4.13 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 All 40 releases
← All changes | posts-data-table.php +93 -93 1.1.11.2 View file →
@@ -2,126 +2,126 @@
2 2
3 3 /**
4 4 * The main plugin file for Posts Table with Search & Sort.
5 5 *
6 - * @package Posts_Data_Table
7 - * @author Barn2 Media <info@barn2.co.uk>
8 - * @license GPL-3.0
9 - * @link https://barn2.co.uk
10 - * @copyright 2016-2017 Barn2 Media Ltd
11 - *
12 6 * @wordpress-plugin
13 - * Plugin Name: Posts Table with Search & Sort
14 - * Plugin URI: https://wordpress.org/plugins/posts-data-table/
15 - * Description: Provides a shortcode to show a list of your posts in an instantly searchable & sortable table.
16 - * Version: 1.1.1
17 - * Author: Barn2 Media
18 - * Author URI: https://barn2.co.uk
19 - * Text Domain: posts-data-table
20 - * Domain Path: /languages
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
21 15 *
22 - * Copyright: 2016-2017 Barn2 Media Ltd
23 - * License: GNU General Public License v3.0
24 - * License URI: http://www.gnu.org/licenses/gpl-3.0.html
16 + * Copyright: Barn2 Media Ltd
17 + * License: GNU General Public License v3.0
18 + * License URI: https://www.gnu.org/licenses/gpl.html
25 19 */
26 -// Prevent direct file access
27 -if ( !defined( 'ABSPATH' ) ) {
28 - exit;
29 -}
30 20
31 -// Current version of this plugin
32 -define( 'POSTS_DATA_TABLE_VERSION', '1.1.1' );
21 +namespace Barn2\Plugin\Posts_Table_Search_Sort {
33 22
34 -class Posts_Data_Table_Plugin {
23 + // Prevent direct file access
24 + if ( ! defined( '\ABSPATH' ) ) {
25 + exit;
26 + }
35 27
36 - public function __construct() {
37 - $this->includes();
28 + use Barn2\Lib\Util;
38 29
39 - add_action( 'plugins_loaded', array( $this, 'maybe_load_plugin' ) );
40 - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_plugin_settings_link' ) );
41 - }
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 {
42 38
43 - private function includes() {
44 - $includes = plugin_dir_path( __FILE__ ) . 'includes/';
39 + const VERSION = '1.2';
40 + const FILE = __FILE__;
45 41
46 - require_once $includes . 'class-posts-data-table-simple.php';
47 - require_once $includes . 'class-posts-data-table-shortcode.php';
48 - }
42 + private $helpers;
49 43
50 - public function maybe_load_plugin() {
51 - // Don't init plugin if Pro version exists
52 - if ( class_exists( 'Posts_Table_Pro_Plugin' ) ) {
53 - return;
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 54 }
55 55
56 - // Load the text domain - should go on 'plugins_loaded' hook
57 - $this->load_textdomain();
56 + public function load() {
57 + add_action( 'plugins_loaded', array( $this, 'maybe_load_plugin' ) );
58 + }
58 59
59 - add_action( 'init', array( $this, 'init' ) );
60 - }
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';
61 64
62 - public function load_textdomain() {
63 - load_plugin_textdomain( 'posts-data-table', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
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';
65 70
66 - public function init() {
67 - new Posts_Data_Table_Shortcode();
71 + require_once __DIR__ . '/includes/admin/class-admin-controller.php';
72 + require_once __DIR__ . '/includes/admin/class-admin-settings-page.php';
73 + }
68 74
69 - // Register styles and scripts
70 - add_action( 'wp_enqueue_scripts', array( $this, 'register_styles' ) );
71 - add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
72 - }
75 + private function define_constants() {
76 + define( 'PTSS_PLUGIN_BASENAME', plugin_basename( self::FILE ) );
77 + }
73 78
74 - public function register_styles() {
75 - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : 'min.';
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 + }
76 84
77 - wp_enqueue_style( 'jquery-data-tables', plugins_url( 'assets/css/datatables/datatables.min.css', __FILE__ ), array(), '1.10.15' );
78 - wp_enqueue_style( 'posts-data-table', plugins_url( "assets/css/posts-data-table.{$suffix}css", __FILE__ ), array( 'jquery-data-tables' ), POSTS_DATA_TABLE_VERSION );
79 - }
85 + add_action( 'init', array( $this, 'init' ) );
86 + }
80 87
81 - public function register_scripts() {
82 - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : 'min.';
88 + public function init() {
89 + $this->includes();
90 + $this->define_constants();
91 + $this->load_textdomain();
83 92
84 - wp_enqueue_script( 'jquery-data-tables', plugins_url( "assets/js/datatables/datatables.{$suffix}js", __FILE__ ), array( 'jquery' ), '1.10.15', true );
85 - wp_enqueue_script( 'posts-data-table', plugins_url( "assets/js/posts-data-table.{$suffix}js", __FILE__ ), array( 'jquery-data-tables' ), POSTS_DATA_TABLE_VERSION, true );
93 + $this->helpers = array();
86 94
87 - $locale = get_locale();
88 - $supported_locales = $this->get_supported_locales();
95 + if ( Util::is_admin() ) {
96 + $this->helpers['admin'] = new Admin_Controller();
97 + }
89 98
90 - // Add language file to script if locale is supported (English file is not added as this is the default language)
91 - if ( array_key_exists( $locale, $supported_locales ) ) {
92 - wp_localize_script( 'posts-data-table', 'posts_data_table', array(
93 - 'langurl' => $supported_locales[$locale]
94 - ) );
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 + }
95 108 }
109 +
110 + private function load_textdomain() {
111 + load_plugin_textdomain( 'posts-data-table', false, dirname( plugin_basename( self::FILE ) ) . '/languages' );
112 + }
96 113 }
97 114
98 - public function add_plugin_settings_link( $links ) {
99 - $links[] = sprintf( '<a href="%1$s" target="_blank">%2$s</a>', esc_url( 'https://barn2.co.uk/wordpress-plugins/posts-table-pro/' ), __( 'Pro Version', 'posts-data-table' ) );
100 - return $links;
101 - }
115 + // Load the plugin
116 + Plugin::instance()->load();
117 +}
102 118
103 - /**
104 - * Returns an array of locales supported by the plugin.
105 - * The array returned uses the locale as the array key mapped to the URL of the corresponding translation file.
106 - *
107 - * @return array The supported locales
108 - */
109 - private function get_supported_locales() {
110 - $lang_file_base_url = plugins_url( 'languages/data-tables/', __FILE__ );
119 +namespace {
111 120
112 - return array(
113 - 'es_ES' => $lang_file_base_url . 'Spanish.json',
114 - 'fr_FR' => $lang_file_base_url . 'French.json',
115 - 'fr_BE' => $lang_file_base_url . 'French.json',
116 - 'fr_CA' => $lang_file_base_url . 'French.json',
117 - 'de_DE' => $lang_file_base_url . 'German.json',
118 - 'de_CH' => $lang_file_base_url . 'German.json',
119 - 'el' => $lang_file_base_url . 'Greek.json',
120 - 'el_EL' => $lang_file_base_url . 'Greek.json',
121 - );
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 + }
122 126 }
123 -
124 127 }
125 -// end class
126 -
127 -$posts_data_table = new Posts_Data_Table_Plugin();