Field_Helper; $file_path = $this->custom_template_dir() . "/{$file_name}.php"; if ( file_exists( $file_path ) ) { include $file_path; } } /** * Method get_directory_custom_fields * * @param $directory_id * @param $only_files * * @return array */ public function get_directory_custom_fields( $directory_id = 0, $only_files = [] ) { $directory_id = ! empty( $directory_id ) ? absint( $directory_id ) : 0; $listing_fields = adqs_get_listing_fields( $directory_id ); if ( empty( $listing_fields ) ) { return []; } $getAllCustomFields = []; foreach ( $listing_fields as $section ) { $sectionFields = $section['fields'] ?? []; foreach ( $sectionFields as $field ) { $input_type = $field['input_type'] ?? ''; if ( in_array( $input_type, $only_files ) ) { $fieldid = $field['fieldid'] ?? ''; $getAllCustomFields[ $fieldid ] = $input_type; } } } return $getAllCustomFields; } /** * Method get_all_custom_fields * * @param $post_id $post_id * @param $data $data * * @return void */ public function get_all_custom_fields( $post_id, $data ) { $path = $this->custom_template_dir() . '/*.php'; $Helper = $this->Field_Helper; $custom_fields = $Helper->file_name_from_folder( $path ); $input_type = ( isset( $data['input_type'] ) && ! empty( $data['input_type'] ) ) ? $data['input_type'] : false; if ( ! empty( $input_type ) && in_array( $input_type, $custom_fields ) ) { $this->get_custom_template( $post_id, $input_type, $data ); } } /** * Method save_all_custom_fields * * @param $post_id $post_id * * @return void */ public function save_all_custom_fields( $post_id = 0 ) { // all key item list $Helper = $this->Field_Helper; $path = $this->custom_template_dir() . '/*.php'; // Note: Nonce verification is handled in the parent save_metabox_data method $custom_fields = $Helper->file_name_from_folder( $path ); // Get directory type ID from post type $post = get_post( $post_id ); $directory_type_id = 0; if ( $post ) { $directory_type_id = adqs_get_directory_id_by_post_type( $post->post_type ); } $custom_fields = $this->get_directory_custom_fields( $directory_type_id, $custom_fields ); if ( ! empty( $custom_fields ) && is_array( $custom_fields ) ) { foreach ( $custom_fields as $id => $input_type ) { $meta_key = sanitize_key( "_{$input_type}_{$id}" ); $getData = isset( $_POST[ $meta_key ] ) ? $_POST[ $meta_key ] : ''; switch ( $input_type ) { case 'text': case 'number': case 'date': case 'time': case 'select': case 'radio': update_post_meta( $post_id, $meta_key, sanitize_text_field( $getData ) ); break; case 'url': update_post_meta( $post_id, $meta_key, esc_url_raw( $getData ) ); break; case 'textarea': update_post_meta( $post_id, $meta_key, sanitize_textarea_field( $getData ) ); $meta_key_list = sanitize_key( "_{$input_type}_list_{$id}" ); $getData_list = isset( $_POST[ $meta_key_list ] ) ? $_POST[ $meta_key_list ] : ''; update_post_meta( $post_id, $meta_key_list, sanitize_text_field( $getData_list ) ); break; case 'checkbox': $getData = isset( $_POST[ $meta_key ] ) ? (array) $_POST[ $meta_key ] : []; $getData = array_map( 'sanitize_text_field', $getData ); update_post_meta( $post_id, $meta_key, $getData ); break; case 'field_images': $getData = isset( $_POST[ $meta_key ] ) ? (array) $_POST[ $meta_key ] : []; $getData = array_map( 'absint', $getData ); update_post_meta( $post_id, $meta_key, $getData ); break; } } } } }