content ?? ''; $description = $shortcode->description ?? ''; } else { // If somthing is posted, try to save input data. $input_keys = array( 'tag', 'old_tag', 'content', 'description' ); try { // Loop all input keys and sanitize and verify them. foreach ( $input_keys as $key ) { $html_allowed = false; if ( 'content' === $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( $tag, $old_tag, 'tag', 'ZumiAdShortcode' ); $validate->exe(); // Show Error. if ( $validate->doesErrorOccur() ) { throw new Exception( $validate->getMessage() ); } $shortcodes = ZumiAdShortcode::all(); if ( count( $shortcodes ) >= $limit ) { throw new Exception( $lan->getModified( 'exceed_max', array( '[number]' => $limit ) ) ); } // Save the record to the DB. $shortcode = new ZumiAdShortcode(); // Set values. $shortcode->tag = $tag; $shortcode->content = $content; $shortcode->description = $description; $shortcode->save(); // If user change tag, delete old one. if ( $tag !== $old_tag ) { ZumiAdShortcode::delete( $old_tag ); } // Override old id with ad id for showing the update has been completed to user. $old_tag = $tag; // 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' ); ?>