PluginProbe
Posts Table with Search & Sort / 1.1.5
Posts Table with Search & Sort v1.1.5
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 1.3.8 All 39 releases
posts-data-table / posts-data-table.php

posts-data-table.php in Posts Table with Search & Sort 1.1.5, at posts-data-table.php

145 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The main plugin file for Posts Table with Search & Sort.
4 *
5 * @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.5
10 * Author: Barn2 Media
11 * Author URI: https://barn2.co.uk
12 * Text Domain: posts-data-table
13 * Domain Path: /languages
14 *
15 * Copyright: Barn2 Media Ltd
16 * License: GNU General Public License v3.0
17 * License URI: https://www.gnu.org/licenses/gpl.html
18 */
19 // Prevent direct file access
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit;
22 }
23
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 {
33
34 const VERSION = '1.1.5';
35 const FILE = __FILE__;
36
37 /**
38 * The singleton instance
39 */
40 private static $_instance = null;
41
42 public function __construct() {
43 $this->includes();
44 }
45
46 public static function instance() {
47 if ( is_null( self::$_instance ) ) {
48 self::$_instance = new self();
49 }
50 return self::$_instance;
51 }
52
53 public function load() {
54 add_action( 'plugins_loaded', array( $this, 'maybe_load_plugin' ) );
55 }
56
57 private function includes() {
58 $includes = plugin_dir_path( self::FILE ) . 'includes/';
59
60 require_once $includes . 'class-posts-data-table-simple.php';
61 require_once $includes . 'class-posts-data-table-shortcode.php';
62 }
63
64 public function maybe_load_plugin() {
65 // Don't load plugin if Pro version active
66 if ( class_exists( 'Posts_Table_Pro_Plugin' ) ) {
67 return;
68 }
69
70 add_action( 'init', array( $this, 'init' ) );
71 add_filter( 'plugin_action_links_' . plugin_basename( self::FILE ), array( $this, 'add_pro_version_link' ) );
72 }
73
74 public function init() {
75 // Load the text domain
76 $this->load_textdomain();
77
78 // Register the posts table shortcode
79 Posts_Data_Table_Shortcode::register_shortcode();
80
81 // Register styles and scripts
82 add_action( 'wp_enqueue_scripts', array( $this, 'register_styles' ) );
83 add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
84 }
85
86 public function register_styles() {
87 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
88
89 wp_enqueue_style( 'jquery-data-tables', plugins_url( 'assets/css/datatables/datatables.min.css', self::FILE ), array(), '1.10.15' );
90 wp_enqueue_style( 'posts-data-table', plugins_url( "assets/css/posts-data-table{$suffix}.css", self::FILE ), array( 'jquery-data-tables' ), self::VERSION );
91 }
92
93 public function register_scripts() {
94 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
95
96 wp_enqueue_script( 'jquery-data-tables', plugins_url( "assets/js/datatables/datatables{$suffix}.js", self::FILE ), array( 'jquery' ), '1.10.15', true );
97 wp_enqueue_script( 'posts-data-table', plugins_url( "assets/js/posts-data-table{$suffix}.js", self::FILE ), array( 'jquery-data-tables' ), self::VERSION, true );
98
99 $locale = get_locale();
100 $supported_locales = $this->get_supported_locales();
101
102 // Add language file to script if locale is supported (English file is not added as this is the default language)
103 if ( array_key_exists( $locale, $supported_locales ) ) {
104 wp_localize_script( 'posts-data-table', 'posts_data_table', array(
105 'langurl' => $supported_locales[$locale]
106 ) );
107 }
108 }
109
110 public function add_pro_version_link( $links ) {
111 $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' ) );
112 return $links;
113 }
114
115 /**
116 * Returns an array of locales supported by the plugin.
117 * The array returned uses the locale as the array key mapped to the URL of the corresponding translation file.
118 *
119 * @return array The supported locales
120 */
121 private function get_supported_locales() {
122 $lang_file_base_url = plugins_url( 'languages/data-tables/', self::FILE );
123
124 return apply_filters( 'posts_data_table_supported_languages', array(
125 'es_ES' => $lang_file_base_url . 'Spanish.json',
126 'fr_FR' => $lang_file_base_url . 'French.json',
127 'fr_BE' => $lang_file_base_url . 'French.json',
128 'fr_CA' => $lang_file_base_url . 'French.json',
129 'de_DE' => $lang_file_base_url . 'German.json',
130 'de_CH' => $lang_file_base_url . 'German.json',
131 'el' => $lang_file_base_url . 'Greek.json',
132 'el_EL' => $lang_file_base_url . 'Greek.json',
133 ) );
134 }
135
136 private function load_textdomain() {
137 load_plugin_textdomain( 'posts-data-table', false, dirname( plugin_basename( self::FILE ) ) . '/languages' );
138 }
139
140 }
141 // Posts_Data_Table_Plugin class
142
143 /* Load the plugin */
144 Posts_Data_Table_Plugin::instance()->load();
145