1
|
|
|
<?php |
2
|
|
|
namespace NirjharLo\WP_Plugin_Framework\Lib; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Add scripts to the plugin. CSS and JS. |
6
|
|
|
* |
7
|
|
|
* @author Nirjhar Lo |
8
|
|
|
* @package wp-plugin-framework |
9
|
|
|
*/ |
10
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; |
11
|
|
|
|
12
|
|
|
if ( ! class_exists( 'Script' ) ) { |
13
|
|
|
|
14
|
|
|
final class Script { |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Add scripts to front/back end heads |
19
|
|
|
* |
20
|
|
|
* @return Void |
21
|
|
|
*/ |
22
|
|
|
public function __construct() { |
23
|
|
|
|
24
|
|
|
add_action( 'admin_head', array( $this, 'data_table_css' ) ); |
|
|
|
|
25
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'backend_scripts' ) ); |
26
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Table css for settings page data tables |
32
|
|
|
* |
33
|
|
|
* @return String |
34
|
|
|
*/ |
35
|
|
|
public function data_table_css() { |
36
|
|
|
|
37
|
|
|
// Set condition to add script |
38
|
|
|
// if ( ! isset( $_GET['page'] ) || $_GET['page'] != 'pageName' ) return; |
39
|
|
|
|
40
|
|
|
$table_css = '<style type="text/css"> |
41
|
|
|
.wp-list-table .column-ColumnName { width: 100%; } |
42
|
|
|
</style>'; |
43
|
|
|
|
44
|
|
|
return $table_css; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Enter scripts into pages |
50
|
|
|
* |
51
|
|
|
* @return String |
52
|
|
|
*/ |
53
|
|
|
public function backend_scripts() { |
54
|
|
|
|
55
|
|
|
// Set condition to add script |
56
|
|
|
// if ( ! isset( $_GET['page'] ) || $_GET['page'] != 'pageName' ) return; |
57
|
|
|
|
58
|
|
|
wp_enqueue_script( 'jsName', PLUGIN_JS . 'ui.js', array() ); |
|
|
|
|
59
|
|
|
wp_localize_script( 'jsName', 'ajax', array( 'ajax_url' => admin_url('admin-ajax.php') ) ); |
|
|
|
|
60
|
|
|
|
61
|
|
|
wp_enqueue_style( 'cssName', PLUGIN_CSS . 'css.css' ); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Enter scripts into pages |
67
|
|
|
* |
68
|
|
|
* @return String |
69
|
|
|
*/ |
70
|
|
|
public function frontend_scripts() { |
71
|
|
|
|
72
|
|
|
wp_enqueue_script( 'jsName', PLUGIN_JS . 'ui.js', array() ); |
|
|
|
|
73
|
|
|
wp_localize_script( 'jsName', 'ajax', array( 'ajax_url' => admin_url('admin-ajax.php') ) ); |
|
|
|
|
74
|
|
|
|
75
|
|
|
wp_enqueue_style( 'cssName', PLUGIN_CSS . 'css.css' ); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} ?> |
|
|
|
|
79
|
|
|
|