PluginProbe
Posts Table with Search & Sort / 1.2
Posts Table with Search & Sort v1.2
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 / includes / class-frontend-scripts.php

class-frontend-scripts.php in Posts Table with Search & Sort 1.2, at includes/class-frontend-scripts.php

71 lines 2.5 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 // Prevent direct file access
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 use Barn2\Lib\Util;
11
12 /**
13 * Registers the frontend styles and scripts for the post tables.
14 *
15 * @author Barn2 Media <info@barn2.co.uk>
16 * @license GPL-3.0
17 * @copyright Barn2 Media Ltd
18 */
19 class Frontend_Scripts implements \Barn2\Lib\Attachable {
20
21 public function attach() {
22 add_action( 'wp_enqueue_scripts', array( $this, 'register_styles' ) );
23 add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
24 }
25
26 public function register_styles() {
27 $suffix = Util::get_script_suffix();
28
29 wp_enqueue_style( 'jquery-data-tables', plugins_url( 'assets/js/datatables/datatables.min.css', Plugin::FILE ), array(), '1.10.18' );
30 wp_enqueue_style( 'posts-data-table', plugins_url( "assets/css/posts-data-table{$suffix}.css", Plugin::FILE ), array( 'jquery-data-tables' ), Plugin::VERSION );
31 }
32
33 public function register_scripts() {
34 $suffix = Util::get_script_suffix();
35
36 wp_enqueue_script( 'jquery-data-tables', plugins_url( "assets/js/datatables/datatables.min.js", Plugin::FILE ), array( 'jquery' ), '1.10.18', true );
37 wp_enqueue_script( 'posts-data-table', plugins_url( "assets/js/posts-data-table{$suffix}.js", Plugin::FILE ), array( 'jquery-data-tables' ), Plugin::VERSION, true );
38
39 $locale = get_locale();
40 $supported_locales = $this->get_supported_locales();
41
42 // Add language file to script if locale is supported (English file is not added as this is the default language)
43 if ( array_key_exists( $locale, $supported_locales ) ) {
44 wp_localize_script( 'posts-data-table', 'posts_data_table', array(
45 'langurl' => $supported_locales[$locale]
46 ) );
47 }
48 }
49
50 /**
51 * Returns an array of locales supported by the plugin.
52 * The array returned uses the locale as the array key mapped to the URL of the corresponding translation file.
53 *
54 * @return array The supported locales
55 */
56 private function get_supported_locales() {
57 $lang_file_base_url = plugins_url( 'languages/data-tables/', Plugin::FILE );
58
59 return apply_filters( 'posts_data_table_supported_languages', array(
60 'es_ES' => $lang_file_base_url . 'Spanish.json',
61 'fr_FR' => $lang_file_base_url . 'French.json',
62 'fr_BE' => $lang_file_base_url . 'French.json',
63 'fr_CA' => $lang_file_base_url . 'French.json',
64 'de_DE' => $lang_file_base_url . 'German.json',
65 'de_CH' => $lang_file_base_url . 'German.json',
66 'el' => $lang_file_base_url . 'Greek.json',
67 'el_EL' => $lang_file_base_url . 'Greek.json',
68 ) );
69 }
70 }
71