|
Server : LiteSpeed System : Linux srv107862549.host 5.15.0-124-generic #134-Ubuntu SMP Fri Sep 27 20:20:17 UTC 2024 x86_64 User : malam2778 ( 1069) PHP Version : 8.0.30 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_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /proc/self/cwd/wp-content/plugins/wordpress-seo/src/repositories/ |
Upload File : |
<?php
namespace Yoast\WP\SEO\Repositories;
use Yoast\WP\Lib\Model;
use Yoast\WP\Lib\ORM;
use Yoast\WP\SEO\Models\Primary_Term;
/**
* Class Primary_Term_Repository.
*/
class Primary_Term_Repository {
/**
* Starts a query for this repository.
*
* @return ORM
*/
public function query() {
return Model::of_type( 'Primary_Term' );
}
/**
* Retrieves a primary term by a post ID and taxonomy.
*
* @param int $post_id The post the indexable is based upon.
* @param string $taxonomy The taxonomy the indexable belongs to.
* @param bool $auto_create Optional. Creates an indexable if it does not exist yet.
*
* @return Primary_Term|null Instance of a primary term.
*/
public function find_by_post_id_and_taxonomy( $post_id, $taxonomy, $auto_create = true ) {
/**
* Instance of the primary term.
*
* @var Primary_Term $primary_term_indexable
*/
$primary_term_indexable = $this->query()
->where( 'post_id', $post_id )
->where( 'taxonomy', $taxonomy )
->find_one();
if ( $auto_create && ! $primary_term_indexable ) {
$primary_term_indexable = $this->query()->create();
}
return $primary_term_indexable;
}
}