| Server IP : 68.183.124.220 / Your IP : 216.73.217.137 Web Server : Apache/2.4.18 (Ubuntu) System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : gavin ( 1000) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/wp-content/plugins/wordpress-seo/inc/ |
Upload File : |
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO
*/
/**
* Represents a post's primary term.
*/
class WPSEO_Primary_Term {
/**
* Taxonomy name for the term.
*
* @var string
*/
protected $taxonomy_name;
/**
* Post ID for the term.
*
* @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;
}
$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;
}
}