@anriko

Передасться ли перменная $post если add_rating_with_add_view если прецепится к хуку postviews_increment_views?

хочу прикрепиться на событие просмотры и add_rating_with_add_view передать id поста для учета рейтинга,что сделал не правильно?
это функция плагина wp-postviews
add_action( 'wp_head', 'process_postviews' );
function process_postviews() {
	global $user_ID, $post;
	if ( is_int( $post ) ) {
		$post = get_post( $post );
	}
	if ( ! wp_is_post_revision( $post ) && ! is_preview() ) {
		if ( is_single() || is_page() ) {
			$id = (int) $post->ID;
			$views_options = get_option( 'views_options' );
			if ( !$post_views = get_post_meta( $post->ID, 'views', true ) ) {
				$post_views = 0;
			}
			$should_count = false;
			switch( (int) $views_options['count'] ) {
				case 0:
					$should_count = true;
					break;
				case 1:
					if( empty( $_COOKIE[ USER_COOKIE ] ) && (int) $user_ID === 0 ) {
						$should_count = true;
					}
					break;
				case 2:
					if( (int) $user_ID > 0 ) {
						$should_count = true;
					}
					break;
			}
			if ( isset( $views_options['exclude_bots'] ) && (int) $views_options['exclude_bots'] === 1 ) {
				$bots = array(
					'Google Bot' => 'google'
					, 'MSN' => 'msnbot'
					, 'Alex' => 'ia_archiver'
					, 'Lycos' => 'lycos'
					, 'Ask Jeeves' => 'jeeves'
					, 'Altavista' => 'scooter'
					, 'AllTheWeb' => 'fast-webcrawler'
					, 'Inktomi' => 'slurp@inktomi'
					, 'Turnitin.com' => 'turnitinbot'
					, 'Technorati' => 'technorati'
					, 'Yahoo' => 'yahoo'
					, 'Findexa' => 'findexa'
					, 'NextLinks' => 'findlinks'
					, 'Gais' => 'gaisbo'
					, 'WiseNut' => 'zyborg'
					, 'WhoisSource' => 'surveybot'
					, 'Bloglines' => 'bloglines'
					, 'BlogSearch' => 'blogsearch'
					, 'PubSub' => 'pubsub'
					, 'Syndic8' => 'syndic8'
					, 'RadioUserland' => 'userland'
					, 'Gigabot' => 'gigabot'
					, 'Become.com' => 'become.com'
					, 'Baidu' => 'baiduspider'
					, 'so.com' => '360spider'
					, 'Sogou' => 'spider'
					, 'soso.com' => 'sosospider'
					, 'Yandex' => 'yandex'
				);
				$useragent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
				foreach ( $bots as $name => $lookfor ) {
					if ( ! empty( $useragent ) && ( false !== stripos( $useragent, $lookfor ) ) ) {
						$should_count = false;
						break;
					}
				}
			}
			$should_count = apply_filters( 'postviews_should_count', $should_count, $id );
			if( $should_count && ( ( isset( $views_options['use_ajax'] ) && (int) $views_options['use_ajax'] === 0 ) || ( !defined( 'WP_CACHE' ) || !WP_CACHE ) ) ) {
				update_post_meta( $id, 'views', $post_views + 1 );



//ВОТ К ЭТОМУ ХУКУ ЦЕПЛЯЮСЬ
				do_action( 'postviews_increment_views', $post_views + 1 );
			}
		}
	}
}

эо хуки wp-recal для добавления кастомного рейтинга
<code lang="php">
if(!is_admin()) add_action('init','rcl_register_add_view_type',30); 
if(is_admin()) add_action('admin_init','rcl_register_add_view_type',30); 
function rcl_register_add_view_type(){ rcl_register_rating_type(array('rating_type'=>'add-view','type_name'=>'просмотры','icon'=>'fa-plus')); }


add_action('postviews_increment_views','add_rating_with_add_view',10,2); 
function add_rating_with_add_view($post){ 
	global $rcl_rating_types; 
if(!$post->user_id) return false; 
$args = array(  
			  'object_id' => $post->ID,
			  'object_author' => $post->user_id, 
			  'rating_value' => $rcl_rating_types['add-view']['type_point'], 
			  'rating_type' => 'add-view' );
rcl_insert_rating($args); 
}</code>
  • Вопрос задан
  • 30 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы