php 社区活动(CE):如果用户已登录,请将发布状态设置为已发布,否则回退到CE设置的默认值。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 社区活动(CE):如果用户已登录,请将发布状态设置为已发布,否则回退到CE设置的默认值。相关的知识,希望对你有一定的参考价值。

<?php
/**
 * Community Events (CE): If user is logged in, set post status to Published, else fallback to CE settings' default.
 *
 * Irrelevant if default post status in CE settings is Published or Anonymous Submissions are not allowed.
 *
 * @link https://support.theeventscalendar.com/420384-Auto-publish-events-submitted-by-logged-in-users Relevant help article.
 * @link https://gist.github.com/cliffordp/9b4dff692829ce5d9ddd46d849689dbb This snippet.
 *
 * @param mixed $option     The option value.
 * @param mixed $default    The fallback value.
 * @param mixed $optionName The name of the option.
 *
 * @return mixed
 */
function set_community_events_publication_status( $option, $default, $optionName ) {
	if (
		! class_exists( 'Tribe__Events__Community__Main' )
		|| 'defaultStatus' !== $optionName
		|| ! is_user_logged_in()
	) {
		return $option;
	}

	return 'publish';
}

add_filter( 'tribe_get_single_option', 'set_community_events_publication_status', 10, 3 );

以上是关于php 社区活动(CE):如果用户已登录,请将发布状态设置为已发布,否则回退到CE设置的默认值。的主要内容,如果未能解决你的问题,请参考以下文章