brand_list(); ?>
*
term_id; $brands[ $term_id ]['name'] = $taxonomy->name; $brands[ $term_id ]['description'] = $taxonomy->description; $brands[ $term_id ]['slug'] = $taxonomy->slug; if ( isset( $options[ $term_id ] ) ) { $brands[ $term_id ]['icon'] = $options[ $term_id ]; } elseif ( isset( $brand[ $term_id ]['icon'] ) ) { $brands[ $term_id ]['icon'] = $brand[ $term_id ]['icon']; } else { $brands[ $term_id ]['icon'] = ''; } } } ksort( $brands ); update_option( 'abprf_brand', $brands ); } public function brand_list(): void { $abprf_brands = ABPRF_Function::get_option( 'abprf_brand' ); $count = 1; if ( ! empty( $abprf_brands ) && is_array( $abprf_brands ) && sizeof( $abprf_brands ) > 0 ) { ?> $brand ) { $name = $brand['name'] ?? ''; $description = $brand['description'] ?? ''; $icon = $brand['icon'] ?? ''; ?>
. [abprf-property brand_id=""]
0 ) { ?>

'', '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_int_array = fn( $key ) => ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) ? array_map( 'absint', wp_unslash( $_POST[ $key ] ) ) : []; $post_array = fn( $key ) => ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST[ $key ] ) ) : []; $post_slug_array = fn( $key ) => ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) ? array_map( 'sanitize_title', wp_unslash( $_POST[ $key ] ) ) : []; $post_textarea_array = fn( $key ) => ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) ? array_map( 'sanitize_textarea_field', wp_unslash( $_POST[ $key ] ) ) : []; $ids = $post_int_array( 'brand_id' ); $names = $post_array( 'brand_name' ); $icons = $post_array( 'brand_icon' ); $slugs = $post_slug_array( 'brand_slug' ); $descriptions = $post_textarea_array( 'brand_description' ); $property_add = $post_int( 'property_add' ); $options = []; $msg = ''; if ( ! empty( $names ) ) { foreach ( $names as $key => $name ) { if ( ! empty( $name ) ) { $id = $ids[ $key ] ?? 0; $slug = $slugs[ $key ] ?? ''; $description = $descriptions[ $key ] ?? ''; if ( $id > 0 ) { $result = wp_update_term( $id, 'abprf_brand', [ 'name' => $name, 'slug' => $slug, 'description' => $description, ] ); } else { $result = wp_insert_term( $name, 'abprf_brand', [ 'slug' => $slug, 'description' => $description, ] ); } if ( is_wp_error( $result ) ) { $msg = $result->get_error_message(); } else { if ( ! $id ) { $id = absint( $result['term_id'] ?? 0 ); } if ( $id > 0 ) { $options[ $id ] = $icons[ $key ] ?? ''; } } } } $this->update_brand( $options ); if ( empty( $msg ) ) { $msg = __( 'Brand Saved Successfully !', 'abp-rentalforge' ); } } else { $msg = __( 'Brand not Saved ! Brand Name can not Blank !...!', 'abp-rentalforge' ); } ob_start(); if ( $property_add > 0 ) { $brands = ''; $property_id = $post_int( 'property_id' ); if ( $property_id > 0 ) { $properties = ABPRF_Query::get_property( [ 'property_id' => $property_id ] ); if ( ! empty( $properties ) && is_array( $properties ) ) { $property = current( $properties ); $brands = $property['brand'] ?? ''; } } self::brand_selection( $brands ); } else { $this->brand_list(); } $html = ob_get_clean(); wp_send_json_success( [ 'html' => $html, 'msg' => $msg ] ); } public function delete_brand(): 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 ); } $brand_id = isset( $_POST['brand_id'] ) ? absint( wp_unslash( $_POST['brand_id'] ) ) : 0; if ( $brand_id <= 0 ) { wp_send_json_error( [ 'html' => '', 'msg' => __( 'Invalid Brand ID ..... !!', 'abp-rentalforge' ) ], 400 ); } $result = wp_delete_term( $brand_id, 'abprf_brand' ); if ( is_wp_error( $result ) ) { ob_start(); $this->brand_list(); $html = ob_get_clean(); wp_send_json_error( [ 'html' => $html, 'msg' => $result->get_error_message() ], 400 ); } $brands = ABPRF_Function::get_option( 'abprf_brand' ); if ( is_array( $brands ) && isset( $brands[ $brand_id ] ) ) { unset( $brands[ $brand_id ] ); update_option( 'abprf_brand', $brands ); } ob_start(); $this->brand_list(); $html = ob_get_clean(); wp_send_json_success( [ 'html' => $html, 'msg' => __( 'Brand Delete Successfully !', 'abp-rentalforge' ) ] ); } public function edit_brand(): 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 ); } $id = isset( $_POST['id'] ) ? absint( wp_unslash( $_POST['id'] ) ) : 0; if ( $id <= 0 ) { wp_send_json_error( [ 'html' => '', 'msg' => __( 'Invalid Brand ID ..... !!', 'abp-rentalforge' ) ], 400 ); } $brands = ABPRF_Function::get_option( 'abprf_brand' ); $brands = is_array( $brands ) ? $brands : []; $brand = $brands[ $id ] ?? []; ob_start(); self::form_brand( $brand, $id ); $html = ob_get_clean(); wp_send_json_success( [ 'html' => $html, 'msg' => __( 'Brand Ready to Editing...... !', 'abp-rentalforge' ) ] ); } } new ABPRF_Brand(); }