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' ) ); |
||||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||||
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() ); |
||||||||
0 ignored issues
–
show
The function
wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
59 | wp_localize_script( 'jsName', 'ajax', array( 'ajax_url' => admin_url('admin-ajax.php') ) ); |
||||||||
0 ignored issues
–
show
The function
admin_url was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The function
wp_localize_script was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
60 | |||||||||
61 | wp_enqueue_style( 'cssName', PLUGIN_CSS . 'css.css' ); |
||||||||
0 ignored issues
–
show
The function
wp_enqueue_style was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
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() ); |
||||||||
0 ignored issues
–
show
The function
wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
73 | wp_localize_script( 'jsName', 'ajax', array( 'ajax_url' => admin_url('admin-ajax.php') ) ); |
||||||||
0 ignored issues
–
show
The function
wp_localize_script was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The function
admin_url was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
74 | |||||||||
75 | wp_enqueue_style( 'cssName', PLUGIN_CSS . 'css.css' ); |
||||||||
0 ignored issues
–
show
The function
wp_enqueue_style was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
76 | } |
||||||||
77 | } |
||||||||
78 | } ?> |
||||||||
0 ignored issues
–
show
It is not recommended to use PHP's closing tag
?> in files other than templates.
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore. A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever. ![]() |
|||||||||
79 |