$label ) { $new[ $key ] = $label; if ( 'title' === $key ) { $new['aimslms_enrolled'] = __( 'Enrolled', 'aims-infosoft-lms' ); $new['aimslms_price'] = __( 'Price', 'aims-infosoft-lms' ); } } return $new; } ); add_action( 'manage_aimslms_course_posts_custom_column', function ( $column, $post_id ) { global $wpdb; if ( 'aimslms_enrolled' === $column ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom table, no WP API alternative. $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT user_id) FROM {$wpdb->prefix}aimslms_course_enrollments WHERE course_id = %d", $post_id ) ); echo esc_html( intval( $count ) ); } if ( 'aimslms_price' === $column ) { $price = get_post_meta( $post_id, '_aimslms_price', true ); if ( '' === $price ) { echo 'Free'; } else { echo esc_html( aimslms_format_price( $price ) ); } } }, 10, 2 ); add_filter( 'manage_edit-aimslms_course_sortable_columns', function ( $columns ) { $columns['aimslms_price'] = 'aimslms_price'; $columns['aimslms_enrolled'] = 'aimslms_enrolled'; return $columns; } ); add_action( 'pre_get_posts', function ( $query ) { if ( ! is_admin() || ! $query->is_main_query() || $query->get( 'post_type' ) !== 'aimslms_course' ) { return; } if ( $query->get( 'orderby' ) === 'aimslms_price' ) { $query->set( 'meta_key', '_aimslms_price' ); $query->set( 'orderby', 'meta_value_num' ); } } ); /** * Check whether a payment gateway is connected (sandbox or live). * * @param string $gateway Gateway identifier. * @return bool True if the gateway has a connected sandbox or live status. */ function aimslms_is_gateway_connected( $gateway ) { $sandbox = get_option( "aimslms_{$gateway}_connection_status_sandbox" ); $live = get_option( "aimslms_{$gateway}_connection_status_live" ); return ( 'connected' === $sandbox || 'connected' === $live ); } /** * Delete all data belonging to a student across custom plugin tables and delete the WP user. * * @param int $user_id User ID whose data should be deleted. */ function aimslms_delete_student_data( $user_id ) { global $wpdb; $tables = array( $wpdb->prefix . 'aimslms_course_enrollments', $wpdb->prefix . 'aimslms_course_progress', $wpdb->prefix . 'aimslms_course_payment', $wpdb->prefix . 'aimslms_course_certificates', $wpdb->prefix . 'aimslms_course_orders', ); foreach ( $tables as $table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom table, no WP API alternative. $wpdb->delete( $table, array( 'user_id' => $user_id ), array( '%d' ) ); } // Delete WordPress user. require_once ABSPATH . 'wp-admin/includes/user.php'; wp_delete_user( $user_id ); }