'docsstation_doc', 'post_status' => 'publish', 'posts_per_page' => -1, ) ); $broken = array(); foreach ( $documents as $document ) { preg_match_all( '/]+href=["\']([^"\']+)["\']/i', $document->post_content, $matches ); foreach ( array_unique( $matches[1] ) as $url ) { $url = trim( html_entity_decode( $url ) ); if ( 0 === strpos( $url, '#' ) || 0 === strpos( $url, 'mailto:' ) || 0 === strpos( $url, 'tel:' ) ) { continue; } $target = url_to_postid( $url ); if ( $target && 'publish' === get_post_status( $target ) ) { continue; } if ( 0 === strpos( $url, home_url( '/' ) ) ) { $broken[] = array( 'document' => $document->ID, 'url' => $url ); } } } update_option( self::LINKS_OPTION, array( 'checked' => current_time( 'mysql' ), 'broken' => $broken ), false ); wp_safe_redirect( add_query_arg( array( 'page' => 'docsstation-analytics', 'link_check' => 'done' ), admin_url( 'edit.php?post_type=docsstation_doc' ) ) ); exit; } public static function delete_feedback() { if ( ! current_user_can( 'manage_options' ) || ! check_admin_referer( 'docsstation_delete_feedback' ) ) { wp_die( esc_html__( 'You are not allowed to delete feedback.', 'docsstation' ) ); } $user_id = isset( $_POST['user_id'] ) ? absint( $_POST['user_id'] ) : 0; $document_id = isset( $_POST['document_id'] ) ? absint( $_POST['document_id'] ) : 0; if ( $user_id && $document_id ) { DocsStation_Feedback::delete_feedback_entry( $user_id, $document_id ); } wp_safe_redirect( admin_url( 'edit.php?post_type=docsstation_doc&page=docsstation-analytics' ) ); exit; } public static function record_view() { if ( ! is_singular( 'docsstation_doc' ) || ! is_main_query() ) { return; } $post_id = get_queried_object_id(); if ( ! $post_id ) { return; } $count = (int) get_post_meta( $post_id, self::VIEWS_META, true ); update_post_meta( $post_id, self::VIEWS_META, $count + 1 ); update_post_meta( $post_id, self::LAST_VIEWED_META, current_time( 'mysql' ) ); } public static function admin_menu() { add_submenu_page( 'edit.php?post_type=docsstation_doc', __( 'DocsStation Analytics', 'docsstation' ), __( 'Analytics', 'docsstation' ), 'manage_options', 'docsstation-analytics', array( __CLASS__, 'analytics_page' ) ); } public static function analytics_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Necessary to fetch top viewed documents for analytics reporting. $documents = get_posts( array( 'post_type' => 'docsstation_doc', 'post_status' => 'publish', 'posts_per_page' => 20, 'no_found_rows' => true, 'update_post_term_cache' => false, 'meta_key' => self::VIEWS_META, 'orderby' => 'meta_value_num', 'order' => 'DESC', ) ); $total_views = 0; foreach ( $documents as $document ) { $total_views += (int) get_post_meta( $document->ID, self::VIEWS_META, true ); } $search_terms = get_option( self::SEARCH_OPTION, array() ); $search_terms = is_array( $search_terms ) ? $search_terms : array(); $link_check = get_option( self::LINKS_OPTION, array() ); $post_counts = wp_count_posts( 'docsstation_doc' ); $published_count = isset( $post_counts->publish ) ? (int) $post_counts->publish : 0; $total_searches = array_sum( array_map( 'intval', $search_terms ) ); $feedback_total = 0; foreach ( $documents as $document ) { $counts = get_post_meta( $document->ID, DocsStation_Feedback::COUNTS_META_KEY, true ); if ( is_array( $counts ) ) { $feedback_total += array_sum( array_map( 'intval', $counts ) ); } } $max_views = $documents ? max( 1, (int) get_post_meta( $documents[0]->ID, self::VIEWS_META, true ) ) : 1; $max_searches = $search_terms ? max( 1, (int) max( $search_terms ) ) : 1; $feedback_rows = get_transient( 'docsstation_feedback_inbox_v2' ); if ( false === $feedback_rows ) { $feedback_rows = array(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Fetching users who submitted document feedback. $feedback_user_ids = get_users( array( 'meta_key' => DocsStation_Feedback::META_KEY, 'fields' => 'ID', 'number' => 100, ) ); foreach ( $feedback_user_ids as $user_id ) { $user_feedback = get_user_meta( $user_id, DocsStation_Feedback::META_KEY, true ); if ( ! is_array( $user_feedback ) ) { continue; } foreach ( $user_feedback as $document_id => $entry ) { if ( ! empty( $entry['comment'] ) && get_post( $document_id ) ) { $feedback_rows[] = array( 'user_id' => (int) $user_id, 'document' => (int) $document_id, 'rating' => isset( $entry['rating'] ) ? $entry['rating'] : '', 'comment' => $entry['comment'], 'updated' => isset( $entry['updated'] ) ? $entry['updated'] : '', ); } } } set_transient( 'docsstation_feedback_inbox_v2', $feedback_rows, 5 * MINUTE_IN_SECONDS ); } usort( $feedback_rows, function ( $left, $right ) { return strcmp( $right['updated'], $left['updated'] ); } ); ?>

ID, self::VIEWS_META, true ); $pct = min( 100, round( ( $views / $max_views ) * 100 ) ); ?>

๐Ÿ“Š

$count ) : $pct = min( 100, round( ( $count / $max_searches ) * 100 ) ); ?>

๐Ÿ”

โ€”

๐Ÿ’ฌ

0 ? 'ds-lh-warn' : 'ds-lh-ok'; ?> 0 ? 'โš ๏ธ' : 'โœ…'; ?>   ยท 
ID, '_docsstation_feedback_counts', true ); $views = (int) get_post_meta( $document->ID, self::VIEWS_META, true ); $helpful = (int) ( is_array( $feedback ) && isset( $feedback['helpful'] ) ? $feedback['helpful'] : 0 ); $not_help = (int) ( is_array( $feedback ) && isset( $feedback['not_helpful'] ) ? $feedback['not_helpful'] : 0 ); $outdated = (int) ( is_array( $feedback ) && isset( $feedback['outdated'] ) ? $feedback['outdated'] : 0 ); $last_view = get_post_meta( $document->ID, self::LAST_VIEWED_META, true ); ?>
ID ) ); ?>