prepare_items(); $addlink = add_query_arg(array('aformid' => 'new', 'aformaction' => 'new'), ADMINPURL); echo '

'.esc_html( __( 'Ajax WP Query Search Filter', 'AjWPQSF' ) ).''.esc_html( __( 'Add New Search Form', 'AjWPQSF' ) ).'

'; echo '
'; $awqsfmain->display(); echo '
'; } if(isset($_GET['aformid']) && isset($_GET['faormaction']) && $_GET['aformaction']=='new' && $_GET['aformaction']=='new'){ require_once AWQSFPLUG . '/admin/add-new.php'; } if(isset($_GET['aformid']) && isset($_GET['aformaction'])){ $post_id = $_GET['aformid']; require_once AWQSFPLUG . '/admin/add-new.php'; } } function admin_ajwpqsf_js(){ wp_enqueue_script('thickbox',null,array('jquery')); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_script('js', plugins_url('admin/scripts/admin_awqsfjs.js', __FILE__), array('jquery'), '1.0', true); wp_localize_script( 'ajax-request', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); } function admin_awpqsf_css(){ wp_enqueue_style('awqsfcss', plugins_url('admin/scripts/admin_awpqsf.css', __FILE__), '1.0', true); wp_enqueue_style('thickbox.css', '/'.WPINC.'/js/thickbox/thickbox.css', null, '1.0'); } function Ajaxwpqsf_setting() { register_post_type( self::post_type, array( 'labels' => array( 'name' => __( 'Ajax WPQSF', 'AjWPQSF' ), 'singular_name' => __( 'Map AWPSF', 'AjWPQSF' ) ), 'exclude_from_search'=>true, 'publicly_queryable'=>false, 'rewrite' => false, 'query_var' => false ) ); load_plugin_textdomain( 'AjWPQSF', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' ); add_shortcode('AjaxWPQSF', array($this, 'Aj_wpqsf_shortcode')); } function ajwpqsf_save_from() { if(isset($_POST['ajxwpqsfsub'])){ if (! wp_verify_nonce($_POST['nonce'], 'ajax-wpqsf-edit') ) { $this->handle_error()->add('nonce', __("No naughty business here, dude", 'AjWPQSF')); return; } $postid =sanitize_text_field($_POST['aformid']); $themeoption = $cptarray = $taxoarray = $cmfarray =$relarray =''; if(!empty($_POST['Ajxqf']['cpt'])){ foreach($_POST['Ajxqf']['cpt'] as $cv){ $cptarray[] = sanitize_text_field($cv); } } if(isset($_POST['Ajxqf']['taxo'])){ foreach($_POST['Ajxqf']['taxo'] as $tv){ $taxoarray[]=array( 'taxname' => sanitize_text_field($tv['taxname']), 'taxlabel'=> sanitize_text_field($tv['taxlabel']), 'taxall' => sanitize_text_field($tv['taxall']), 'hide' => sanitize_text_field($tv['hide']), 'exc' => sanitize_text_field($tv['exc']), 'type' => sanitize_text_field($tv['type']) ); } } if(isset($_POST['Ajxqf']['cmf'])){ foreach($_POST['Ajxqf']['cmf'] as $cv){ $cmfarray[] = array( 'metakey' => sanitize_text_field($cv['metakey']), 'label' => sanitize_text_field($cv['label']), 'all' => sanitize_text_field($cv['all']), 'compare' => wp_filter_nohtml_kses( stripslashes($cv['compare'])), 'type' => sanitize_text_field($cv['type']), 'opt' => sanitize_text_field($cv['opt']) ); } } foreach($_POST['Ajxqf']['rel'] as $rv){ $relarray[] = array( 'tax'=> isset($rv['tax']) ? sanitize_text_field($rv['tax']) : '', 'cmf'=> isset($rv['cmf']) ? sanitize_text_field($rv['cmf']) : '', 'strchk'=> isset($rv['strchk']) ? sanitize_text_field($rv['strchk']) : '', 'strlabel'=> $rv['strlabel'], 'smetekey'=> $rv['smetekey'], 'otype'=> isset($rv['otype']) ? sanitize_text_field($rv['otype']) : '', 'sorder'=> isset($rv['sorder']) ? sanitize_text_field($rv['sorder']) : '', 'button'=> $rv['button'], 'resultc'=> $rv['resultc'], 'div'=> $rv['div'] ); } if($_POST['themeopt']){ $themeoption = $_POST['themeopt']; } if($postid == 'new'){ $post_information = array( 'post_title' => sanitize_text_field($_POST['ftitle']) , 'post_type' => self::post_type, 'post_status' => 'publish' ); $newform_id = wp_insert_post($post_information); if(empty($newform_id)){ $this->handle_error()->add('insert', __("Error! Try to create again.", 'AjWPQSF')); return; } if(!empty($cptarray) ){ update_post_meta($newform_id, 'ajaxwpqsf-cpt', $cptarray);} if(!empty($taxoarray)){ update_post_meta($newform_id, 'ajaxwpqsf-taxo', $taxoarray);} if(!empty($cmfarray)){ update_post_meta($newform_id, 'ajaxwpqsf-cmf', $cmfarray);} if(!empty($relarray)){ update_post_meta($newform_id, 'ajaxwpqsf-relbool', $relarray);} if(!empty($themeoption)){ update_post_meta($newform_id, 'ajaxwpqsf-theme', $themeoption);} $returnlink = add_query_arg(array('aformid' => $newform_id, 'aformaction' => 'edit','status'=>'success'), ADMINPURL); wp_redirect( $returnlink ); exit; }//end add new if($postid != 'new' && absint($postid) ){ $updateform = array(); $updateform['ID'] = $postid ; $updateform['post_title'] = sanitize_text_field($_POST['ftitle']); $update = wp_update_post( $updateform ); if(empty($update)){ $this->handle_error()->add('update', __("Error! Something wrong when updating your setting.", 'AjWPQSF')); return; } $oldcpt = get_post_meta($post_id, 'ajaxwpqsf-cpt', true); $oldtaxo = get_post_meta($post_id, 'ajaxwpqsf-taxo', true); $oldcmf = get_post_meta($post_id, 'ajaxwpqsf-cmf', true); $oldrel = get_post_meta($post_id, 'ajaxwpqsf-relbool', true); $oldthemeopt = get_post_meta($post_id, 'ajaxwpqsf-theme', true); $newcpt = !empty($cptarray) ? $cptarray : ''; $newtaxo = !empty($taxoarray) ? $taxoarray : ''; $newcmf = !empty($cmfarray) ? $cmfarray : ''; $newrel = !empty($relarray) ? $relarray : ''; $newthemeopt = !empty($themeoption) ? $themeoption : ''; if (empty($newcpt)) { delete_post_meta($postid, 'ajaxwpqsf-cpt', $oldcpt); } elseif($oldcpt != $newcpt) { update_post_meta($postid, 'ajaxwpqsf-cpt', $newcpt); } if (empty($newtaxo)) { delete_post_meta($postid, 'ajaxwpqsf-taxo', $oldtaxo); } elseif($newtaxo != $oldtaxo) { update_post_meta($postid, 'ajaxwpqsf-taxo', $newtaxo); } if (empty($newcmf)) { delete_post_meta($postid, 'ajaxwpqsf-cmf', $oldcmf); } elseif ($newcmf != $oldcmf) { update_post_meta($postid, 'ajaxwpqsf-cmf', $newcmf); } if (empty($newrel)) { delete_post_meta($postid, 'ajaxwpqsf-relbool', $oldrel); } elseif ($newrel != $oldrel) { update_post_meta($postid, 'ajaxwpqsf-relbool', $newrel); } if($newthemeopt != $oldthemeopt) { update_post_meta($postid, 'ajaxwpqsf-theme', $newthemeopt); } $returnlink = add_query_arg(array('aformid' => $postid, 'aformaction' => 'edit','status'=>'updated'), ADMINPURL); wp_redirect( $returnlink ); exit; }//end update }//end submit } function Aj_wpqsf_shortcode($atts) { extract(shortcode_atts(array('id' => false, 'formtitle' =>1), $atts)); if($id) { ob_start(); $output = include AWQSFPLUG . '/html/searchform.php'; $output = ob_get_clean(); return $output; } else{ echo 'no form added.'; } } } } add_filter('widget_text', 'do_shortcode'); global $ajaxwpqsf; $ajaxwpqsf = new ajaxwpqsf(); ?>