Skip to content

Commit 575453b

Browse files
update
1 parent c7c91f9 commit 575453b

File tree

3 files changed

+140
-52
lines changed

3 files changed

+140
-52
lines changed

inc/helper.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,11 @@ function filter_search_by_date_and_category($query)
461461

462462
if (! function_exists('aae_addon_breadcrumbs')) {
463463

464-
function aae_addon_breadcrumbs()
464+
function aae_addon_breadcrumbs($tag = 'div', $separator = ' » ')
465465
{
466466
global $post;
467467

468-
$separator = ' » ';
469-
echo '<div class="aae-breadcrumbs"><a href="' . esc_url(home_url()) . '">' . esc_html__('Home', 'animation-addons-for-elementor') . '</a>';
468+
echo '<' . $tag . ' class="aae-breadcrumbs"><a href="' . esc_url(home_url()) . '">' . esc_html__('Home', 'animation-addons-for-elementor') . '</a>';
470469

471470
if (is_front_page()) {
472471
echo '</div>';
@@ -546,6 +545,6 @@ function aae_addon_breadcrumbs()
546545
echo esc_html__('404 - Page not found', 'animation-addons-for-elementor');
547546
}
548547

549-
echo '</div>';
548+
echo '</' . $tag . '>';
550549
}
551550
}

inc/hook.php

Lines changed: 88 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?php
22

