PluginProbe
Posts Table with Search & Sort / 1.3.1
Posts Table with Search & Sort v1.3.1
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
posts-data-table / src / Frontend_Scripts.php

Frontend_Scripts.php in Posts Table with Search & Sort 1.3.1, at src/Frontend_Scripts.php

78 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Barn2\Plugin\Posts_Table_Search_Sort;
4
5 use Barn2\Lib\Util,
6 Barn2\Lib\Registerable,
7 Barn2\Lib\Plugin\Plugin,
8 Barn2\Lib\Service;
9
10 /**
11 * Registers the frontend styles and scripts for the post tables.
12 *
13 * @author Barn2 Media <info@barn2.co.uk>
14 * @license GPL-3.0
15 * @copyright Barn2 Media Ltd
16 */
17 class Frontend_Scripts implements Registerable, Service {
18
19 const DATATABLES_VERSION = '1.10.21';
20
21 private $plugin;
22
23 public function __construct( Plugin $plugin ) {
24 $this->plugin = $plugin;
25 }
26
27 public function register() {
28 \add_action( 'wp_enqueue_scripts', array( $this, 'register_styles' ) );
29 \add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
30 }
31
32 public function register_styles() {
33 $suffix = Util::get_script_suffix();
34
35 \wp_register_style( 'jquery-data-tables', \plugins_url( 'assets/js/datatables/datatables.min.css', $this->plugin->get_file() ), array(), self::DATATABLES_VERSION );
36 \wp_register_style( 'posts-data-table', \plugins_url( "assets/css/posts-data-table{$suffix}.css", $this->plugin->get_file() ), array( 'jquery-data-tables' ), $this->plugin->get_version() );
37 }
38
39 public function register_scripts() {
40 $suffix = Util::get_script_suffix();
41
42 \wp_register_script( 'jquery-data-tables', \plugins_url( "assets/js/datatables/datatables.min.js", $this->plugin->get_file() ), array( 'jquery' ), self::DATATABLES_VERSION, true );
43 \wp_register_script( 'posts-data-table', \plugins_url( "assets/js/posts-data-table{$suffix}.js", $this->plugin->get_file() ), array( 'jquery-data-tables' ), $this->plugin->get_version(), true );
44
45 $locale = \get_locale();
46 $supported_locales = $this->get_supported_locales();
47
48 // Add language file to script if locale is supported (English file is not added as this is the default language)
49 if ( \array_key_exists( $locale, $supported_locales ) ) {
50 \wp_localize_script( 'posts-data-table', 'posts_data_table', array(
51 'langurl' => $supported_locales[$locale]
52 ) );
53 }
54 }
55
56 /**
57 * Returns an array of locales supported by the plugin.
58 * The array returned uses the locale as the array key mapped to the URL of the corresponding translation file.
59 *
60 * @return array The supported locales
61 */
62 private function get_supported_locales() {
63 $lang_file_base_url = \plugins_url( 'languages/data-tables/', $this->plugin->get_file() );
64
65 return \apply_filters( 'posts_data_table_supported_languages', array(
66 'es_ES' => $lang_file_base_url . 'Spanish.json',
67 'fr_FR' => $lang_file_base_url . 'French.json',
68 'fr_BE' => $lang_file_base_url . 'French.json',
69 'fr_CA' => $lang_file_base_url . 'French.json',
70 'de_DE' => $lang_file_base_url . 'German.json',
71 'de_CH' => $lang_file_base_url . 'German.json',
72 'el' => $lang_file_base_url . 'Greek.json',
73 'el_EL' => $lang_file_base_url . 'Greek.json',
74 ) );
75 }
76
77 }
78