feature_list(); ?>
* *
'; print_r( $features ); echo ''; if ( sizeof( $features ) > 0 ) { foreach ( $features as $key => $feature ) { $label = $feature['label'] ?? ''; ?>
-
'', 'msg' => __( 'Invalid security token.', 'abp-rentalforge' ) ], 403 ); } if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( [ 'html' => '', 'msg' => __( 'Insufficient permissions.', 'abp-rentalforge' ) ], 403 ); } $post_int = fn( $key, $default = 0 ) => isset( $_POST[ $key ] ) ? absint( $_POST[ $key ] ) : $default; $post_array = fn( $key ) => ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST[ $key ] ) ) : []; $old_features = ABPRF_Function::get_option( 'abprf_feature' ); $old_features = is_array( $old_features ) ? $old_features : []; $id = ( ! empty( $old_features ) ) ? array_key_last( $old_features ) : 'fec_id_1'; $feature_ids = $post_array( 'feature_id' ); $feature_names = $post_array( 'feature_name' ); $feature_values = $post_array( 'feature_value' ); $feature_icon = $post_array( 'feature_icon' ); $property_add = $post_int( 'property_add' ); if ( ! empty( $feature_names ) ) { foreach ( $feature_names as $key => $feature_name ) { $feature_val = $feature_values[ $key ] ?? ''; if ( $feature_name !== '' && $feature_val !== '' ) { $old_id = $feature_ids[ $key ] ?? ''; if ( ! empty( $old_id ) && isset( $old_features[ $old_id ] ) ) { $id = $old_id; } else { if ( isset( $old_features[ $id ] ) ) { $number = (int) str_replace( 'fec_id_', '', $id ); $id = 'fec_id_' . ( $number + 1 ); while ( isset( $old_features[ $id ] ) ) { $number = (int) str_replace( 'fec_id_', '', $id ); $id = 'fec_id_' . ( $number + 1 ); } } } $old_features[ $id ] = [ 'label' => $feature_name, 'value' => $feature_val, 'icon' => $feature_icon[ $key ] ?? '', ]; } } } update_option( 'abprf_feature', $old_features ); self::update_feature_js(); $html = ''; if ( $property_add <= 0 ) { ob_start(); $this->feature_list(); $html = ob_get_clean(); } wp_send_json_success( [ 'html' => $html, 'feature_js' => ABPRF_Function::get_option( 'abprf_feature_js' ), 'msg' => __( 'Feature Saved Successfully..........!!', 'abp-rentalforge' ), ] ); } public function delete_feature(): void { if ( ! check_ajax_referer( 'abprf_admin_ajax_nonce', 'nonce', false ) ) { wp_send_json_error( [ 'html' => '', 'msg' => __( 'Invalid security token.', 'abp-rentalforge' ) ], 403 ); } if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( [ 'html' => '', 'msg' => __( 'Insufficient permissions.', 'abp-rentalforge' ) ], 403 ); } $fec_id = isset( $_POST['fec_id'] ) ? sanitize_text_field( wp_unslash( $_POST['fec_id'] ) ) : ''; $features = ABPRF_Function::get_option( 'abprf_feature' ); $features = is_array( $features ) ? $features : []; if ( ! empty( $fec_id ) && isset( $features[ $fec_id ] ) ) { unset( $features[ $fec_id ] ); update_option( 'abprf_feature', $features ); self::update_feature_js(); } ob_start(); $this->feature_list(); $html = ob_get_clean(); wp_send_json_success( [ 'html' => $html, 'msg' => __( 'Feature Deleted Successfully!', 'abp-rentalforge' ), ] ); } public function edit_feature(): void { if ( ! check_ajax_referer( 'abprf_admin_ajax_nonce', 'nonce', false ) ) { wp_send_json_error( [ 'html' => '', 'msg' => __( 'Invalid security token.', 'abp-rentalforge' ) ], 403 ); } if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( [ 'html' => '', 'msg' => __( 'Insufficient permissions.', 'abp-rentalforge' ) ], 403 ); } $fec_id = isset( $_POST['fec_id'] ) ? sanitize_text_field( wp_unslash( $_POST['fec_id'] ) ) : ''; $features = ABPRF_Function::get_option( 'abprf_feature' ); $features = is_array( $features ) ? $features : []; $feature = $features[ $fec_id ] ?? []; ob_start(); self::form_feature( $feature, $fec_id ); $html = ob_get_clean(); wp_send_json_success( [ 'html' => $html, 'msg' => __( 'Feature Ready to Edit...... !', 'abp-rentalforge' ), ] ); } public static function update_feature_js(): void { $features = ABPRF_Function::get_option( 'abprf_feature' ); $features = is_array( $features ) ? $features : []; $feature_js = []; if ( sizeof( $features ) > 0 ) { foreach ( $features as $key => $feature ) { $feature_js[] = [ 'id' => $key, 'icon' => ( $feature['icon'] ?? '' ), 'label' => ( $feature['label'] ?? '' ), 'value' => ( $feature['value'] ?? '' ) ]; } update_option( 'abprf_feature_js', $feature_js ); } } public static function feature_selection_form(): void { ?>