'moderation', //singular name of the listed records 'plural' => 'moderations', //plural name of the listed records 'ajax' => false, //does this table support ajax? 'screen' => 'wpForoModerations', ] ); } /** ************************************************************************ * Recommended. This method is called when the parent class can't find a method * specifically build for a given column. Generally, it's recommended to include * one method for each column you want to render, keeping your package class * neat and organized. For example, if the class needs to process a column * named 'title', it would first see if a method named $this->column_title() * exists - if it does, that method will be used. If it doesn't, this one will * be used. Generally, you should try to use custom column methods as much as * possible. * * Since we have defined a column_title() method later on, this method doesn't * need to concern itself with any column with a name of 'title'. Instead, it * needs to handle everything else. * * For more detailed insight into how columns are handled, take a look at * WP_List_Table::single_row_columns() * * @param array $item A singular item (one full row's worth of data) * @param string $column_name The name/slug of the column to be processed * * @return string Text or HTML to be placed inside the column **************************************************************************/ function column_default( $item, $column_name ) { switch( $column_name ) { case 'title': return apply_filters( 'wpforo_admin_listtables_moderations_column_title', $item[ $column_name ], $item ); case 'userid': $userdata = get_userdata( $item[ $column_name ] ); $display_name = ! empty( $userdata->user_nicename ) ? urldecode( $userdata->user_nicename ) : $item[ $column_name ]; // Check if user is banned $member = WPF()->member->get_member( $item[ $column_name ] ); $is_banned = ( ! empty( $member ) && isset( $member['status'] ) && $member['status'] === 'banned' ); if( $is_banned ) { return '' . esc_html( $display_name ) . ''; } return esc_html( $display_name ); case 'is_first_post': return ( $item[ $column_name ] ) ? __( 'TOPIC', 'wpforo' ) : __( 'REPLY', 'wpforo' ); case 'private': return ( $item[ $column_name ] ) ? __( 'YES', 'wpforo' ) : __( 'NO', 'wpforo' ); default: return $item[ $column_name ]; } } /** ************************************************************************ * Recommended. This is a custom column method and is responsible for what * is rendered in any column with a name/slug of 'title'. Every time the class * needs to render a column, it first looks for a method named * column_{$column_title} - if it exists, that method is run. If it doesn't * exist, column_default() is called instead. * * This example also illustrates how to implement rollover actions. Actions * should be an associative array formatted as 'slug'=>'link html' - and you * will need to generate the URLs yourself. You could even ensure the links * * * @param array $item A singular item (one full row's worth of data) * * @return string Text to be placed inside the column (movie title only) **************************************************************************@see WP_List_Table::::single_row_columns() */ function column_postid( $item ) { $vhref = WPF()->moderation->get_view_url( $item['postid'] ); //Build row actions $actions = [ 'view' => '' . __( 'View', 'wpforo' ) . '' ]; if( $this->get_filter_by_status_var() ) { $ahref = wp_nonce_url( admin_url( sprintf( 'admin.php?page=%1$s&wpfaction=%2$s&postid=%3$s', wpforo_prefix_slug( 'moderations' ), 'dashboard_post_approve', $item['postid'] ) ), 'wpforo-approve-post-' . $item['postid'] ); $actions['wpfapprove'] = '' . __( 'Approve', 'wpforo' ) . ''; } else { $uhref = wp_nonce_url( admin_url( sprintf( 'admin.php?page=%1$s&wpfaction=%2$s&postid=%3$s', wpforo_prefix_slug( 'moderations' ), 'dashboard_post_unapprove', $item['postid'] ) ), 'wpforo-unapprove-post-' . $item['postid'] ); $actions['wpfunapprove'] = '' . __( 'Unapprove', 'wpforo' ) . ''; } $dhref = wp_nonce_url( admin_url( sprintf( 'admin.php?page=%1$s&wpfaction=%2$s&postid=%3$s', wpforo_prefix_slug( 'moderations' ), 'dashboard_post_delete', $item['postid'] ) ), 'wpforo-delete-post-' . $item['postid'] ); $actions['delete'] = '' . __( 'Delete', 'wpforo' ) . ''; // Ban/Unban User action - show based on user's current ban status if( ! empty( $item['userid'] ) && $item['userid'] > 0 && WPF()->usergroup->can( 'bm' ) && intval( $item['userid'] ) !== WPF()->current_userid ) { $member = WPF()->member->get_member( $item['userid'] ); $is_banned = ( ! empty( $member ) && isset( $member['status'] ) && $member['status'] === 'banned' ); if( $is_banned ) { $unban_url = wp_nonce_url( admin_url( sprintf( 'admin.php?page=%1$s&wpfaction=%2$s&userid=%3$s', wpforo_prefix_slug( 'members' ), 'user_unban', $item['userid'] ) ), 'wpforo-user-unban-' . $item['userid'] ); $actions['ban_user'] = '' . __( 'Unban User', 'wpforo' ) . ''; } else { $ban_url = wp_nonce_url( admin_url( sprintf( 'admin.php?page=%1$s&wpfaction=%2$s&userid=%3$s', wpforo_prefix_slug( 'members' ), 'user_ban', $item['userid'] ) ), 'wpforo-user-ban-' . $item['userid'] ); $actions['ban_user'] = '' . __( 'Ban User', 'wpforo' ) . ''; } } // Delete User action - links to WordPress delete user page if( ! empty( $item['userid'] ) && $item['userid'] > 0 && WPF()->usergroup->can( 'dm' ) && intval( $item['userid'] ) !== WPF()->current_userid ) { $delete_user_url = wp_nonce_url( admin_url( 'users.php?action=delete&user=' . intval( $item['userid'] ) ), 'bulk-users' ); $actions['delete_user'] = '' . __( 'Delete User', 'wpforo' ) . ''; } $actions = apply_filters( 'wpforo_admin_listtables_moderations_actions', $actions, $item ); //Return the title contents return sprintf( '%1$s %2$s', /*$1%s*/ $item['postid'], /*$2%s*/ $this->row_actions( $actions ) ); } /** ************************************************************************ * REQUIRED if displaying checkboxes or using bulk actions! The 'cb' column * is given special treatment when columns are processed. It ALWAYS needs to * have its own method. * * @param array $item A singular item (one full row's worth of data) * * @return string Text to be placed inside the column (movie title only) **************************************************************************@see WP_List_Table::::single_row_columns() */ function column_cb( $item ) { return sprintf( '', /*$1%s*/ 'postids', //Let's simply repurpose the table's singular label ("movie") /*$2%s*/ $item['postid'] //The value of the checkbox should be the record's id ); } /** ************************************************************************ * REQUIRED! This method dictates the table's columns and titles. This should * return an array where the key is the column slug (and class) and the value * is the column's title text. If you need a checkbox for bulk actions, refer * to the $columns array below. * * The 'cb' column is treated differently than the rest. If including a checkbox * column in your table you must create a column_cb() method. If you don't need * to bulk actions or checkboxes, simply leave the 'cb' entry out of your array. * * @return array An associative array containing column information: 'slugs'=>'Visible Titles' **************************************************************************@see WP_List_Table::::single_row_columns() */ function get_columns() { return [ 'cb' => '', //Render a checkbox instead of text 'postid' => __( 'ID', 'wpforo' ), 'title' => __( 'Title', 'wpforo' ), 'is_first_post' => __( 'Type', 'wpforo' ), 'userid' => __( 'Created By', 'wpforo' ), 'created' => __( 'Created', 'wpforo' ), 'private' => __( 'Private', 'wpforo' ), ]; } /** ************************************************************************ * Optional. If you want one or more columns to be sortable (ASC/DESC toggle), * you will need to register it here. This should return an array where the * key is the column that needs to be sortable, and the value is db column to * sort by. Often, the key and value will be the same, but this is not always * the case (as the value is a column name from the database, not the list table). * * This method merely defines which columns should be sortable and makes them * clickable - it does not handle the actual sorting. You still need to detect * the ORDERBY and ORDER querystring variables within prepare_items() and sort * your data accordingly (usually by modifying your query). * * @return array An associative array containing all the columns that should be sortable: 'slugs'=>array('data_values',bool) **************************************************************************/ function get_sortable_columns() { return [ 'postid' => [ 'postid', false ], //true means it's already sorted 'title' => [ 'title', false ], 'is_first_post' => [ 'is_first_post', false ], 'userid' => [ 'userid', false ], 'created' => [ 'created', false ], 'private' => [ 'private', false ], ]; } /** ************************************************************************ * Optional. If you need to include bulk actions in your list table, this is * the place to define them. Bulk actions are an associative array in the format * 'slug'=>'Visible Title' * * If this method returns an empty value, no bulk action will be rendered. If * you specify any bulk actions, the bulk actions box will be rendered with * the table automatically on display(). * * Also note that list tables are not automatically wrapped in
elements, * so you will need to create those manually in order for bulk actions to function. * * @return array An associative array containing all the bulk actions: 'slugs'=>'Visible Titles' **************************************************************************/ function get_bulk_actions() { $bulk_actions = []; if( $this->get_filter_by_status_var() ) { $bulk_actions['approve'] = __( 'Approve', 'wpforo' ); } else { $bulk_actions['unapprove'] = __( 'Unapprove', 'wpforo' ); } $bulk_actions['delete'] = __( 'Delete', 'wpforo' ); return $bulk_actions; } /** ************************************************************************ * REQUIRED! This is where you prepare your data for display. This method will * usually be used to query the database, sort and filter the data, and generally * get it ready to be displayed. At a minimum, we should set $this->items and * $this->set_pagination_args(), although the following properties and methods * are frequently interacted with here... * * @uses $this->_column_headers * @uses $this->items * @uses $this->get_columns() * @uses $this->get_sortable_columns() * @uses $this->get_pagenum() * @uses $this->set_pagination_args() **************************************************************************/ function prepare_items() { /** * First, lets decide how many records per page to show */ $per_page = wpforo_get_option( 'count_per_page', 10 ); /** * REQUIRED. Now we need to define our column headers. This includes a complete * array of columns to be displayed (slugs & titles), a list of columns * to keep hidden, and a list of columns that are sortable. Each of these * can be defined in another method (as we've done here) before being * used to build the value for our _column_headers property. */ $columns = $this->get_columns(); $hidden = []; $sortable = $this->get_sortable_columns(); /** * REQUIRED. Finally, we build an array to be used by the class for column * headers. The $this->_column_headers property takes an array which contains * 3 other arrays. One for all columns, one for hidden columns, and one * for sortable columns. */ $this->_column_headers = [ $columns, $hidden, $sortable ]; /** * REQUIRED. Now we can add our *sorted* data to the items' property, where * it can be used by the rest of the class. */ $args = [ 'check_private' => false, 'status' => $this->get_filter_by_status_var(), 'orderby' => '`created` DESC, `postid` DESC' ]; if( $s = wpfval( $_REQUEST, 's' ) ) { $args['include'] = WPF()->moderation->search( $s ); } $filter_by_userid = $this->get_filter_by_userid_var(); $orderby = wpfval( $_REQUEST, 'orderby' ); $order = strtoupper( (string) wpfval( $_REQUEST, 'order' ) ); if( $filter_by_userid !== - 1 ) $args['userid'] = $filter_by_userid; if( $type = $this->get_filter_by_type_var() ){ $args['is_first_post'] = $type === 'topic'; } if( array_key_exists( $orderby, $sortable ) ) $args['orderby'] = sanitize_text_field( $orderby ); if( in_array( $order, [ 'ASC', 'DESC' ] ) ) $args['order'] = sanitize_text_field( $order ); $paged = $this->get_pagenum(); $args['offset'] = ( $paged - 1 ) * $per_page; $args['row_count'] = $per_page; $items_count = 0; $this->items = ( isset( $args['include'] ) && empty( $args['include'] ) ? [] : WPF()->post->get_posts( $args, $items_count ) ); $this->wpfitems_count = $items_count; $this->set_pagination_args( [ 'total_items' => $items_count, //WE have to calculate the total number of items 'per_page' => $per_page, //WE have to determine how many items to show on a page 'total_pages' => ceil( $items_count / $per_page ) //WE have to calculate the total number of pages ] ); } public function get_filter_by_status_var() { $filter_by_status = wpfval( $_REQUEST, 'filter_by_status' ); if( ! is_null( $filter_by_status ) && $filter_by_status !== '-1' ) { $status = intval( $filter_by_status ); } else { $status = 1; } return $status; } public function get_filter_by_type_var() { $filter_by_type = wpfval( $_REQUEST, 'filter_by_type' ); return in_array( $filter_by_type, [ 'topic', 'reply' ], true ) ? $filter_by_type : ''; } public function get_filter_by_userid_var() { $filter_by_userid = wpfval( $_REQUEST, 'filter_by_userid' ); if( ! is_null( $filter_by_userid ) && $filter_by_userid !== '-1' ) { $userid = wpforo_bigintval( $filter_by_userid ); } else { $userid = - 1; } return $userid; } public function users_dropdown() { ?> get_filter_by_status_var(); if( $statuses = WPF()->moderation->post_statuses ) : ?> get_filter_by_type_var(); ?> get_filter_by_status_var() !== 1 ) { return; } // Get moderation data for this post $moderation_data = $this->get_moderation_data( $item ); // Always render the report row to maintain odd/even striping // Empty rows will be hidden via CSS $this->render_moderation_report_row( $item, $moderation_data ); } /** * Get moderation data for a post * * @param array $item Post item data * @return array|null Moderation data or null */ private function get_moderation_data( $item ) { $postid = intval( $item['postid'] ); // Check cache first if( isset( $this->moderation_cache[ $postid ] ) ) { return $this->moderation_cache[ $postid ]; } $result = []; // Determine content type $is_first_post = ! empty( $item['is_first_post'] ); $content_type = $is_first_post ? 'topic' : 'post'; $content_id = $is_first_post ? ( $item['topicid'] ?? $item['postid'] ) : $item['postid']; // Get AI Moderation data (if AI Moderation is active) if( class_exists( '\wpforo\classes\AIContentModeration' ) && ! empty( WPF()->ai_content_moderation ) ) { $ai_logs = WPF()->ai_content_moderation->get_moderation_logs( $content_type, (int) $content_id ); if( ! empty( $ai_logs ) ) { $result['ai_moderation'] = $ai_logs; } } // Check for wpForo built-in antispam (this is simple - just a flag that post was unapproved by antispam) // Built-in antispam doesn't store detailed data, but we can check if it was likely antispam-based // by looking at whether user is new or if spam patterns were detected if( empty( $result['ai_moderation'] ) && ! empty( $item['userid'] ) ) { $new_user_max_posts = wpforo_setting( 'antispam', 'new_user_max_posts' ); if( $new_user_max_posts ) { $user_posts = WPF()->member->member_approved_posts( $item['userid'] ); if( $user_posts <= $new_user_max_posts ) { // Likely caught by built-in antispam for new users $result['builtin_antispam'] = [ 'reason' => 'new_user', 'label' => __( 'New User Filter', 'wpforo' ), 'description' => __( 'Post was automatically held for moderation because the author is a new user.', 'wpforo' ), ]; } } } // Cache the result $this->moderation_cache[ $postid ] = $result; return $result; } /** * Render the moderation report row * * @param array $item Post item data * @param array $moderation_data Moderation data (can be empty) */ private function render_moderation_report_row( $item, $moderation_data ) { $columns_count = count( $this->get_columns() ); $has_data = ! empty( $moderation_data ); $row_class = 'wpf-moderation-report-row' . ( $has_data ? '' : ' wpf-moderation-report-empty' ); ?>
render_ai_moderation_report( $log ); } } // Display built-in antispam info if( ! empty( $moderation_data['builtin_antispam'] ) ) { $this->render_builtin_antispam_report( $moderation_data['builtin_antispam'] ); } ?>
[ 'label' => $is_ai ? __( 'Spam Detection', 'wpforo' ) : __( 'Auto Moderation', 'wpforo' ), 'icon' => '', 'color' => $is_ai ? '#d63384' : '#0d6efd', ], 'toxicity' => [ 'label' => __( 'Toxicity Detection', 'wpforo' ), 'icon' => '', 'color' => '#fd7e14', ], 'compliance' => [ 'label' => __( 'Policy Compliance', 'wpforo' ), 'icon' => '', 'color' => '#6f42c1', ], 'flood' => [ 'label' => __( 'Auto Moderation', 'wpforo' ), 'icon' => '', 'color' => '#0d6efd', ], ]; $config = $type_config[ $mod_type ] ?? $type_config['spam']; // Status class and label $status_class = 'clean'; $status_label = __( 'Clean', 'wpforo' ); if( $score >= 85 ) { $status_class = 'detected'; $status_label = __( 'Detected', 'wpforo' ); } elseif( $score >= 70 ) { $status_class = 'suspected'; $status_label = __( 'Suspected', 'wpforo' ); } elseif( $score >= 51 ) { $status_class = 'uncertain'; $status_label = __( 'Uncertain', 'wpforo' ); } // Action labels $action_labels = [ 'none' => __( 'No action', 'wpforo' ), 'approve' => __( 'Auto-approved', 'wpforo' ), 'auto_approve' => __( 'Auto-approved', 'wpforo' ), 'unapprove' => __( 'Unapproved', 'wpforo' ), 'unapprove_ban' => __( 'Unapproved + Banned', 'wpforo' ), 'delete_author' => __( 'Deleted + Banned', 'wpforo' ), ]; $action_label = $action_labels[ $action ] ?? $action; // Quality labels $quality_labels = [ 'fast' => __( 'Fast', 'wpforo' ), 'balanced' => __( 'Balanced', 'wpforo' ), 'advanced' => __( 'Advanced', 'wpforo' ), 'premium' => __( 'Premium', 'wpforo' ), 'rule_based' => __( 'Rule-based', 'wpforo' ), ]; $quality_label = $quality_labels[ $quality ] ?? $quality; ?>
0 ) : ?>