-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOpen-Elementor-Widget.php
61 lines (53 loc) · 2.11 KB
/
Open-Elementor-Widget.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
<?php
/*
Plugin Name: OpenWidgetElementor
Description: Custom widget for elementor
Version: 1.0
Author: Davide
*/ function remove_text_before_last_post_title($excerpt)
{
// Ottieni l'ultimo post
$last_post = get_posts(array(
'numberposts' => 1,
'order' => 'DESC',
))[0];
// Ottieni il titolo dell'ultimo post
$last_post_title = $last_post->post_title;
// Trova la posizione del titolo dell'ultimo post nell'excerpt
$position = strpos($excerpt, $last_post_title);
// Se il titolo è presente, restituisce solo il testo dopo di esso
if ($position !== false) {
$excerpt=preg_replace('#<a.*?>.*?</a>#i', '', $excerpt);
return substr($excerpt, $position);
}
$excerpt = preg_replace('#<a.*?>.*?</a>#i', '', $excerpt);
// Se il titolo non è presente, restituisce l'excerpt originale
return $excerpt;
}
add_filter('wp_trim_excerpt', 'remove_text_before_last_post_title');
add_action('elementor/widgets/widgets_registered', 'register_OpenElementorWidget_widgets');
function add_elementor_widget_categories($elements_manager)
{
$elements_manager->add_category(
'OpenWidget',
[
'title' => esc_html__('OpenWidget', 'open-elementor-widget'),
'icon' => 'fa fa-plug',
]
);
}
add_action('elementor/elements/categories_registered', 'add_elementor_widget_categories');
function register_OpenElementorWidget_widgets($widgets_manager)
{
// Include and register the latest-posts-hover widget
require_once(plugin_dir_path(__FILE__) . 'widgets/Latest-Posts-Hover.php');
$widgets_manager->register_widget_type(new \Latest_Posts_Hover_Widget());
require_once(plugin_dir_path(__FILE__) . 'widgets/Post-info.php');
$widgets_manager->register_widget_type(new \Post_Info_Widget());
require_once(plugin_dir_path(__FILE__) . 'widgets/Animated-Text.php');
$widgets_manager->register_widget_type(new \Animated_Text_Widget());
require_once(plugin_dir_path(__FILE__) . 'widgets/Image-hover.php');
$widgets_manager->register_widget_type(new \Image_Hover_Widget());
require_once(plugin_dir_path(__FILE__) . 'widgets/Article.php');
$widgets_manager->register_widget_type(new \Article_Widget());
}