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