<?php

/***
 * STOCK TICKERS
 */

function xmlsf_news_stock_tickers( $stock_tickers ) {
	global $post;
	$options = get_option('xmlsf_news_advanced');

	if ( !empty($options['stock_tickers']) ) {

		$terms = get_the_terms( $post->ID, 'stock_tickers' );
		$stock_tickers = (array) $stock_tickers;

		if ( $terms && ! is_wp_error( $terms ) ) {
			foreach ( $terms as $term ) {
				if ( is_object($term) && !empty($term->name) )
					$stock_tickers[] = $term->name;
			}
		}
	}

	return $stock_tickers;
}

/***
 * KEYWORDS
 */

function xmlsf_news_keywords( $keywords ) {
	global $post;
	$options = get_option('xmlsf_news_advanced');

	if ( !empty($options['keywords_from']) ) {
		$terms = get_the_terms( $post->ID, $options['keywords_from'] );
		$names = array();

		if ( $terms && ! is_wp_error( $terms ) ) {
			foreach ( $terms as $term ) {
				if ( is_object($term) && !empty($term->name) )
					$names[] = $term->name;
			}
		}
		$keywords = array_merge( (array) $keywords, $names );
	}

	return $keywords;
}
