Elementor.php
99 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 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Registers WPP's icon for Elementor. |
| 61 | * |
| 62 | * @since 7.3.0 |
| 63 | */ |
| 64 | public function elementor_icon_css() { |
| 65 | $icon_file = esc_url(plugin_dir_url(dirname(__FILE__, 3))) . 'assets/images/flame.svg'; |
| 66 | |
| 67 | echo '<style> |
| 68 | .wpp-eicon { |
| 69 | display: inline-block; |
| 70 | width: 24px; |
| 71 | height: 24px; |
| 72 | background: url("' . $icon_file . '") center center /contain no-repeat; |
| 73 | } |
| 74 | </style>'; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Registers WPP widget. |
| 79 | * |
| 80 | * @since 7.3.0 |
| 81 | * @param \Elementor\Widgets_Manager $widgets_manager Elementor widgets manager. |
| 82 | */ |
| 83 | public function register_widget($widgets_manager) { |
| 84 | $registered_themes = $this->themer->get_themes(); |
| 85 | ksort($registered_themes); |
| 86 | |
| 87 | require_once(__DIR__ . '/widgets/widget.php'); |
| 88 | $widgets_manager->register( |
| 89 | new \Elementor_WPP_Widget( |
| 90 | [], |
| 91 | [ |
| 92 | 'image' => $this->thumbnail, |
| 93 | 'themer' => $this->themer |
| 94 | ] |
| 95 | ) |
| 96 | ); |
| 97 | } |
| 98 | } |
| 99 |