PluginProbe ʕ •ᴥ•ʔ
CookieYes – Cookie Banner for Cookie Consent (Easy to setup GDPR/CCPA Compliant Cookie Notice) / 3.5.0
CookieYes – Cookie Banner for Cookie Consent (Easy to setup GDPR/CCPA Compliant Cookie Notice) v3.5.0
3.5.1 3.5.0 3.4.2 trunk 1.0.1 1.0.3 1.2 1.2.1 1.2.2 1.3 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.2.0 3.2.1 3.2.10 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.3.9.1 3.4.0 3.4.1
cookie-law-info / legacy / admin / modules / cli-policy-generator / classes / class-policy-generator-ajax.php
cookie-law-info / legacy / admin / modules / cli-policy-generator / classes Last commit date
class-policy-generator-ajax.php 1 month ago class-preview-page.php 1 month ago
class-policy-generator-ajax.php
139 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5 class Cookie_Law_Info_Policy_Generator_Ajax extends Cookie_Law_Info_Cli_Policy_Generator {
6
7
8 public function __construct() {
9 add_action( 'wp_ajax_cli_policy_generator', array( $this, 'ajax_policy_generator' ) );
10 }
11
12 /*
13 *
14 * Main Ajax hook for processing requests
15 */
16 public function ajax_policy_generator() {
17 check_ajax_referer( 'cli_policy_generator', 'security' );
18 if ( ! current_user_can( 'manage_options' ) ) {
19 wp_die( esc_html__( 'You do not have sufficient permission to perform this operation', 'cookie-law-info' ) );
20 }
21 $out = array(
22 'response' => false,
23 'message' => __( 'Unable to handle your request.', 'cookie-law-info' ),
24 );
25 $non_json_response = array();
26 if ( isset( $_POST['cli_policy_generator_action'] ) ) {
27 $allowed_actions = array( 'autosave_content_data', 'save_contentdata', 'get_policy_pageid' );
28 $action = isset( $_POST['cli_policy_generator_action'] ) ? sanitize_text_field( wp_unslash( $_POST['cli_policy_generator_action'] ) ) : '';
29 $cli_policy_generator_action = in_array( $action, $allowed_actions ) ? $action : '';
30 if ( in_array( $cli_policy_generator_action, $allowed_actions ) && method_exists( $this, $cli_policy_generator_action ) ) {
31 $out = $this->{$cli_policy_generator_action}();
32 }
33 }
34 if ( in_array( $cli_policy_generator_action, $non_json_response ) ) {
35 echo esc_html( is_array( $out ) ? $out['message'] : $out );
36 } else {
37 echo wp_json_encode( $out );
38 }
39 exit();
40 }
41
42 /*
43 * @since 1.7.4
44 * Get current policy page ID (Ajax-main)
45 * This is used to update the hidden field for policy page id. (In some case user press back button)
46 */
47 public function get_policy_pageid() {
48 $page_id = Cookie_Law_Info_Cli_Policy_Generator::get_cookie_policy_pageid();
49 $policy_page_status = get_post_status( $page_id );
50 if ( $policy_page_status && $policy_page_status != 'trash' ) {
51
52 } else {
53 $page_id = 0;
54 }
55 return array(
56 'response' => true,
57 'page_id' => $page_id,
58 );
59 }
60
61 /*
62 * @since 1.7.4
63 * Save current data (Ajax-main)
64 */
65 public function save_contentdata() {
66 check_ajax_referer( 'cli_policy_generator', 'security' );
67 $out = array(
68 'response' => true,
69 'er' => '',
70 );
71 $content_data = array();
72 $count = isset( $_POST['content_data'] ) ? count( $_POST['content_data'] ) : 0;
73 for ( $i = 0; $i < $count; $i++ ) {
74 $data = array(
75 'ord' => isset( $_POST['content_data'][ $i ]['ord'] ) ? absint( $_POST['content_data'][ $i ]['ord'] ) : 0,
76 'hd' => isset( $_POST['content_data'][ $i ]['hd'] ) ? sanitize_text_field( wp_unslash( $_POST['content_data'][ $i ]['hd'] ) ) : '',
77 'content' => isset( $_POST['content_data'][ $i ]['content'] ) ? wp_kses_post( wp_unslash( $_POST['content_data'][ $i ]['content'] ) ) : '',
78 );
79 $content_data[] = $data;
80 }
81 $page_id = isset( $_POST['page_id'] ) ? absint( $_POST['page_id'] ) : 0;
82 $enable_webtofee_powered_by = isset( $_POST['enable_webtofee_powered_by'] ) ? absint( $_POST['enable_webtofee_powered_by'] ) : 0;
83 $id = wp_insert_post(
84 array(
85 'ID' => $page_id, // if ID is zero it will create new page otherwise update
86 'post_title' => 'Cookie Policy',
87 'post_type' => 'page',
88 'post_content' => Cookie_Law_Info_Cli_Policy_Generator::generate_page_content( $enable_webtofee_powered_by, $content_data, 0 ),
89 'post_status' => 'draft', // default is draft
90 )
91 );
92 if ( is_wp_error( $id ) ) {
93 $out = array(
94 'response' => false,
95 'er' => __( 'Error', 'cookie-law-info' ),
96 );
97 } else {
98 Cookie_Law_Info_Cli_Policy_Generator::set_cookie_policy_pageid( $id );
99 $out['url'] = get_edit_post_link( $id );
100 }
101 return $out;
102 }
103
104 /*
105 * @since 1.7.4
106 * Autosave Current content to session (Ajax-main)
107 */
108 public function autosave_content_data() {
109 check_ajax_referer( 'cli_policy_generator', 'security' );
110 $out = array(
111 'response' => true,
112 'er' => '',
113 );
114 $content_data = array();
115 $count = isset( $_POST['content_data'] ) ? count( $_POST['content_data'] ) : 0;
116 for ( $i = 0; $i < $count; $i++ ) {
117 $data = array(
118 'ord' => isset( $_POST['content_data'][ $i ]['ord'] ) ? absint( $_POST['content_data'][ $i ]['ord'] ) : 0,
119 'hd' => isset( $_POST['content_data'][ $i ]['hd'] ) ? sanitize_text_field( wp_unslash( $_POST['content_data'][ $i ]['hd'] ) ) : '',
120 'content' => isset( $_POST['content_data'][ $i ]['content'] ) ? wp_kses_post( wp_unslash( $_POST['content_data'][ $i ]['content'] ) ) : '',
121 );
122 $content_data[] = $data;
123 }
124 $page_id = isset( $_POST['page_id'] ) ? intval( $_POST['page_id'] ) : 0;
125 $enable_webtofee_powered_by = isset( $_POST['enable_webtofee_powered_by'] ) ? intval( $_POST['enable_webtofee_powered_by'] ) : 0;
126 if ( is_array( $content_data ) ) {
127 $content_html = Cookie_Law_Info_Cli_Policy_Generator::generate_page_content( $enable_webtofee_powered_by, $content_data );
128 update_option( 'cli_pg_content_data', $content_html );
129 } else {
130 $out = array(
131 'response' => false,
132 'er' => __( 'Error', 'cookie-law-info' ),
133 );
134 }
135 return $out;
136 }
137 }
138 new Cookie_Law_Info_Policy_Generator_Ajax();
139