HEX
Server: Apache
System: Linux 162-240-236-42.bluehost.com 3.10.0-1160.114.2.el7.x86_64 #1 SMP Wed Mar 20 15:54:52 UTC 2024 x86_64
User: bt667 (1004)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /home/bt667/public_html/wp-content/plugins/schema/includes/extensions/comment.php
<?php

/**
 *  Comment extention
 *
 *  Adds schema Comment for Article types
 *
 *  @since 1.5.3
 */
 
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly


add_filter( 'schema_output', 'schema_wp_do_comments_number' );
/**
 * Add comments number for Article types via schema_output filter  
 *
 * @since 1.5.3
 * @return array 
 */
function schema_wp_do_comments_number( $schema ) {
	
	$comments_enable = schema_wp_get_option( 'comments_enable' );
	
	if ( $comments_enable != true )
		return $schema;
		
	global $post;
	
	$schema_type = $schema["@type"];

	$support_article_types 	= schema_wp_get_support_article_types();
	
	if ( in_array( $schema_type, $support_article_types, false) )
		$schema["commentCount"] = get_comments_number($post->ID);
	
	return $schema;
}


add_filter( 'schema_output', 'schema_wp_do_comment' );
/**
 * Add Schema Comment for Article types via schema_output filter  
 *
 * @since 1.5.3
 * @return array 
 */
function schema_wp_do_comment( $schema ) {
	
	$comments_enable = schema_wp_get_option( 'comments_enable' );
	
	if ( $comments_enable != true )
		return $schema;
		
	global $post;
	
	$schema_type 			= $schema["@type"];
	$support_article_types 	= schema_wp_get_support_article_types();
	$number 				= apply_filters( 'schema_wp_do_comment_number', '10'); // default = 10
	
	if ( in_array( $schema_type, $support_article_types, true) ) {
		$Comments = schema_wp_get_comments();
		if ( !empty($Comments) )	
			$schema["comment"] = $Comments;
	}
	
	return $schema;
}


/**
 * Get comments   
 *
 * @since 1.5.4
 * @return array 
 */
function schema_wp_get_comments( $post_id = null ) {
		
	if ( isset($post_id) ) {
		$post = get_post($post_id);
	} else {
		global $post;
	}
	
	// Check comments count first, if now comments, then return an empty array
	// @since 1.7.1
	$comment_count = get_comments_number( $post->ID );
	if ( $comment_count < 1 ) {
		return array();
	}

	$number	= apply_filters( 'schema_wp_do_comments', '10'); // default = 10
		
	$Comments = array();
	
	$PostComments = get_comments( array( 'post_id' => $post->ID, 'number' => $number, 'status' => 'approve', 'type' => 'comment' ) );

	if ( count( $PostComments ) ) {
		foreach ( $PostComments as $Item ) {
			$Comments[] = array (
					'@type' => 'Comment',
					'dateCreated' => $Item->comment_date,
					'description' => $Item->comment_content,
					'author' => array (
						'@type' => 'Person',
						'name' => $Item->comment_author,
						'url' => $Item->comment_author_url,
				),
			);
		}

		return apply_filters( 'schema_wp_filter_comments', $Comments );
	}
}