class-delete-old-posts-filters.php
1 month ago
class-delete-old-posts-redirects.php
1 month ago
class-delete-old-posts.php
1 month ago
class-enqueue-assets.php
1 month ago
class-enqueue-assets.php
73 lines
| 1 | <?php |
| 2 | namespace DEL\OLD\Posts\Cls\Assets; |
| 3 | |
| 4 | /** |
| 5 | * Enqueue Assets |
| 6 | */ |
| 7 | |
| 8 | class Enqueue_Assets { |
| 9 | |
| 10 | /** |
| 11 | * Constructor. |
| 12 | */ |
| 13 | public function __construct() { |
| 14 | /** |
| 15 | * Actions. |
| 16 | */ |
| 17 | add_action( 'admin_enqueue_scripts', [ $this, 'deloldp_EnqueueAssets' ] ); |
| 18 | add_filter( 'style_loader_src', [ $this, 'deloldp_StyleandScriptSrcVerStrip' ], 10, 2 ); |
| 19 | add_filter( 'script_loader_src', [ $this, 'deloldp_StyleandScriptSrcVerStrip' ], 10, 2 ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Enqueue editor scripts & styles. |
| 24 | * |
| 25 | */ |
| 26 | public function deloldp_EnqueueAssets() { |
| 27 | global $wp; |
| 28 | |
| 29 | /** |
| 30 | * check the page url |
| 31 | */ |
| 32 | $current_url = home_url($_SERVER['REQUEST_URI']); |
| 33 | |
| 34 | /** |
| 35 | * load assets only if is page of the plugin |
| 36 | */ |
| 37 | if( stristr( $current_url, 'page=delete-old-posts' ) !== false ) { |
| 38 | $vers = $this->delop_get_plugin_version(); |
| 39 | wp_enqueue_style ( 'tailwind', plugin_dir_url( __FILE__ ) . '../assets/css/tailwind.css', false, $vers, 'all'); |
| 40 | wp_enqueue_script ( 'alpine', plugin_dir_url( __FILE__ ) . '../assets/js/alpine.min.js', [], $vers, true); |
| 41 | wp_enqueue_script ( 'alpine_script', plugin_dir_url( __FILE__ ) . '../assets/js/deloldp_alpine.js', [], $vers, true); |
| 42 | wp_enqueue_script ( 'multi_select', plugin_dir_url( __FILE__ ) . '../assets/js/delp_multi_select.js', [], $vers, true); |
| 43 | wp_enqueue_style ( 'multi_select', plugin_dir_url( __FILE__ ) . '../assets/css/delp_multi_select.css', false, $vers, 'all'); |
| 44 | wp_enqueue_script ( 'delp_script', plugin_dir_url( __FILE__ ) . '../assets/js/delp_script.js', ['jquery'], $vers, true); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Strip WP Version in Stylesheets/Scripts |
| 50 | */ |
| 51 | function deloldp_StyleandScriptSrcVerStrip( $src, $handle ) { |
| 52 | /** |
| 53 | * use it for external css or js |
| 54 | */ |
| 55 | if(stristr($src,'alpinejs')) $src = remove_query_arg( 'ver', $src ); |
| 56 | return $src; |
| 57 | } |
| 58 | |
| 59 | function delop_get_plugin_version(){ |
| 60 | if ( is_admin() ) { |
| 61 | if( ! function_exists('get_plugin_data') ){ |
| 62 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 63 | } |
| 64 | $plugin_data = get_plugin_data( dirname(__DIR__, 1) . '/' . basename(dirname(__DIR__, 1)) . '.php' ); |
| 65 | |
| 66 | if( isset($plugin_data['Version']) && $plugin_data['Version'] != '' ) return $plugin_data['Version']; |
| 67 | else return date('d_m_Y_H'); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // new Enqueue_Assets(); |
| 73 |