Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
9 / 12
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Base
72.73% covered (warning)
72.73%
8 / 11
0.00% covered (danger)
0.00%
0 / 1
9.30
0.00% covered (danger)
0.00%
0 / 1
 check
72.73% covered (warning)
72.73%
8 / 11
0.00% covered (danger)
0.00%
0 / 1
9.30
1<?php
2
3declare(strict_types=1);
4
5namespace Beyondwords\Wordpress\Core\Player\Renderer;
6
7use Beyondwords\Wordpress\Component\Post\PostMetaUtils;
8use Beyondwords\Wordpress\Component\Settings\Fields\IntegrationMethod\IntegrationMethod;
9use Beyondwords\Wordpress\Core\CoreUtils;
10
11/**
12 * Class Base.
13 *
14 * Base class for player renderers.
15 */
16defined('ABSPATH') || exit;
17
18class Base
19{
20    /**
21     * Check whether a player should be rendered.
22     *
23     * @param \WP_Post $post WordPress post object.
24     *
25     * @return bool True if a player should be rendered.
26     */
27    public static function check(\WP_Post $post): bool
28    {
29        if (function_exists('is_preview') && is_preview()) {
30            return false;
31        }
32
33        if (CoreUtils::isGutenbergPage() || CoreUtils::isEditScreen()) {
34            return false;
35        }
36
37        $projectId = PostMetaUtils::getProjectId($post->ID);
38
39        if (! $projectId) {
40            return false;
41        }
42
43        $contentId = PostMetaUtils::getContentId($post->ID);
44        $method = IntegrationMethod::getIntegrationMethod($post);
45
46        return $method === IntegrationMethod::CLIENT_SIDE ||
47               ($method === IntegrationMethod::REST_API && $contentId);
48    }
49}