| 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 |
|