Script::backend_scripts()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
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
The function add_action 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 ignore-call  annotation

24
			/** @scrutinizer ignore-call */ 
25
   add_action( 'admin_head', array( $this, 'data_table_css' ) );
Loading history...
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
Bug introduced by
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 ignore-call  annotation

58
			/** @scrutinizer ignore-call */ 
59
   wp_enqueue_script( 'jsName', PLUGIN_JS . 'ui.js', array() );
Loading history...
59
			wp_localize_script( 'jsName', 'ajax', array( 'ajax_url' => admin_url('admin-ajax.php') ) );
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

59
			wp_localize_script( 'jsName', 'ajax', array( 'ajax_url' => /** @scrutinizer ignore-call */ admin_url('admin-ajax.php') ) );
Loading history...
Bug introduced by
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 ignore-call  annotation

59
			/** @scrutinizer ignore-call */ 
60
   wp_localize_script( 'jsName', 'ajax', array( 'ajax_url' => admin_url('admin-ajax.php') ) );
Loading history...
60
61
			wp_enqueue_style( 'cssName', PLUGIN_CSS . 'css.css' );
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

61
			/** @scrutinizer ignore-call */ 
62
   wp_enqueue_style( 'cssName', PLUGIN_CSS . 'css.css' );
Loading history...
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
Bug introduced by
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 ignore-call  annotation

72
			/** @scrutinizer ignore-call */ 
73
   wp_enqueue_script( 'jsName', PLUGIN_JS . 'ui.js', array() );
Loading history...
73
			wp_localize_script( 'jsName', 'ajax', array( 'ajax_url' => admin_url('admin-ajax.php') ) );
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

73
			/** @scrutinizer ignore-call */ 
74
   wp_localize_script( 'jsName', 'ajax', array( 'ajax_url' => admin_url('admin-ajax.php') ) );
Loading history...
Bug introduced by
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 ignore-call  annotation

73
			wp_localize_script( 'jsName', 'ajax', array( 'ajax_url' => /** @scrutinizer ignore-call */ admin_url('admin-ajax.php') ) );
Loading history...
74
75
			wp_enqueue_style( 'cssName', PLUGIN_CSS . 'css.css' );
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

75
			/** @scrutinizer ignore-call */ 
76
   wp_enqueue_style( 'cssName', PLUGIN_CSS . 'css.css' );
Loading history...
76
		}
77
	}
78
} ?>
0 ignored issues
show
Best Practice introduced by
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.

Loading history...
79