category_list(); ?>
0 ) { foreach ( $taxonomies as $taxonomy ) { $category[ $taxonomy->term_id ]['name'] = $taxonomy->name; $category[ $taxonomy->term_id ]['description'] = $taxonomy->description; } } ksort( $category ); update_option( 'abprf_category', $category ); } public function category_list(): void { $all_categories = ABPRF_Function::get_option( 'abprf_category' ); $count = 1; if ( ! empty( $all_categories ) && is_array( $all_categories ) && sizeof( $all_categories ) > 0 ) { ?> $category ) { $name = $category['name'] ?? ''; $description = $category['description'] ?? ''; ?>
. [abprf-post cat_id=""] [abprf-property cat_id=""]
name; $slug = $term->slug; $des = $term->description; } } ?>
0 ) { ?>
$category ) { $name = $category['name'] ?? ''; ?>

'', '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_val = fn( $key, $default = '' ) => isset( $_POST[ $key ] ) ? sanitize_text_field( wp_unslash( $_POST[ $key ] ) ) : $default; $post_textarea = fn( $key, $default = '' ) => isset( $_POST[ $key ] ) ? sanitize_textarea_field( wp_unslash( $_POST[ $key ] ) ) : $default; $post_slug = fn( $key, $default = '' ) => isset( $_POST[ $key ] ) ? sanitize_title( wp_unslash( $_POST[ $key ] ) ) : $default; $cat_term_id = $post_int( 'cat_term_id' ); $name = $post_val( 'name' ); $slug = $post_slug( 'slug' ); $description = $post_textarea( 'description' ); $abprf_post_id = $post_int( 'abprf_post_id' ); if ( empty( $name ) ) { wp_send_json_error( [ 'html' => '', 'msg' => __( 'Category Name cannot be blank!', 'abp-rentalforge' ) ], 400 ); } if ( $cat_term_id > 0 ) { $result = wp_update_term( $cat_term_id, 'abprf_category', [ 'name' => $name, 'slug' => $slug, 'description' => $description, ] ); } else { $result = wp_insert_term( $name, 'abprf_category', [ 'slug' => $slug, 'description' => $description, ] ); } $this->update_category(); ob_start(); if ( $abprf_post_id > 0 ) { $_category = ABPRF_Function::get_post_info( $abprf_post_id, 'abprf_category' ); self::category_selection( $_category ); } else { $this->category_list(); } $html = ob_get_clean(); if ( is_wp_error( $result ) ) { wp_send_json_error( [ 'html' => $html, 'msg' => $result->get_error_message() ], 400 ); } wp_send_json_success( [ 'html' => $html, 'msg' => __( 'Category Saved Successfully !', 'abp-rentalforge' ) ] ); } public function delete_category(): 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 ); } $cat_id = isset( $_POST['cat_id'] ) ? absint( wp_unslash( $_POST['cat_id'] ) ) : 0; if ( ! $cat_id ) { wp_send_json_error( __( 'Invalid Category ID.', 'abp-rentalforge' ), 400 ); } $result = wp_delete_term( $cat_id, 'abprf_category' ); $this->update_category(); ob_start(); $this->category_list(); $html = ob_get_clean(); if ( is_wp_error( $result ) ) { wp_send_json_error( [ 'html' => $html, 'msg' => $result->get_error_message() ], 400 ); } global $wpdb; $table_name = $wpdb->prefix . 'abprf_property'; $all_ids = ABPRF_Query::get_post_id( [ 'cat_id' => $cat_id ] ); if ( count( $all_ids ) > 0 ) { foreach ( $all_ids as $id ) { $id = absint( $id ); $category = ABPRF_Function::get_post_info( $id, 'category' ); $category = ! empty( $category ) ? explode( ',', $category ) : []; if ( ! empty( $category ) && in_array( (string) $cat_id, $category, true ) ) { $category = array_diff( $category, [ (string) $cat_id ] ); $category = ! empty( $category ) ? implode( ',', $category ) : ''; update_post_meta( $id, 'category', $category ); $data = [ 'category' => $category ]; $where = [ 'post_id' => $id ]; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->update( $table_name, $data, $where, [ '%s' ], [ '%d' ] ); } } } wp_send_json_success( [ 'html' => $html, 'msg' => __( 'Category Delete Successfully !', 'abp-rentalforge' ) ] ); } public function add_category(): 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 ); } $cat_id = isset( $_POST['tax_id'] ) ? absint( wp_unslash( $_POST['tax_id'] ) ) : 0; ob_start(); $this->form( $cat_id ); $html = ob_get_clean(); wp_send_json_success( [ 'html' => $html, 'msg' => __( 'Category Form Loaded Successfully .....! ', 'abp-rentalforge' ) ] ); } } new ABPRF_Category(); }