/** * @ajax */ public function ajax_admin_save_options() { if (!tf_current_user_can(array('manage_options'), false)) { die('Access denied'); } // check security with nonce. check_ajax_referer('tfuse_framework_save_options', '_ajax_nonce'); $tfuse_framework_options = array(); $post_options = $this->request->isset_POST('options') ? $this->request->POST('options') : ''; $unserialized = json_decode($post_options); $values = get_object_vars($unserialized); $admin_options = $this->get->options('admin'); $admin_options = tf_only_options($admin_options); $do_refresh = FALSE; foreach ($admin_options as $option_id => $option) { if (isset($option['on_update']) && $option['on_update'] == 'reload_page') { if (!isset($values[$option_id]) && $this->get->option('admin', $option_id) == 'true' || isset($values[$option_id]) && $this->get->option('admin', $option_id) != $values[$option_id]) { $do_refresh = TRUE; } } if ($this->optisave->has_method("admin_{$option['type']}")) { $this->optisave->{"admin_{$option['type']}"}($option, $values, $tfuse_framework_options); } else { $this->optisave->admin_text($option, $values, $tfuse_framework_options); } } update_option(TF_THEME_PREFIX . '_tfuse_framework_options', $tfuse_framework_options); do_action('tfuse_admin_save_options', $values, $tfuse_framework_options); if ($do_refresh) { $this->ajax->out_json['reload_page'] = TRUE; } $this->ajax->ajax_finish(); }
/** * @ajax */ function tfuse_ajax_add_shortcode_page() { if (!tf_current_user_can(array('edit_posts'), false)) { die(__('Access denied', 'tfuse')); } $data = array(); $this->load_shortcode_files(TRUE); $data['shortcodes'] = $this->get_shortcodes(); $shc_ids = array(); foreach ($data['shortcodes'] as $type => $atts) { $shc_ids[$type] = $atts['IDs']; } $data['categories'] = $this->get_categories(); $flipped = array_flip($data['categories']); $categories = array('all' => __('Show all', 'tfuse')); foreach ($flipped as $key => $val) { $categories[$key] = $val; } $data['category_option'] = array('name' => __('Shortcode Categories', 'tfuse'), 'desc' => __('Shortcode Categories', 'tfuse'), 'id' => 'tf_shortcode_categories', 'value' => 'all', 'options' => $categories, 'type' => 'select'); $data['filter_option'] = array('name' => __('Shortcode Text Fitler', 'tfuse'), 'desc' => __('Shortcode Text Filter', 'tfuse'), 'id' => 'tf_shortcode_text_filter', 'value' => '', 'type' => 'text'); $data['ext_name'] = $this->_the_class_name; $out = $this->load->ext_view($this->_the_class_name, 'all_shortcodes', $data, TRUE); tfjecho(array('status' => 1, 'content' => utf8_encode($out), 'shc_ids' => $shc_ids)); }
/** * Create post_id for opening gallery popup * and attach to it given images */ function ajax_get_temp_gallery_post_id() { if (!tf_current_user_can(array('manage_options', 'edit_posts', 'tf_admin_boutique'), false)) { return false; } /** @var TF_TFUSE $TFUSE */ global $TFUSE; $value = json_decode($TFUSE->request->POST('value')); if ($value === null) { $value = array(); } $response = array('status' => 0); $this->delete_all_posts(); do { $attachments = array(); foreach ($value as $file) { if (!is_object($file)) { continue; } $attachments[] = array('url' => $file->url, 'title' => @$file->title, 'alt' => @$file->alt, 'caption' => @$file->caption, 'desc' => @$file->desc); } $post_id = $this->create_post(); if (!$post_id) { break; } $this->create_attachments($post_id, $attachments); $response['post_id'] = $post_id; $response['status'] = 1; } while (false); echo json_encode($response); die; }
/** * Ajax handler is triggered when * something is added to the nav menu * @ajax */ public function ajax_add_menu_item() { if (!tf_current_user_can(array('manage_options', 'edit_theme_options'), false)) { die('-1'); } check_ajax_referer('add-menu_item', 'menu-settings-column-nonce'); require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; // For performance reasons, we omit some object properties from the checklist. // The following is a hacky way to restore them when adding non-custom items. $menu_items_data = array(); if ($this->request->POST('menu-item')) { foreach ((array) $this->request->POST('menu-item') as $menu_item_data) { if (!empty($menu_item_data['menu-item-type']) && 'custom' != $menu_item_data['menu-item-type'] && !empty($menu_item_data['menu-item-object-id'])) { switch ($menu_item_data['menu-item-type']) { case 'post_type': $_object = get_post($menu_item_data['menu-item-object-id']); break; case 'taxonomy': $_object = get_term($menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object']); break; } $_menu_items = array_map('wp_setup_nav_menu_item', array($_object)); $_menu_item = array_shift($_menu_items); // Restore the missing menu item properties $menu_item_data['menu-item-description'] = $_menu_item->description; } $menu_items_data[] = $menu_item_data; } } $item_ids = wp_save_nav_menu_items(0, $menu_items_data); if (is_wp_error($item_ids)) { die('-1'); } foreach ((array) $item_ids as $menu_item_id) { $menu_obj = get_post($menu_item_id); if (!empty($menu_obj->ID)) { $menu_obj = wp_setup_nav_menu_item($menu_obj); $menu_obj->label = $menu_obj->title; // don't show "(pending)" in ajax-added items $menu_items[] = $menu_obj; } } if (!empty($menu_items)) { $args = array('after' => '', 'before' => '', 'link_after' => '', 'link_before' => '', 'walker' => new TF_ADMIN_MENU_WALKER()); echo walk_nav_menu_tree($menu_items, 0, (object) $args); } die; }
/** * @ajax */ function form_preview() { if (!tf_current_user_can(array('publish_pages'), false)) { die('Access denied'); } require_once TFUSE_CONFIG_SHORTCODES . '/shortcodes/contactform.php'; $_formArray = $this->prepare_ajax_data($this->request->POST('tf_form_')); $_COOKIE['form_array'] = serialize($_formArray); // $this->request->COOKIE('form_array', serialize($_formArray)); echo do_shortcode('[tfuse_contactform]'); die; }
/** * @ajax */ function form_preview() { if (!tf_current_user_can(array('publish_pages'), false)) { die(__('Access denied', 'tfuse')); } require_once TFUSE_CONFIG_SHORTCODES . '/shortcodes/reservationform.php'; $form_data = $this->request->POST('tf_form_'); $_form = array(); parse_str(urldecode($form_data), $_form); $_formArray = $this->prepare_ajax_data($_form); $form_data = $this->request->POST('tf_form_'); $_form = array(); parse_str(urldecode($form_data), $_form); $_formArray = $this->prepare_ajax_data($_form); $_COOKIE['res_form_array'] = serialize($_formArray); // $this->request->COOKIE('res_form_array', serialize($_formArray)); echo do_shortcode('[tfuse_reservationform]'); die; }