| Server IP : 103.82.32.14 / Your IP : 216.73.217.121 Web Server : Apache/2.2.32 (Unix) mod_ssl/2.2.32 OpenSSL/1.0.1e-fips mod_fcgid/2.3.9 System : Linux cloud.lonmanhoabinh.com 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : lonmakmf ( 524) PHP Version : 5.6.30 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /home/lonmakmf/public_html/wp-content/plugins/wordpress-seo/inc/ |
Upload File : |
<?php
/**
* @package WPSEO
*/
/**
* Represents a post's primary term
*/
class WPSEO_Primary_Term {
/**
* @var string
*/
protected $taxonomy_name;
/**
* @var int
*/
protected $post_ID;
/**
* The taxonomy this term is part of
*
* @param string $taxonomy_name Taxonomy name for the term.
* @param int $post_ID Post ID for the term.
*/
public function __construct( $taxonomy_name, $post_ID ) {
$this->taxonomy_name = $taxonomy_name;
$this->post_ID = $post_ID;
}
/**
* Returns the primary term ID
*
* @return int|bool
*/
public function get_primary_term() {
$primary_term = get_post_meta( $this->post_ID, WPSEO_Meta::$meta_prefix . 'primary_' . $this->taxonomy_name, true );
$terms = $this->get_terms();
if ( ! in_array( $primary_term, wp_list_pluck( $terms, 'term_id' ) ) ) {
$primary_term = false;
}
// By default the first term (sorted by ID) is the primary term.
if ( ! $primary_term ) {
if ( ! empty( $terms ) ) {
usort( $terms, '_usort_terms_by_ID' );
$primary_term = array_shift( $terms );
$primary_term = $primary_term->term_id;
}
}
$primary_term = (int) $primary_term;
return ( $primary_term ) ? ( $primary_term ) : false;
}
/**
* Sets the new primary term ID
*
* @param int $new_primary_term New primary term ID.
*/
public function set_primary_term( $new_primary_term ) {
update_post_meta( $this->post_ID, WPSEO_Meta::$meta_prefix . 'primary_' . $this->taxonomy_name, $new_primary_term );
}
/**
* Get the terms for the current post ID.
* When $terms is not an array, set $terms to an array.
*
* @return array
*/
protected function get_terms() {
$terms = get_the_terms( $this->post_ID, $this->taxonomy_name );
if ( ! is_array( $terms ) ) {
$terms = array();
}
return $terms;
}
}