Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Posts_To_Podcast_Helper
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 is_enabled
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_status_permission_check
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Helper for the Posts to Podcast feature.
4 *
5 * @package automattic/jetpack-podcast
6 */
7
8namespace Automattic\Jetpack\Podcast;
9
10/**
11 * Gating + permission helpers for the Posts to Podcast REST endpoint.
12 */
13class Posts_To_Podcast_Helper {
14
15    /**
16     * Whether the Posts to Podcast feature is active for the current request.
17     *
18     * @return bool
19     */
20    public static function is_enabled() {
21        /**
22         * Filter to allow disabling the Posts to Podcast feature on a per-site basis.
23         * Defaults to true wherever the podcast package is active; flip this to false
24         * to hide the section during a staged rollout without disabling the package.
25         *
26         * @since 0.1.0
27         *
28         * @param bool $enabled Whether the feature is enabled. Default true.
29         */
30        return (bool) apply_filters( 'jetpack_posts_to_podcast_is_enabled', true );
31    }
32
33    /**
34     * Permission callback for the local proxy REST endpoint.
35     *
36     * @param \WP_REST_Request $request Full details about the request.
37     *
38     * @return true|\WP_Error
39     */
40    public static function get_status_permission_check( $request ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
41        if ( ! current_user_can( 'edit_posts' ) ) {
42            return new \WP_Error(
43                'rest_forbidden',
44                __( 'Sorry, you are not allowed to use this feature on this site.', 'jetpack-podcast' ),
45                array( 'status' => rest_authorization_required_code() )
46            );
47        }
48
49        return true;
50    }
51}