-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-seo-widgets.php
120 lines (94 loc) · 3.84 KB
/
class-seo-widgets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace HarvesterWidgets;
class Harvester_SEO_Widgets {
private static $_instance = null;
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
public function page_harvester_styles() {
wp_register_style( 'page_harvester', plugins_url( 'assets/app.css', __FILE__ ) );
wp_enqueue_style( 'page_harvester' );
}
public function page_harvester_scripts() {
wp_register_script( 'ph_main', plugins_url( 'assets/main.js', __FILE__ ) );
}
public function add_module_attribute($tag, $handle, $src) {
// if not your script, do nothing and return original $tag
if ( 'ph_main' !== $handle ) {
return $tag;
}
// change the script tag by adding type="module" and return it.
$tag = '<script type="module" src="' . esc_url( $src ) . '"></script>';
return $tag;
}
public function editor_scripts() {
add_filter( 'script_loader_tag', [ $this, 'editor_scripts_as_a_module' ], 10, 2 );
wp_enqueue_script(
'elementor-hello-world-editor',
plugins_url( '/assets/js/editor/editor.js', __FILE__ ),
[
'elementor-editor',
],
'1.2.1',
true
);
}
public function editor_scripts_as_a_module( $tag, $handle ) {
if ( 'elementor-hello-world-editor' === $handle ) {
$tag = str_replace( '<script', '<script type="module"', $tag );
}
return $tag;
}
public function register_widgets( $widgets_manager ) {
// Its is now safe to include Widgets files
require_once( __DIR__ . '/widgets/interlink.php' );
require_once( __DIR__ . '/widgets/city-links.php' );
require_once( __DIR__ . '/widgets/blog-directory.php' );
require_once( __DIR__ . '/widgets/lead-form.php' );
require_once( __DIR__ . '/widgets/click-to-call.php' );
require_once( __DIR__ . '/widgets/concrete-weight-calculator.php' );
require_once( __DIR__ . '/widgets/location.php' );
require_once( __DIR__ . '/widgets/state.php' );
require_once( __DIR__ . '/widgets/phone-number.php' );
// Register Widgets
$widgets_manager->register( new Widgets\InterLink() );
$widgets_manager->register( new Widgets\CityLinks() );
$widgets_manager->register( new Widgets\BlogDirectory() );
$widgets_manager->register( new Widgets\LeadForm() );
$widgets_manager->register( new Widgets\ClickToCall() );
$widgets_manager->register( new Widgets\ConcreteWeightCalculator() );
$widgets_manager->register( new Widgets\Location() );
$widgets_manager->register( new Widgets\State() );
$widgets_manager->register( new Widgets\PhoneNumber() );
}
public function widget_category($elements_manager){
$elements_manager->add_category(
'page_harvester',
[
'title' => esc_html__( 'Page Harvester', 'page-harvester' ),
'icon' => 'fa fa-plug',
]
);
}
public function __construct() {
// Register widget scripts
add_action( 'elementor/frontend/before_enqueue_styles', [ $this, 'page_harvester_styles' ]);
// add_action( 'elementor/frontend/before_register_scripts', [ $this, 'page_harvester_scripts' ]);
// add_action( 'elementor/frontend/before_enqueue_scripts', [ $this, 'page_harvester_scripts' ]);
// add_action( 'elementor/preview/enqueue_scripts', [ $this, 'page_harvester_scripts' ]);
// add_action( 'elementor/preview/enqueue_scripts', [ $this, 'page_harvester_scripts' ]);
add_action( 'elementor/preview/enqueue_styles', [ $this, 'page_harvester_styles' ]);
add_action( 'wp_enqueue_scripts', [ $this, 'page_harvester_styles' ]);
add_action( 'wp_enqueue_scripts', [ $this, 'page_harvester_scripts' ]);
add_filter( 'script_loader_tag', array( $this,'add_module_attribute'), 10,3 );
// Register widgets
add_action( 'elementor/widgets/register', [ $this, 'register_widgets' ] );
// Create Widget Category
add_action( 'elementor/elements/categories_registered', [ $this, 'widget_category' ] );
}
}
// Instantiate Plugin Class
Harvester_SEO_Widgets::instance();