PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / 7.4.0
WP Popular Posts v7.4.0
4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 5.0.0 5.0.1 5.0.2 5.1.0 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.1.2 6.1.3 6.1.4 6.2.0 6.2.1 6.3.0 6.3.1 6.3.2 6.3.3 6.3.4 6.4.0 6.4.1 6.4.2 7.0.0 7.0.1 7.1.0 7.2.0 7.3.0 7.3.1 7.3.2 7.3.3 7.3.4 7.3.5 7.3.6 7.3.7 7.3.8 7.4.0 trunk 2.3.7 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.2 4.0.3 4.0.5 4.0.6
wordpress-popular-posts / src / Front / Front.php
wordpress-popular-posts / src / Front Last commit date
Front.php 1 year ago
Front.php
128 lines
1 <?php
2 /**
3 * The public-facing functionality of the plugin.
4 *
5 * Defines hooks to enqueue the public-specific stylesheet and JavaScript.
6 *
7 * @package WordPressPopularPosts
8 * @subpackage WordPressPopularPosts/Front
9 * @author Hector Cabrera <me@cabrerahector.com>
10 */
11
12 namespace WordPressPopularPosts\Front;
13
14 use WordPressPopularPosts\{ Helper, Translate };
15
16 class Front {
17
18 /**
19 * Plugin options.
20 *
21 * @var array $config
22 * @access private
23 */
24 private $config;
25
26 /**
27 * Translate object.
28 *
29 * @var \WordPressPopularPosts\Translate $translate
30 * @access private
31 */
32 private $translate;
33
34 /**
35 * Construct.
36 *
37 * @since 5.0.0
38 * @param array $config Admin settings.
39 * @param \WordPressPopularPosts\Translate $translate Translate class.
40 */
41 public function __construct(array $config, Translate $translate)
42 {
43 $this->config = $config;
44 $this->translate = $translate;
45 }
46
47 /**
48 * WordPress public-facing hooks.
49 *
50 * @since 5.0.0
51 */
52 public function hooks()
53 {
54 add_action('wp_head', [$this, 'inline_loading_css']);
55 add_action('wp_head', [$this, 'enqueue_scripts'], 2);
56 add_action('wp_enqueue_scripts', [$this, 'enqueue_styles']);
57 }
58
59 /**
60 * Inserts CSS related to the loading animation into <head>
61 *
62 * @since 5.3.0
63 */
64 public function inline_loading_css()
65 {
66 $wpp_insert_loading_animation_styles = apply_filters('wpp_insert_loading_animation_styles', true);
67
68 if ( $wpp_insert_loading_animation_styles ) :
69 ?>
70 <style id="wpp-loading-animation-styles">@-webkit-keyframes bgslide{from{background-position-x:0}to{background-position-x:-200%}}@keyframes bgslide{from{background-position-x:0}to{background-position-x:-200%}}.wpp-widget-block-placeholder,.wpp-shortcode-placeholder{margin:0 auto;width:60px;height:3px;background:#dd3737;background:linear-gradient(90deg,#dd3737 0%,#571313 10%,#dd3737 100%);background-size:200% auto;border-radius:3px;-webkit-animation:bgslide 1s infinite linear;animation:bgslide 1s infinite linear}</style>
71 <?php
72 endif;
73 }
74
75 /**
76 * Enqueues public facing styles.
77 *
78 * @since 5.0.0
79 */
80 public function enqueue_styles()
81 {
82 if ( $this->config['tools']['css'] ) {
83 $theme_file = get_stylesheet_directory() . '/wpp.css';
84
85 if ( @is_file($theme_file) ) {
86 wp_enqueue_style('wordpress-popular-posts-css', get_stylesheet_directory_uri() . '/wpp.css', [], WPP_VERSION, 'all');
87 } // Load stock stylesheet
88 else {
89 wp_enqueue_style('wordpress-popular-posts-css', plugin_dir_url(dirname(dirname(__FILE__))) . 'assets/css/wpp.css', [], WPP_VERSION, 'all');
90 }
91 }
92 }
93
94 /**
95 * Enqueues public facing scripts.
96 *
97 * @since 7.0.0
98 */
99 public function enqueue_scripts()
100 {
101 $is_single = 0;
102
103 if (
104 ( 0 == $this->config['tools']['log']['level'] && ! is_user_logged_in() )
105 || ( 1 == $this->config['tools']['log']['level'] )
106 || ( 2 == $this->config['tools']['log']['level'] && is_user_logged_in() )
107 ) {
108 $is_single = Helper::is_single();
109 }
110
111 $wpp_js_url = plugin_dir_url(dirname(dirname(__FILE__))) . 'assets/js/wpp.' . (! defined('WP_DEBUG') || false === WP_DEBUG ? 'min.' : '') . 'js?ver=' . WPP_VERSION;
112
113 wp_print_script_tag(
114 [
115 'id' => 'wpp-js',
116 'src' => $wpp_js_url,
117 'data-sampling' => (int) $this->config['tools']['sampling']['active'],
118 'data-sampling-rate' => (int) $this->config['tools']['sampling']['rate'],
119 'data-api-url' => esc_url_raw(rest_url('wordpress-popular-posts')),
120 'data-post-id' => (int) $is_single,
121 'data-token' => wp_create_nonce('wp_rest'),
122 'data-lang' => function_exists('PLL') ? $this->translate->get_current_language() : 0,
123 'data-debug' => (int) WP_DEBUG
124 ]
125 );
126 }
127 }
128