3-
if ( ! defined( 'ABSPATH' ) ) {
4-
exit;
3+
if (! defined('ABSPATH')) {
4+
exit;
55
} // Exit if accessed directly
66

77
use Elementor\Plugin;
88

9-
if(function_exists('wcf_set_postview')){
10-
add_action( 'wp_head', 'wcf_set_postview' );
9+
if (function_exists('wcf_set_postview')) {
10+
add_action('wp_head', 'wcf_set_postview');
1111
}
1212

13-
function aaeaddonlight_hk_allow_svg_uploads($mimes) {
13+
function aaeaddonlight_hk_allow_svg_uploads($mimes)
14+
{
1415
// Allow SVG files
1516
$mimes['svg'] = 'image/svg+xml';
1617
$mimes['svgz'] = 'image/svg+xml'; // Compressed SVG
@@ -19,62 +20,65 @@ function aaeaddonlight_hk_allow_svg_uploads($mimes) {
1920

2021
add_filter('upload_mimes', 'aaeaddonlight_hk_allow_svg_uploads');
2122

22-
function aae_handle_aae_post_shares_count() {
23-
if(!isset($_POST['nonce'])){
24-
exit( 'No naughty business please . Provide Security Code' );
23+
function aae_handle_aae_post_shares_count()
24+
{
25+
if (!isset($_POST['nonce'])) {
26+
exit('No naughty business please . Provide Security Code');
2527
}
26-
$nonce = sanitize_text_field( wp_unslash($_POST['nonce']));
27-
if ( ! wp_verify_nonce( $nonce , 'wcf-addons-frontend' ) ) {
28-
exit( 'No naughty business please' );
29-
}
30-
31-
if ( isset( $_POST['post_id'] ) && isset($_POST['social'])) {
32-
$post_id = intval( sanitize_text_field( wp_unslash($_POST['post_id'])) );
33-
$social = sanitize_text_field( wp_unslash($_POST['social']) );
34-
28+
$nonce = sanitize_text_field(wp_unslash($_POST['nonce']));
29+
if (! wp_verify_nonce($nonce, 'wcf-addons-frontend')) {
30+
exit('No naughty business please');
31+
}
32+
33+
if (isset($_POST['post_id']) && isset($_POST['social'])) {
34+
$post_id = intval(sanitize_text_field(wp_unslash($_POST['post_id'])));
35+
$social = sanitize_text_field(wp_unslash($_POST['social']));
36+
3537
// Retrieve current share count, increment it, or set it if it doesn't exist
36-
$current_shares = get_post_meta( $post_id, 'aae_post_shares', true );
37-
if ( ! is_array( $current_shares ) ) {
38+
$current_shares = get_post_meta($post_id, 'aae_post_shares', true);
39+
if (! is_array($current_shares)) {
3840
$current_shares = [];
3941
}
40-
if ( isset( $current_shares[ $social ] ) ) {
41-
$current_shares[ $social ]++;
42+
if (isset($current_shares[$social])) {
43+
$current_shares[$social]++;
4244
} else {
43-
$current_shares[ $social ] = 1;
45+
$current_shares[$social] = 1;
46+
}
47+
48+
$shares_count = array_sum(array_values($current_shares));
49+
50+
foreach ($current_shares as $k => $single) {
51+
update_post_meta($post_id, 'aae_post_shares_' . $k, $single);
4452
}
45-
46-
$shares_count = array_sum( array_values($current_shares) );
47-
48-
foreach($current_shares as $k=> $single){
49-
update_post_meta( $post_id, 'aae_post_shares_'.$k, $single );
50-
}
51-
52-
update_post_meta( $post_id, 'aae_post_shares_count', $shares_count );
53-
update_post_meta( $post_id, 'aae_post_shares', $current_shares );
53+
54+
update_post_meta($post_id, 'aae_post_shares_count', $shares_count);
55+
update_post_meta($post_id, 'aae_post_shares', $current_shares);
5456

5557
// Return updated share count as a response
56-
wp_send_json_success( array(
58+
wp_send_json_success(array(
5759
'share_count' => $shares_count,
5860
'post_shares' => $current_shares
59-
) );
61+
));
6062
} else {
61-
wp_send_json_error( 'Invalid post ID' );
63+
wp_send_json_error('Invalid post ID');
6264
}
6365
}
64-
add_action( 'wp_ajax_aae_post_shares', 'aae_handle_aae_post_shares_count' ); // For logged-in users
65-
add_action( 'wp_ajax_nopriv_aae_post_shares', 'aae_handle_aae_post_shares_count' ); // For non-logged-in users
66+
add_action('wp_ajax_aae_post_shares', 'aae_handle_aae_post_shares_count'); // For logged-in users
67+
add_action('wp_ajax_nopriv_aae_post_shares', 'aae_handle_aae_post_shares_count'); // For non-logged-in users
6668

67-
function aaeaddon_disable_comments_for_custom_post_type() {
68-
remove_post_type_support( 'wcf-addons-template', 'comments' );
69+
function aaeaddon_disable_comments_for_custom_post_type()
70+
{
71+
remove_post_type_support('wcf-addons-template', 'comments');
6972
}
70-
add_action( 'init', 'aaeaddon_disable_comments_for_custom_post_type' , 100);
73+
add_action('init', 'aaeaddon_disable_comments_for_custom_post_type', 100);
7174

72-
function aaeaddon_custom_hide_admin_notices_for_specific_page() {
73-
$screen = get_current_screen();
75+
function aaeaddon_custom_hide_admin_notices_for_specific_page()
76+
{
77+
$screen = get_current_screen();
7478
// ist of admin pages where you want to disable notices
7579
$pages_to_hide_notices = array(
76-
'wcf-custom-fonts',
77-
'wcf-custom-icons',
80+
'wcf-custom-fonts',
81+
'wcf-custom-icons',
7882
'animation-addon_page_wcf-cpt-builder',
7983
'edit-wcf-addons-template',
8084
'animation-addon_page_wcf_addons_settings',
@@ -90,3 +94,44 @@ function aaeaddon_custom_hide_admin_notices_for_specific_page() {
9094
}
9195
add_action('admin_head', 'aaeaddon_custom_hide_admin_notices_for_specific_page');
9296

97+
98+
99+
// post reaction ajax handeler
100+
101+
if (!function_exists('aaeaddon_post_lite_reaction_ajax')) {
102+
function aaeaddon_post_lite_reaction_ajax()
103+
{
104+
if (! wp_verify_nonce($_REQUEST['nonce'], 'wcf-addons-frontend')) {
105+
exit('No naughty business please');
106+
}
107+
108+
$post_id = absint($_POST['post_id']);
109+
$reaction = sanitize_text_field($_POST['reaction']);
110+
111+
if (! $post_id || ! $reaction) {
112+
wp_send_json_error('Invalid data');
113+
}
114+
115+
$reactions = get_post_meta($post_id, 'aaeaddon_post_reactions', true);
116+
if (! is_array($reactions)) {
117+
$reactions = [];
118+
}
119+
120+
if (isset($reactions[$reaction])) {
121+
$reactions[$reaction]++;
122+
} else {
123+
$reactions[$reaction] = 1;
124+
}
125+
126+
$reactions_count = array_sum(array_values($reactions));
127+
128+
foreach ($reactions as $k => $single) {
129+
update_post_meta($post_id, 'aaeaddon_post_reactions_' . $k, $single);
130+
}
131+
update_post_meta($post_id, 'aaeaddon_post_reactions', $reactions);
132+
update_post_meta($post_id, 'aaeaddon_post_total_reactions', $reactions_count);
133+
wp_send_json_success($reactions);
134+
}
135+
add_action('wp_ajax_nopriv_aaeaddon_post_reaction', 'aaeaddon_post_lite_reaction_ajax');
136+
add_action('wp_ajax_aaeaddon_post_reaction', 'aaeaddon_post_lite_reaction_ajax');
137+
}

widgets/breadcrumbs.php

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ protected function register_controls()
5656
]
5757
);
5858

59+
$this->add_control(
60+
'yoast_seo',
61+
[
62+
'label' => esc_html__('Enable Yoast', 'animation-addons-for-elementor'),
63+
'type' => Controls_Manager::SWITCHER,
64+
'label_on' => esc_html__('Yes', 'animation-addons-for-elementor'),
65+
'label_off' => esc_html__('No', 'animation-addons-for-elementor'),
66+
'return_value' => 'yes',
67+
'default' => 'yes',
68+
]
69+
);
70+
5971
if (! class_exists('\WPSEO_Breadcrumbs')) {
6072

6173
$this->add_control(
@@ -68,8 +80,6 @@ protected function register_controls()
6880
);
6981

7082
$this->end_controls_section();
71-
72-
return;
7383
}
7484

7585
$this->add_responsive_control(
@@ -125,6 +135,37 @@ protected function register_controls()
125135
]
126136
);
127137

138+
$this->add_control(
139+
'br_separator',
140+
[
141+
'label' => esc_html__('Seprator Text', 'animation-addons-for-elementor'),
142+
'type' => Controls_Manager::TEXT,
143+
'default' => ' &raquo; ',
144+
'placeholder' => esc_html__('Seprator text', 'animation-addons-for-elementor'),
145+
'condition' => [
146+
'yoast_seo!' => 'yes'
147+
]
148+
]
149+
);
150+
151+
$this->add_control(
152+
'sep_description',
153+
[
154+
'raw' => sprintf(
155+
/* translators: 1: Link opening tag, 2: Link closing tag. */
156+
esc_html__('You can use HTML entities as separators. Check out %1$sHTML Symbols%2$s for examples.', 'animation-addons-for-elementor'),
157+
sprintf('<a href="%s" target="_blank">', 'https://www.toptal.com/designers/htmlarrows/symbols/'),
158+
'</a>'
159+
),
160+
'type' => Controls_Manager::RAW_HTML,
161+
'content_classes' => 'elementor-descriptor',
162+
'condition' => [
163+
'yoast_seo!' => 'yes'
164+
]
165+
]
166+
);
167+
168+
128169
$this->end_controls_section();
129170

130171
$this->start_controls_section(
@@ -207,17 +248,20 @@ private function get_html_tag()
207248
$html_tag = $this->get_settings('html_tag');
208249

209250
if (empty($html_tag)) {
210-
$html_tag = 'p';
251+
$html_tag = 'div';
211252
}
212253

213254
return Utils::validate_html_tag($html_tag);
214255
}
215256

216257
protected function render()
217258
{
218-
if (class_exists('\WPSEO_Breadcrumbs')) {
219-
$html_tag = $this->get_html_tag();
259+
$settings = $this->get_settings_for_display();
260+
$html_tag = $this->get_html_tag();
261+
if (class_exists('\WPSEO_Breadcrumbs') && $settings['yoast_seo'] == 'yes') {
220262
WPSEO_Breadcrumbs::breadcrumb('<' . $html_tag . ' id="breadcrumbs">', '</' . $html_tag . '>');
263+
} else {
264+
aae_addon_breadcrumbs($html_tag, $settings['br_separator']);
221265
}
222266
}
223267
}

0 commit comments

Comments
 (0)