Completed
Push — develop ( 39f279...fe90ef )
by David
05:06
created

Wordlift_Admin::enqueue_styles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 17
rs 9.4286
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * The admin-specific functionality of the plugin.
5
 *
6
 * @link       http://wordlift.it
7
 * @since      1.0.0
8
 *
9
 * @package    Wordlift
10
 * @subpackage Wordlift/admin
11
 */
12
13
/**
14
 * The admin-specific functionality of the plugin.
15
 *
16
 * Defines the plugin name, version, and two examples hooks for how to
17
 * enqueue the admin-specific stylesheet and JavaScript.
18
 *
19
 * @package    Wordlift
20
 * @subpackage Wordlift/admin
21
 * @author     WordLift <[email protected]>
22
 */
23
class Wordlift_Admin {
24
25
	/**
26
	 * The ID of this plugin.
27
	 *
28
	 * @since    1.0.0
29
	 * @access   private
30
	 * @var      string    $plugin_name    The ID of this plugin.
31
	 */
32
	private $plugin_name;
33
34
	/**
35
	 * The version of this plugin.
36
	 *
37
	 * @since    1.0.0
38
	 * @access   private
39
	 * @var      string    $version    The current version of this plugin.
40
	 */
41
	private $version;
42
43
	/**
44
	 * Initialize the class and set its properties.
45
	 *
46
	 * @since    1.0.0
47
	 * @param      string    $plugin_name       The name of this plugin.
48
	 * @param      string    $version    The version of this plugin.
49
	 */
50
	public function __construct( $plugin_name, $version ) {
51
52
		$this->plugin_name = $plugin_name;
53
		$this->version = $version;
54
55
	}
56
57
	/**
58
	 * Register the stylesheets for the admin area.
59
	 *
60
	 * @since    1.0.0
61
	 */
62
	public function enqueue_styles() {
63
64
		/**
65
		 * This function is provided for demonstration purposes only.
66
		 *
67
		 * An instance of this class should be passed to the run() function
68
		 * defined in Wordlift_Loader as all of the hooks are defined
69
		 * in that particular class.
70
		 *
71
		 * The Wordlift_Loader will then create the relationship
72
		 * between the defined hooks and the functions defined in this
73
		 * class.
74
		 */
75
76
		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
77
78
	}
79
80
	/**
81
	 * Register the JavaScript for the admin area.
82
	 *
83
	 * @since    1.0.0
84
	 */
85
	public function enqueue_scripts() {
86
87
		/**
88
		 * This function is provided for demonstration purposes only.
89
		 *
90
		 * An instance of this class should be passed to the run() function
91
		 * defined in Wordlift_Loader as all of the hooks are defined
92
		 * in that particular class.
93
		 *
94
		 * The Wordlift_Loader will then create the relationship
95
		 * between the defined hooks and the functions defined in this
96
		 * class.
97
		 */
98
99
		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.js', array( 'jquery' ), $this->version, false );
100
101
		// Add WL api endpoint to retrieve entities based on their title. We only load it on the entity edit page.
102
		$entity_being_edited = get_post();
103
		if (  isset( $entity_being_edited->post_type ) && $entity_being_edited->post_type == Wordlift_Entity_Service::TYPE_NAME && is_numeric( get_the_ID() ) ) {
104
105
			wp_localize_script( $this->plugin_name, 'wlEntityTitleLiveSearchParams', array(
106
					'ajax_url' => admin_url( 'admin-ajax.php' ),
107
					'action'   => 'entity_by_title',
108
					'post_id'  => get_the_ID()
109
				)
110
			);
111
		}
112
	}
113
114
}
115