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