php 事件日历:事件聚合器:查找缺少所需UID的导入iCal事件。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 事件日历:事件聚合器:查找缺少所需UID的导入iCal事件。相关的知识,希望对你有一定的参考价值。

<?php

/**
 * The Events Calendar: Event Aggregator: Find imported iCal events missing the
 * required UID.
 *
 * If logged-in as an Administrator: event post IDs with links to their wp-admin
 * edit screen will appear on your Front Page (will not work if your home page
 * is your Blog page).
 *
 * @link https://gist.github.com/cliffordp/63f285cf719eda762b3349bdf03401f9
 * @link https://theeventscalendar.com/support/forums/topic/scheduled-imports-not-working-11/#post-1383206
 */
add_filter( 'the_content', 'cliff_events_imported_by_ea_missing_uid', 50 );
function cliff_events_imported_by_ea_missing_uid( $content ) {
	if (
		// only display our results on the home page (won't appear if is_home()
		! is_front_page()
		// or current user is not an Administrator
		|| ! current_user_can( 'create_users' )
	) {
		return $content;
	}

	$args = array(
		'post_type'      => 'tribe_events',
		// 'post_status' => 'any',
		'posts_per_page' => - 1,
		'orderby'        => 'ID',
		// 'order' => 'ASC',
		'fields'         => 'ids', // just the post ID
		'meta_query'     => array(
			array(
				'key'     => '_EventOrigin',
				'value'   => 'event-aggregator',
				'compare' => '=',
			),
			array(
				'key'     => '_tribe_aggregator_origin',
				'value'   => array( 'ical', 'ics', 'gcal' ), // not 'facebook', 'meetup', or 'url', since those sources use their respective APIs instead of their iCal URLs
				'compare' => 'IN',
			),
			array(
				'key'     => '_uid',
				'compare' => 'NOT EXISTS', // MAY NEED TO INSTEAD LOOK FOR EQUALS ''
			),
		),
	);

	$ids = get_posts( $args );

	$output = '';

	if ( ! empty( $ids ) ) {
		$output .= PHP_EOL . 'iCal Events Imported by Event Aggregator missing their UID: ';

		foreach ( $ids as $key => $value ) {
			$output .= sprintf( '<a href="/wp-admin/post.php?post=%1$s&action=edit">%1$s</a>', $value ); // edit links

			// add comma if not last in array (this method only works for arrays with unique values)
			if ( $value !== end( $ids ) ) {
				$output .= ', ' . PHP_EOL;
			}
		}

		$output .= PHP_EOL;
		$output .= '<br><br>';
	}

	$content = $output . $content;

	return $content;
}

以上是关于php 事件日历:事件聚合器:查找缺少所需UID的导入iCal事件。的主要内容,如果未能解决你的问题,请参考以下文章

php 事件日历:事件聚合器:覆盖导入范围默认值。

php 事件日历:事件聚合器:覆盖导入范围默认值。

php 事件日历:事件聚合器:永远不会导入任何场地。

php 事件日历:事件聚合器:永远不会导入任何场地。

php 事件日历:事件聚合器:所有导入的事件设置为特定用户作为帖子作者。

php 事件日历:事件聚合器:所有导入的事件设置为特定用户作为帖子作者。