admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('ajax-nonce'), ) ); } function admin_enqueue_scripts() { // $wp_screen = new WP_Screen(); // if (!$wp_screen->is_block_editor()) { if (true) { $this->wp_enqueue_scripts(); } } function install() { if (!function_exists('is_plugin_active')) { include_once (ABSPATH . 'wp-admin/includes/plugin.php'); } if (is_plugin_active('ajax-sections-pro-by-radaplug/ajax-sections-pro-by-radaplug.php')) { deactivate_plugins(plugin_basename(__FILE__)); wp_die('Could not activate plugin because Radaplug Ajax Sections Pro is already activated, Go back to Plugins Page'); } } function radaplug_ajax_section_sc($atts = []) { $radaplug_ajax_section = '
'; $radaplug_ajax_section .= '
$post, 'post_type' => $post_type, 'numberposts' => -1, 'post_status' => 'publish', ) ); if (count($wp_query) == 1) { $wp_post = $wp_query[0]; $post = $wp_post->ID; } else { $post = 0; } } $wp_post = $this->radaplug_before_sc_post($wp_post); if (!empty($wp_post) and $wp_post->post_status == 'publish') { $radaplug_ajax_section .= ' post="' . $post . '"'; $radaplug_ajax_section .= ' type="' . $post_type . '"'; } else { return ''; } } else { return ''; } if (isset($atts['delay'])) { $delay = (int) sanitize_text_field($atts['delay']); $radaplug_ajax_section .= ' delay="' . $delay . '"'; } if (isset($atts['button']) and $atts['button'] != '') { $button = sanitize_text_field($atts['button']); $button = str_replace(' ', ' ', $button); $radaplug_ajax_section .= ' button="' . $button . '"'; } if (isset($atts['radaplug_load_via_ajax'])) { $atts['radaplug_load_via_ajax'] = sanitize_text_field($atts['radaplug_load_via_ajax']); if ($atts['radaplug_load_via_ajax'] == 1 OR $atts['radaplug_load_via_ajax'] == 'yes') { $atts['_load_via_ajax'] = 'yes'; } else { $atts['_load_via_ajax'] = 'no'; } } else { $atts['_load_via_ajax'] = 'no'; } $radaplug_ajax_section .= ' _load_via_ajax=' . $atts['_load_via_ajax']; $_page_builder = ''; if (isset($atts['_page_builder'])) { $_page_builder = sanitize_text_field($atts['_page_builder']); $radaplug_ajax_section .= ' _page_builder=' . $_page_builder; } if ($atts['_load_via_ajax'] == 'no') { $content = do_shortcode('[radaplug-insert page=' . $post . ' display=content]'); } else { $content = ' '; } if (isset($atts['spinner'])) { $atts['spinner'] = sanitize_text_field($atts['spinner']); if ($atts['spinner'] == 1 OR $atts['spinner'] == 'yes') { $radaplug_ajax_section .= ' spinner="yes"'; } else { $radaplug_ajax_section .= ' spinner="no"'; } } else { $radaplug_ajax_section .= ' spinner="yes"'; } $radaplug_ajax_section .= '>' . $content . '
'; if ($this->radaplug_sc_times) { $this->radaplug_sc_times = false; } else { return ''; } return $radaplug_ajax_section; } function ajax_radaplug_ajax_section() { if ( !isset( $_POST['nonce'] ) || !wp_verify_nonce( sanitize_text_field( wp_unslash ( $_POST['nonce'] ) ) , 'ajax-nonce' ) ) { $verify_nonce = false; } else { $verify_nonce = true; } $post = sanitize_text_field($_POST['post']); $dup = (int) sanitize_text_field($_POST['dup']); $post_type = sanitize_text_field($_POST['post_type']); $content = ''; $response = array(); if (isset($post)) { $wp_post = new \stdClass(); $post_id = (int) $post; if (is_numeric($post_id) and $post_id !== 0) { $post = $post_id; $wp_post = get_post($post); } else if (is_string($post)) { $post = esc_html($post); $wp_query = get_posts( array( 'name' => $post, 'post_type' => $post_type, 'numberposts' => -1, 'post_status' => 'publish', ) ); if (count($wp_query) == 1) { $wp_post = $wp_query[0]; $post_id = $wp_post->ID; } else { $post_id = 0; } } if ($dup == 0) { $response['post_id'] = $post_id; wp_send_json_success( wp_json_encode($response) ); die(); } $wp_post = $this->radaplug_before_ajax_post($wp_post); if (!$verify_nonce) { if (isset($post) and !empty($wp_post)) { $response['post'] = $post; $response['post_id'] = $post_id; $response['type'] = $wp_post->post_type; $response['content'] = 'Session expired, Please refresh the page and try again'; } wp_send_json_success( wp_json_encode($response) ); die(); } if (!empty($wp_post) and $wp_post->post_status == 'publish') { $content = do_shortcode('[radaplug-insert page=' . $post . ' display=content]'); } $response['post'] = $post; $response['post_id'] = $post_id; $response['dup'] = $dup; $response['type'] = $wp_post->post_type; $response['content'] = $content; } wp_send_json_success( wp_json_encode($response) ); die(); } function radaplug_before_sc_post($wp_post) { if (!empty($wp_post) and $wp_post->post_status == 'publish' and $wp_post->ID != get_the_ID()) { return $this->radaplug_before_ajax_post($wp_post); } else { return false; } } function radaplug_before_ajax_post($wp_post) { $current_allowed_posts = get_option('current_allowed_posts'); if (in_array($wp_post->post_type, $current_allowed_posts)) { return $wp_post; } else { return false; } } } if ( class_exists( 'Radaplug_Ajax_Sections_Name_Space\Radaplug_Ajax_Sections' ) ) { $Radaplug_Ajax_Sections_Instance = new Radaplug_Ajax_Sections(); require_once (plugin_dir_path(__FILE__) . 'inc/radaplug-insert-pages/radaplug-insert-pages.php'); require_once (plugin_dir_path(__FILE__) . 'inc/radaplug-gutenberg-ajax-blocks/radaplug-gutenberg-ajax-blocks.php'); } }