PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / 7.3.8
WP Popular Posts v7.3.8
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 / Compatibility / Elementor / Elementor.php
wordpress-popular-posts / src / Compatibility / Elementor Last commit date
widgets 8 months ago Elementor.php 1 year ago
Elementor.php
121 lines
1 <?php
2 /**
3 * Integrates WPP with Elementor.
4 *
5 * @package WordPressPopularPosts
6 * @subpackage WordPressPopularPosts/Compatibility
7 * @author Hector Cabrera <me@cabrerahector.com>
8 */
9
10 namespace WordPressPopularPosts\Compatibility\Elementor;
11
12 use WordPressPopularPosts\Compatibility\Compat;
13 use WordPressPopularPosts\{Image, Themer};
14
15 class Elementor extends Compat
16 {
17 /**
18 * Image object.
19 *
20 * @var \WordPressPopularPosts\Image
21 * @access private
22 */
23 private $thumbnail;
24
25 /**
26 * Themer object.
27 *
28 * @var \WordPressPopularPosts\Themer $themer
29 * @access private
30 */
31 private $themer;
32
33 /**
34 * Construct.
35 *
36 * @param array $settings
37 */
38 public function __construct($settings, Image $image, Themer $themer)
39 {
40 $this->thumbnail = $image;
41 $this->themer = $themer;
42 }
43
44 /**
45 * Registers various WPPxElementor things.
46 *
47 * @since 7.3.0
48 */
49 public function init()
50 {
51 if ( defined('ELEMENTOR_VERSION') && version_compare(ELEMENTOR_VERSION, '3.5.0', '>=') ) {
52 // Registers flame icon
53 add_action('elementor/editor/after_enqueue_scripts', [$this, 'elementor_icon_css']);
54 // Registers WPP widget
55 add_action('elementor/widgets/register', [$this, 'register_widget']);
56 // Disable [wpp] shortcode AJAX loading in editor mode
57 add_filter('shortcode_atts_wpp', [$this, 'disable_ajax_in_editor'], 10, 4);
58 }
59 }
60
61 /**
62 * Registers WPP's icon for Elementor.
63 *
64 * @since 7.3.0
65 */
66 public function elementor_icon_css() {
67 $icon_file = esc_url(plugin_dir_url(dirname(__FILE__, 3))) . 'assets/images/flame.svg';
68
69 echo '<style>
70 .wpp-eicon {
71 display: inline-block;
72 width: 24px;
73 height: 24px;
74 background: url("' . $icon_file . '") center center /contain no-repeat;
75 }
76 </style>';
77 }
78
79 /**
80 * Registers WPP widget.
81 *
82 * @since 7.3.0
83 * @param \Elementor\Widgets_Manager $widgets_manager Elementor widgets manager.
84 */
85 public function register_widget($widgets_manager) {
86 $registered_themes = $this->themer->get_themes();
87 ksort($registered_themes);
88
89 require_once(__DIR__ . '/widgets/widget.php');
90 $widgets_manager->register(
91 new \Elementor_WPP_Widget(
92 [],
93 [
94 'image' => $this->thumbnail,
95 'themer' => $this->themer
96 ]
97 )
98 );
99 }
100
101 /**
102 * Disables [wpp] AJAX loading in editor mode.
103 *
104 * @since 7.4.0
105 * @param array $out The output array of shortcode attributes.
106 * @param array $pairs The supported attributes and their defaults.
107 * @param array $atts The user defined shortcode attributes.
108 * @param string $shortcode The shortcode name.
109 */
110 public function disable_ajax_in_editor(array $out, array $pairs, array $atts, string $shortcode) {
111 if (
112 'wpp' === $shortcode &&
113 \Elementor\Plugin::$instance->editor->is_edit_mode()
114 ) {
115 $out['ajaxify'] = 0;
116 }
117
118 return $out;
119 }
120 }
121