11<?php
22
3- if ( ! defined ( 'ABSPATH ' ) ) {
4- exit ;
3+ if (! defined ('ABSPATH ' ) ) {
4+ exit ;
55} // Exit if accessed directly
66
77use 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
2021add_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}
9195add_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+ }
0 commit comments