Skip to content

Commit 1c00319

Browse files
committed
Merge branch 'release/2.3.0'
2 parents dc956eb + c40d443 commit 1c00319

File tree

12 files changed

+426
-207
lines changed

12 files changed

+426
-207
lines changed

CHANGELOG.md

Lines changed: 129 additions & 119 deletions
Large diffs are not rendered by default.

classes/Controllers/Compatibility.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace ContentControl\Controllers;
1111

1212
use ContentControl\Base\Controller;
13+
use ContentControl\Controllers\Compatibility\BetterDocs;
1314
use ContentControl\Controllers\Compatibility\Divi;
1415
use ContentControl\Controllers\Compatibility\Elementor;
1516
use ContentControl\Controllers\Compatibility\QueryMonitor;
@@ -31,6 +32,7 @@ class Compatibility extends Controller {
3132
*/
3233
public function init() {
3334
$this->container->register_controllers( [
35+
'Compatibility\BetterDocs' => new BetterDocs( $this->container ),
3436
'Compatibility\Divi' => new Divi( $this->container ),
3537
'Compatibility\Elementor' => new Elementor( $this->container ),
3638
'Compatibility\QueryMonitor' => new QueryMonitor( $this->container ),
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* BetterDocs controller class.
4+
*
5+
* @package ContentControl
6+
*/
7+
8+
namespace ContentControl\Controllers\Compatibility;
9+
10+
use ContentControl\Base\Controller;
11+
12+
/**
13+
* BetterDocs controller class.
14+
*/
15+
class BetterDocs extends Controller {
16+
17+
/**
18+
* Initiate hooks & filter.
19+
*
20+
* @return void
21+
*/
22+
public function init() {
23+
add_action( 'content_control/get_rest_api_intent', [ $this, 'get_rest_api_intent' ], 10 );
24+
}
25+
26+
/**
27+
* Get intent for BetterDocs.
28+
*
29+
* @param array<string,mixed> $intent Intent.
30+
*
31+
* @return array<string,mixed>
32+
*/
33+
public function get_rest_api_intent( $intent ) {
34+
global $wp;
35+
36+
37+
if ( ! defined( 'BETTERDOCS_PLUGIN_FILE' ) ) {
38+
return $intent;
39+
}
40+
41+
$rest_route = $wp->query_vars['rest_route'];
42+
$endpoint_parts = explode( '/', str_replace( '/wp/v2/', '', $rest_route ) );
43+
44+
// Set the custom search intent.
45+
if ( isset( $wp->query_vars['search'] ) ) {
46+
$intent['search'] = sanitize_title( $wp->query_vars['search'] );
47+
}
48+
49+
if ( 'unknown' === $intent['type'] && 'docs' === $intent['name'] ) {
50+
// If we have a post type or taxonomy, the name is the first part (posts, categories).
51+
$post_type = sanitize_key( $endpoint_parts[0] );
52+
53+
if ( 'docs' === $post_type ) {
54+
$intent['type'] = 'post_type';
55+
}
56+
}
57+
58+
// phpcs:disable WordPress.Security.NonceVerification.Recommended
59+
if ( isset( $_REQUEST['post_type'] ) ) {
60+
$post_type = sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) );
61+
62+
// Check if any ct_forced_* request aregs are set. If so we should use the post type intent.
63+
if ( strpos( $post_type, 'ct_forced_' ) !== false ) {
64+
$intent['type'] = 'post_type';
65+
66+
$post_type = str_replace( 'ct_forced_', '', $post_type );
67+
68+
$intent['name'] = explode( ':', $post_type );
69+
}
70+
}
71+
// phpcs:enable WordPress.Security.NonceVerification.Recommended
72+
73+
return $intent;
74+
}
75+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "code-atlantic/content-control",
3-
"version": "2.2.8",
3+
"version": "2.3.0",
44
"type": "wordpress-plugin",
55
"license": "GPL-2.0-or-later",
66
"minimum-stability": "dev",

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

content-control.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Content Control
44
* Plugin URI: https://contentcontrolplugin.com/?utm_campaign=plugin-info&utm_source=php-file-header&utm_medium=plugin-ui&utm_content=plugin-uri
55
* Description: Restrict content to logged in/out users or specific user roles. Restrict access to certain parts of a page/post. Control the visibility of widgets.
6-
* Version: 2.2.8
6+
* Version: 2.3.0
77
* Author: Code Atlantic
88
* Author URI: https://code-atlantic.com/?utm_campaign=plugin-info&utm_source=php-file-header&utm_medium=plugin-ui&utm_content=author-uri
99
* Donate link: https://code-atlantic.com/donate/?utm_campaign=donations&utm_source=php-file-header&utm_medium=plugin-ui&utm_content=donate-link
@@ -30,7 +30,7 @@ function get_plugin_config() {
3030
return [
3131
'name' => \__( 'Content Control', 'content-control' ),
3232
'slug' => 'content-control',
33-
'version' => '2.2.8',
33+
'version' => '2.3.0',
3434
'option_prefix' => 'content_control',
3535
// Maybe remove this and simply prefix `name` with `'Popup Maker'`.
3636
'text_domain' => 'content-control',

inc/functions/developers.php

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -334,42 +334,82 @@ function check_referrer_is_admin() {
334334
}
335335

336336
/**
337-
* Check if protection methods should be disabled.
338-
*
339-
* Generally used to bypass protections when using page editors.
337+
* Check if request is excluded.
340338
*
341339
* @return bool
342340
*
343-
* @since 2.0.0
341+
* @since 2.3.0
344342
*/
345-
function protection_is_disabled() {
346-
$is_disabled = false;
343+
function request_is_excluded() {
344+
static $is_excluded;
347345

348-
if (
349-
// Disable protection when user is excluded.
350-
( user_is_excluded() ) ||
351-
352-
// Check if doing cron.
353-
( defined( 'DOING_CRON' ) && DOING_CRON ) ||
346+
if ( isset( $is_excluded ) ) {
347+
return $is_excluded;
348+
}
354349

355-
// Check if doing ADMIN AJAX from valid admin referrer.
356-
( defined( 'DOING_AJAX' ) && DOING_AJAX && check_referrer_is_admin() ) ||
350+
$is_excluded = false;
357351

358-
// Check if doing REST API from valid admin referrer.
359-
( is_rest() && check_referrer_is_admin() ) ||
352+
if (
353+
// Check if doing cron.
354+
is_cron()
360355

361356
// If this is rest request and not core wp namespace.
362-
( is_rest() && ! is_wp_core_rest_namespace() ) ||
363-
364-
// Disable protection when viewing post previews.
365-
( is_preview() && current_user_can( 'edit_post', get_the_ID() ) ) ||
357+
// || ( is_rest() && ! is_wp_core_rest_namespace() ).
366358

367359
// Disable protection when not on the frontend.
368-
( ! is_frontend() && ! is_rest() )
360+
// || ( ! is_frontend() && ! is_rest() ).
369361
) {
370-
$is_disabled = true;
362+
$is_excluded = true;
371363
}
372364

365+
return $is_excluded;
366+
}
367+
368+
/**
369+
* Check if the request is for a priveleged user in the admin area.
370+
*
371+
* @return bool
372+
*
373+
* @since 2.3.0
374+
*/
375+
function request_for_user_is_excluded() {
376+
// Check if user has permission to manage settings and is on the admin area.
377+
if ( user_is_excludable() ) {
378+
if (
379+
// Is in the admin area.
380+
is_admin() ||
381+
// Is an ajax request from the admin area.
382+
(
383+
( is_ajax() || is_rest() ) &&
384+
check_referrer_is_admin()
385+
)
386+
) {
387+
return true;
388+
}
389+
}
390+
391+
$post_id = get_the_ID();
392+
393+
// Disable protection when viewing post previews or editing a post.
394+
if ( ( $post_id > 0 || is_preview() ) && current_user_can( 'edit_post', $post_id ) ) {
395+
return true;
396+
}
397+
398+
return false;
399+
}
400+
401+
/**
402+
* Check if protection methods should be disabled.
403+
*
404+
* Generally used to bypass protections when using page editors.
405+
*
406+
* @return bool
407+
*
408+
* @since 2.0.0
409+
*/
410+
function protection_is_disabled() {
411+
$is_disabled = user_is_excluded() || request_is_excluded() || request_for_user_is_excluded();
412+
373413
/**
374414
* Filter whether protection is disabled.
375415
*

inc/functions/query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,5 +400,5 @@ function get_rest_api_intent() {
400400
$intent = $result;
401401
}
402402

403-
return $intent;
403+
return apply_filters( 'content_control/get_rest_api_intent', $intent );
404404
}

inc/functions/restrictions.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,22 @@ function admins_are_excluded() {
3333
return get_data_version( 'settings' ) > 1 && plugin()->get_option( 'excludeAdmins' );
3434
}
3535

36+
/**
37+
* Current user is excluded from restrictions.
38+
*
39+
* @return bool True if user is excluded, false if not.
40+
*/
41+
function user_is_excludable() {
42+
return \current_user_can( plugin()->get_permission( 'manage_settings' ) );
43+
}
44+
3645
/**
3746
* Current user is excluded from restrictions.
3847
*
3948
* @return bool True if user is excluded, false if not.
4049
*/
4150
function user_is_excluded() {
42-
return admins_are_excluded() && \current_user_can( plugin()->get_permission( 'manage_settings' ) );
51+
return admins_are_excluded() && user_is_excludable();
4352
}
4453

4554
/**

0 commit comments

Comments
 (0)