code ?? ''; $description = $ad->description ?? ''; } else { // If somthing is posted, try to save input data. $input_keys = array( 'ad_id', 'old_ad_id', 'code', 'description' ); try { // Loop all input keys and sanitize and verify them. foreach ( $input_keys as $key ) { $html_allowed = false; if ( 'code' === $key ) { $html_allowed = true; } ${$key} = Sanitize::get( $key, 'post', $html_allowed ); // If input value is false, throw an error. if ( false === ${$key} ) { throw new Exception( ${$key} . 'has invalid characters' ); } } // Check $ad_id and $old_ad_id, if $ad_id is already exists in DB table. $validate = new ValidateID( $ad_id, $old_ad_id, 'ad_id', 'ZumiAd' ); $validate->exe(); // Show Error. if ( $validate->doesErrorOccur() ) { throw new Exception( $validate->getMessage() ); } $ads = ZumiAd::all(); if ( count( $ads ) >= $limit ) { throw new Exception( $lan->getModified( 'exceed_max', array( '[number]' => $limit ) ) ); } // Save the record to the DB. $ad = new ZumiAd(); $ad->ad_id = $ad_id; $ad->code = $code; $ad->description = $description; $ad->save(); // If user change ad id, delete old one. if ( $ad_id !== $old_ad_id ) { ZumiAd::delete( $old_ad_id ); } // Override old id with ad id for showing the update has been completed to user. $old_ad_id = $ad_id; // Show a message. echo '' . esc_html( $lan->saved ) . ''; } catch ( Exception $e ) { // Show an error message. echo '' . esc_html( $e->getMessage() ) . ''; } } // Create nounce. $nonce = wp_create_nonce( 'zumi-nonce' ); ?>