HEX
Server: Apache
System: Linux srv-plesk28.ps.kz 5.14.0-284.18.1.el9_2.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jun 29 17:06:27 EDT 2023 x86_64
User: greencl1 (10085)
PHP: 8.1.33
Disabled: apache_setenv,dl,eval,exec,openlog,passthru,pcntl_exec,pcntl_fork,popen,posix_getpwuid,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,socket_create,socket_create_listen,socket_create_pair,syslog,system,socket_listen,stream_socket_server
Upload Files
File: /var/www/vhosts/greenclinic.kz/newsite/wp-content/plugins/ajax-directions/ajax-directions.php
<?php 

/**
 * Plugin Name: Поиск по направлениям 
 */
add_action('wp_ajax_direction', 'direction_search');
add_action('wp_ajax_nopriv_direction', 'direction_search');
 
function direction_search(){
    $serVal = $_POST['name'];
     
    $itemArray = []; 
    $k = 0;
    if(empty($serVal)){         
    }else{
        $args = array(
            'post_type' => 'prices',
            'meta_query' => array(
              'relation' => 'AND',              
                array(                
                'value'   => $serVal,
                'compare' => 'LIKE'
                )
            
            )  
        );      
        $query = new WP_Query( $args );
        $cusResult = $query->posts;
    foreach($cusResult as $cusResultItem){
        $post_id = $cusResultItem->ID;
        $prices = get_field('prices', $post_id);
        $k = 0;
        foreach($prices as $prices_item){
            $name = mb_strtolower($prices_item['name']);
            $search = mb_strtolower($serVal);  
            if(stristr($name, $search)){  
                $postTitle = get_the_title($post_id); 
                if($k === 0){
                $itemArray[$post_id][$k]= [
                    'id' =>  $post_id,
                    'pricename' =>  $postTitle,
                    'nomer' => $prices_item['nomer'],
                    'name'  => $prices_item['name'],
                    'price' => $prices_item['price'],
                    'count' => $prices_item['count'],
                    'type' => $prices_item['radio'],
                ];
                }else{
                $itemArray[$post_id][$k]= [
                    'id' =>  $post_id,
                    'pricename' =>  '',
                    'nomer' => $prices_item['nomer'],
                    'name'  => $prices_item['name'],
                    'price' => $prices_item['price'],
                    'count' => $prices_item['count'],
                    'type' => $prices_item['radio'],
                ];
            }
            $k++;   
        }
        }
    }
     echo json_encode($itemArray);
  } 
 wp_die();   
}




add_action('wp_enqueue_scripts', 'direction_script'); 
function direction_script(){
    wp_enqueue_script('direction', plugins_url('ajax-directions/directions-app.js'), array('jquery'), _S_VERSION, true); 
    wp_localize_script('direction', 'plugin', array(
        'ajaxurl' => admin_url('admin-ajax.php')
    ));
}  



add_action('wp_ajax_pdirection', 'pdirection_search');
add_action('wp_ajax_nopriv_pdirection', 'pdirection_search');


function pdirection_search(){ 
    $serVal = $_POST['name']; 
    $serPriceId = $_POST['pid'];     
    $itemArray = []; 
    $k = 0;
    if(empty($serVal)){         
    }else{
        
            $args = array(
                'post_type' => 'prices',           
                'meta_query' => array(
                  'relation' => 'AND',              
                    array(                
                    'value'   => $serVal,
                    'compare' => 'LIKE'
                    )
                
                ) 
            );  
        
            
        $query = new WP_Query( $args );
        $cusResult = $query->posts;
    foreach($cusResult as $cusResultItem){
        foreach($serPriceId as $serPriceId_item){
        $post_id = $serPriceId_item;  
        $prices = get_field('prices', $post_id);
        }
        $k = 0;
        foreach($prices as $prices_item){
            $name = mb_strtolower($prices_item['name']);
            $search = mb_strtolower($serVal);  
            if(stristr($name, $search)){  
                $postTitle = get_the_title($post_id); 
                if($k === 0){
                $itemArray[$post_id][$k]= [
                    'id' =>  $post_id,
                    'pricename' =>  $postTitle,
                    'nomer' => $prices_item['nomer'],
                    'name'  => $prices_item['name'],
                    'price' => $prices_item['price'],
                    'count' => $prices_item['count'],
                ];
                }else{
                $itemArray[$post_id][$k]= [
                    'id' =>  $post_id,
                    'pricename' =>  '',
                    'nomer' => $prices_item['nomer'],
                    'name'  => $prices_item['name'],
                    'price' => $prices_item['price'],
                    'count' => $prices_item['count'],
                ];
            }
            $k++;   
        }
        }
    }
     echo json_encode($itemArray);
  } 
 wp_die();   
}  



add_action('wp_enqueue_scripts', 'pdirection_script'); 
function pdirection_script(){
    wp_enqueue_script('pdirection', plugins_url('ajax-directions/directions-app.js',), array('jquery'), _S_VERSION, true); 
    wp_localize_script('pdirection', 'plugin', array(
        'ajaxurl' => admin_url('admin-ajax.php')
    ));
}