Plugin Directory


Ignore:
Timestamp:
01/04/2024 07:47:40 PM (16 months ago)
Author:
ashanjay
Message:

2.2.8 (2024-1-4)

FIXED: all day events not updating to correct start end unix time
FIXED: various authorisation and CSRF validations in ajax calls
FIXED: ajax calls to wp_send_json()
REMOVED: unused evo_eventpost_update_meta() from ajax

File:
1 edited

Legend:

Unmodified
Added
Removed
  • eventon-lite/trunk/includes/admin/class-admin-ajax.php

    r2978856 r3017578  
    22/**
    33 * Function ajax for backend
    4  * @version   L 2.2
     4 * @version   L2.2.8
    55 */
    66class EVO_admin_ajax{
     
    1111            'import_settings'       =>'import_settings',
    1212           
    13             'eventpost_update_meta' =>'evo_eventpost_update_meta', 
    1413            'rel_event_list'        =>'rel_event_list',
    1514            'get_latlng'                =>'get_latlng',
     
    3534    // virtual events
    3635        public function config_virtual_event(){
     36
     37            // validate if user has permission
     38            if( !current_user_can('edit_eventons') ){
     39                wp_send_json(array(
     40                    'status'=>'bad','msg'=> __('You do not have proper permission to access this','eventon')
     41                ));
     42                wp_die();
     43            }
     44
    3745            $post_data = $this->helper->sanitize_array( $_POST);
    3846
    39             $EVENT = new EVO_Event( $post_data['eid'] );
     47            $EVENT = new EVO_Event( (int) $post_data['eid'] );
    4048
    4149            ob_start();
     
    4351            include_once('views/virtual_event_settings.php');
    4452
    45             echo json_encode(array(
     53            wp_send_json(array(
    4654                'status'=>'good','content'=> ob_get_clean()
    47             ));exit;
     55            ));
     56            wp_die();
    4857        }
    4958        public function select_virtual_moderator(){
     
    5160            ob_start();
    5261
    53             $eid = sanitize_text_field( $_POST['eid'] );
     62            $eid = (int) $_POST['eid'];
    5463
    5564            $EVENT = new EVO_Event( $eid);
     
    6372                <form class='evo_vir_select_mod'>
    6473                    <input type="hidden" name="action" value='eventon_save_virtual_mod_settings'>
    65                     <input type="hidden" name="eid" value='<?php echo $eid;?>'>
     74                    <input type="hidden" name="eid" value='<?php echo esc_attr( $eid );?>'>
     75
     76                    <?php wp_nonce_field( 'evo_save_virtual_mod_settings', 'evo_noncename' );?>
    6677                   
    6778                    <p class='row'>
     
    90101                        </select>
    91102                    </p>
    92                     <p class='evo_save_changes' ><span class='evo_btn save_virtual_event_mod_config ' data-eid='<?php echo $eid;?>' style='margin-right: 10px'><?php _e('Save Changes','eventon');?></span></p>
     103                    <p class='evo_save_changes' ><span class='evo_btn save_virtual_event_mod_config ' data-eid='<?php echo esc_attr( $eid );?>' style='margin-right: 10px'><?php _e('Save Changes','eventon');?></span></p>
    93104                </form>
    94105            </div>
     
    96107            <?php
    97108
    98             echo json_encode(array(
     109            wp_send_json(array(
    99110                'status'=>'good','content'=> ob_get_clean()
    100             ));exit;
     111            ));wp_die();
    101112        }
    102113        public function get_virtual_users_select_options($role_slug, $set_user_id=''){
     
    118129        public function get_virtual_users(){
    119130
     131            // validate if user has permission
     132            if( !current_user_can('edit_eventons') ){
     133                wp_send_json(array(
     134                    'status'=>'bad','msg'=> __('You do not have proper permission to access this','eventon')
     135                ));
     136                wp_die();
     137            }
     138
    120139            $user_role = sanitize_text_field( $_POST['_user_role']);
    121140
    122             echo json_encode(array(
     141            wp_send_json(array(
    123142                'status'=>'good',
    124143                'content'=> empty($user_role) ?
    125144                    "<option value=''>--</option>" :
    126145                    $this->get_virtual_users_select_options($user_role)
    127             ));exit;
     146            )); wp_die();
    128147
    129148           
    130149        }
    131150        public function save_virtual_event_settings(){
     151            // validate if user has permission
     152            if( current_user_can('edit_eventons') ){
     153                wp_send_json(array(
     154                    'status'=>'bad','msg'=> __('You do not have proper permission to access this','eventon')
     155                ));
     156                wp_die();
     157            }
     158           
     159            // nonce validation
     160            if( isset($_POST['evo_noncename']) && !wp_verify_nonce( $_POST['evo_noncename'], 'evo_save_virtual_event_settings' ) ){
     161                wp_send_json(array(
     162                    'status'=>'bad','msg'=> __('Nonce validation failed','eventon')
     163                )); wp_die();
     164            }
     165
    132166            $post_data = $this->helper->sanitize_array( $_POST);
    133167
     
    143177            }
    144178
    145             echo json_encode(array(
     179            wp_send_json(array(
    146180                'status'=>'good','msg'=> __('Virtual Event Data Saved Successfully','eventon')
    147             ));exit;
     181            )); wp_die();
    148182        }
    149183        public function save_virtual_mod_settings(){
    150             $post_data = $this->helper->sanitize_array( $_POST);
     184            // validate if user has permission
     185            if( !current_user_can('edit_eventons') ){
     186                wp_send_json(array(
     187                    'status'=>'bad','msg'=> __('You do not have proper permission to access this','eventon')
     188                ));
     189                wp_die();
     190            }           
     191
     192            // nonce validation
     193            if( isset($_POST['evo_noncename']) && !wp_verify_nonce( $_POST['evo_noncename'], 'evo_save_virtual_mod_settings' ) ){
     194                wp_send_json(array(
     195                    'status'=>'bad','msg'=> __('Nonce validation failed','eventon')
     196                ));
     197                wp_die();
     198            }       
     199
     200            $post_data = $this->helper->sanitize_array( $_POST);   
    151201
    152202            $EVENT = new EVO_Event( $post_data['eid']);
     
    155205            $EVENT->save_meta('_mod', $post_data['_mod']);
    156206
    157             echo json_encode(array(
     207            wp_send_json(array(
    158208                'status'=>'good','msg'=> __('Moderator Data Saved Successfully','eventon')
    159             ));exit;
     209            )); wp_die();
    160210           
    161211        }
     
    257307
    258308            if( !isset($_POST['address'])){
    259                 echo json_encode(array(
    260                 'status'=>'bad','m'=> __('Address Missing','eventon'))); exit;
     309                wp_send_json(array(
     310                'status'=>'bad','m'=> __('Address Missing','eventon'))); wp_die();
    261311            }
    262312
     
    272322            $response = wp_remote_retrieve_body( $response );
    273323            if(!$response){
    274                 echo json_encode(array(
    275                 'status'=>'bad','m'=> __('Could not connect to google maps api','eventon'))); exit;
     324                wp_send_json(array(
     325                'status'=>'bad','m'=> __('Could not connect to google maps api','eventon'))); wp_die();
    276326            }
    277327
    278328            $RR = json_decode($response);
    279329
    280             echo json_encode(array(
     330            wp_send_json(array(
    281331                'status'=>'good',
    282332                'lat' => $RR->results[0]->geometry->location->lat,
    283333                'lng' => $RR->results[0]->geometry->location->lng,
    284             )); exit;
    285         }
    286 
    287     // update event post meta
    288         function evo_eventpost_update_meta(){
    289 
    290             $post_data = $this->helper->recursive_sanitize_array_fields( $_POST);
    291 
    292             if(isset($post_data['eid']) && isset($post_data['values']) ){
    293            
    294                 $post = array();
    295                 foreach($post_data['values'] as $key=>$val){
    296                     update_post_meta($post_data['eid'], $key, $val);
    297 
    298                     do_action('eventon_saved_event_metadata', $post_data['eid'], $key, $val);
    299                 }
    300                 echo json_encode(array(
    301                     'status'=>  'good',
    302                     'msg'=> __('Successfully saved event meta data!','eventon')
    303                 )); exit;
    304             }else{
    305                 echo 'Event ID not available!'; exit;
    306             }
     334            )); wp_die();
    307335        }
    308336
    309337    // export eventon settings
    310338        function export_settings(){
    311             // check if admin and loggedin
    312                 if(!is_admin() && !is_user_logged_in()) die('User not loggedin!');
     339            // validate if user has permission
     340            if( !current_user_can('edit_eventons') ){
     341                wp_send_json(array(
     342                    'status'=>'bad','msg'=> __('You do not have proper permission to access this','eventon')
     343                )); wp_die();
     344            }
    313345
    314346            // verify nonce
     
    326358            }
    327359
    328             echo json_encode($json);
    329             exit;
     360            wp_send_json($json); wp_die();
    330361        }
    331362    // import settings
    332363        function import_settings(){
    333364            $output = array('status'=>'','msg'=>'');
     365           
    334366            // verify nonce
    335                 $output['success'] =wp_create_nonce('eventon_admin_nonce');
     367                $output['success'] = wp_create_nonce('eventon_admin_nonce');
    336368                if(!wp_verify_nonce($_POST['nonce'], 'eventon_admin_nonce')) $output['msg'] = __('Security Check Failed!','eventon');
    337369
     
    352384            }
    353385           
    354             echo json_encode($output);
    355             exit;
     386            wp_send_json($output); wp_die();
    356387
    357388        }
Note: See TracChangeset for help on using the changeset viewer.