PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / trunk
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO vtrunk
2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.10.0 1.11.0 All 47 releases
thinkrank / includes / editor / class-elementor-manager.php

class-elementor-manager.php in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO trunk, at includes/editor/class-elementor-manager.php

112 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Elementor Integration Manager
5 *
6 * Registers ThinkRank's Elementor widgets (FAQ, HowTo, Table of Contents) so
7 * Elementor-built pages get the same content patterns and structured data as
8 * the Gutenberg blocks. Notably, RankMath ships no such widgets — Elementor
9 * users there get schema only by decorating Elementor's own accordion.
10 *
11 * All hooks are Elementor-fired: when Elementor is not active, none of this
12 * runs and no Elementor classes are referenced.
13 *
14 * @package ThinkRank
15 * @subpackage Editor
16 * @since 1.18.0
17 */
18
19 declare(strict_types=1);
20
21 namespace ThinkRank\Editor;
22
23 // Prevent direct access
24 if (!defined('ABSPATH')) {
25 exit;
26 }
27
28 /**
29 * Elementor Manager.
30 *
31 * @since 1.18.0
32 */
33 class Elementor_Manager {
34
35 /**
36 * Wire up hooks. Safe without Elementor — the hooks simply never fire.
37 *
38 * @return void
39 */
40 public function init(): void {
41 add_action('elementor/elements/categories_registered', [$this, 'register_category']);
42 add_action('elementor/widgets/register', [$this, 'register_widgets']);
43 add_action('wp_enqueue_scripts', [$this, 'register_widget_styles']);
44 add_action('elementor/editor/after_enqueue_styles', [$this, 'register_widget_styles']);
45 add_action('elementor/preview/enqueue_styles', [$this, 'enqueue_preview_styles']);
46 }
47
48 /**
49 * Add the ThinkRank widget category.
50 *
51 * @param object $elements_manager Elementor elements manager.
52 * @return void
53 */
54 public function register_category($elements_manager): void {
55 $elements_manager->add_category('thinkrank', [
56 'title' => __('ThinkRank', 'thinkrank'),
57 'icon' => 'eicon-search',
58 ]);
59 }
60
61 /**
62 * Register the widgets.
63 *
64 * @param object $widgets_manager Elementor widgets manager.
65 * @return void
66 */
67 public function register_widgets($widgets_manager): void {
68 $widgets_manager->register(new Elementor\FAQ_Widget());
69 $widgets_manager->register(new Elementor\Howto_Widget());
70 $widgets_manager->register(new Elementor\TOC_Widget());
71 }
72
73 /**
74 * Register (not enqueue) the shared block stylesheets so widgets can
75 * declare them via get_style_depends() — Elementor then loads them only
76 * on pages that actually use the widget.
77 *
78 * @return void
79 */
80 public function register_widget_styles(): void {
81 foreach (['faq-block', 'howto-block', 'toc-block'] as $handle) {
82 $css = THINKRANK_PLUGIN_DIR . "assets/{$handle}.css";
83 if (!file_exists($css)) {
84 continue;
85 }
86
87 $asset_path = THINKRANK_PLUGIN_DIR . "assets/{$handle}.asset.php";
88 $asset = file_exists($asset_path) ? include $asset_path : [];
89
90 wp_register_style(
91 "thinkrank-{$handle}",
92 THINKRANK_PLUGIN_URL . "assets/{$handle}.css",
93 [],
94 $asset['version'] ?? THINKRANK_VERSION
95 );
96 }
97 }
98
99 /**
100 * In the Elementor editor preview all styles must load up front (the
101 * preview doesn't know which widgets will be dropped in).
102 *
103 * @return void
104 */
105 public function enqueue_preview_styles(): void {
106 $this->register_widget_styles();
107 foreach (['faq-block', 'howto-block', 'toc-block'] as $handle) {
108 wp_enqueue_style("thinkrank-{$handle}");
109 }
110 }
111 }
112