Completed
Push — master ( 4713b5...48986a )
by David
05:28 queued 15s
created

Wordlift_Public   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 95
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A enqueue_styles() 0 17 1
B enqueue_scripts() 0 30 2
1
<?php
2
3
/**
4
 * The public-facing functionality of the plugin.
5
 *
6
 * @link       https://wordlift.io
7
 * @since      1.0.0
8
 *
9
 * @package    Wordlift
10
 * @subpackage Wordlift/public
11
 */
12
13
/**
14
 * The public-facing 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/public
21
 * @author     WordLift <[email protected]>
22
 */
23
class Wordlift_Public {
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
	 *
48
	 * @param      string $plugin_name The name of the plugin.
49
	 * @param      string $version     The version of this plugin.
50
	 */
51
	public function __construct( $plugin_name, $version ) {
52
53
		$this->plugin_name = $plugin_name;
54
		$this->version     = $version;
55
56
	}
57
58
	/**
59
	 * Register the stylesheets for the public-facing side of the site.
60
	 *
61
	 * @since    1.0.0
62
	 */
63
	public function enqueue_styles() {
64
65
		/**
66
		 * This function is provided for demonstration purposes only.
67
		 *
68
		 * An instance of this class should be passed to the run() function
69
		 * defined in Wordlift_Loader as all of the hooks are defined
70
		 * in that particular class.
71
		 *
72
		 * The Wordlift_Loader will then create the relationship
73
		 * between the defined hooks and the functions defined in this
74
		 * class.
75
		 */
76
77
		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-public.css', array(), $this->version, 'all' );
78
79
	}
80
81
	/**
82
	 * Register the stylesheets for the public-facing side of the site.
83
	 *
84
	 * @since    1.0.0
85
	 */
86
	public function enqueue_scripts() {
87
88
		/**
89
		 * This function is provided for demonstration purposes only.
90
		 *
91
		 * An instance of this class should be passed to the run() function
92
		 * defined in Wordlift_Loader as all of the hooks are defined
93
		 * in that particular class.
94
		 *
95
		 * The Wordlift_Loader will then create the relationship
96
		 * between the defined hooks and the functions defined in this
97
		 * class.
98
		 */
99
100
		// Prepare a settings array for client-side functions.
101
		$settings = array(
102
			'ajaxUrl' => admin_url( 'admin-ajax.php' ),
103
		);
104
105
		// If we're in a single page, then print out the post id.
106
		if ( is_singular() ) {
107
			$settings['postId'] = get_the_ID();
108
		}
109
110
		// Note that we switched the js to be loaded in footer, since it is loading
111
		// the json-ld representation.
112
		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-public.js', array( 'jquery' ), $this->version, true );
113
		wp_localize_script( $this->plugin_name, 'wlSettings', $settings );
114
115
	}
116
117
}
118