Changeset 3205648
- Timestamp:
- 12/10/2024 01:00:27 PM (16 months ago)
- Location:
- simple-page-access-restriction/trunk
- Files:
-
- 3 edited
-
changelog.txt (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
simple-page-access-restriction.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-page-access-restriction/trunk/changelog.txt
r3128968 r3205648 1 = Version 1.0.30 - December 12, 2024 = 2 * Fix: Exclude restricted posts from GET and REST search queries 3 1 4 = Version 1.0.29 - July 31, 2024 = 2 5 * Fix: Allow query parameters in the redirect URL -
simple-page-access-restriction/trunk/readme.txt
r3128968 r3205648 8 8 Tested up to: 6.5 9 9 Requires PHP: 5.6 10 Stable Tag: 1.0. 2910 Stable Tag: 1.0.30 11 11 License: GPL v2 or later 12 12 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 116 116 117 117 == Changelog == 118 = Version 1.0.30 - December 12, 2024 = 119 * Fix: Exclude restricted posts from GET and REST search queries 120 118 121 = Version 1.0.29 - July 31, 2024 = 119 122 * Fix: Allow query parameters in the redirect URL -
simple-page-access-restriction/trunk/simple-page-access-restriction.php
r3128968 r3205648 4 4 * Plugin URI: https://www.pluginsandsnippets.com/downloads/simple-page-access-restriction/ 5 5 * Description: This plugin offers a simple way to restrict visits to select pages only to logged-in users and allows for page redirection to a defined (login) page of your choice. 6 * Version: 1.0. 296 * Version: 1.0.30 7 7 * Author: Plugins & Snippets 8 8 * Author URI: https://www.pluginsandsnippets.com/ … … 39 39 private static $instance; 40 40 private static $admin_instance; 41 42 public function __construct() { 43 44 } 45 41 42 public function __construct() {} 46 43 47 44 /** … … 80 77 81 78 // Plugin related constants 82 define( 'SIMPLE_PAGE_ACCESS_RESTRICTION_VER', '1.0. 29' );79 define( 'SIMPLE_PAGE_ACCESS_RESTRICTION_VER', '1.0.30' ); 83 80 define( 'SIMPLE_PAGE_ACCESS_RESTRICTION_NAME', 'Simple Page Access Restriction' ); 84 81 define( 'SIMPLE_PAGE_ACCESS_RESTRICTION_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) ); … … 130 127 */ 131 128 private function hooks() { 129 add_action( 'init', array( $this, 'add_rest_api_filters' ) ); 130 add_filter( 'pre_get_posts', array( $this, 'exclude_restricted_posts' ) ); 132 131 add_action( 'template_redirect', array( $this, 'check_page_access' ), 1 ); 133 add_action( 'init', array( $this, 'add_rest_api_filters' ) ); 132 } 133 134 /** 135 * Change the GET and REST search queries 136 * to exclude restricted posts. 137 * 138 * @param WP_Query $query The query. 139 * @return WP_Query The query. 140 */ 141 public function exclude_restricted_posts( $query ) { 142 // Check if the request is for the backend. 143 if ( is_admin() ) { 144 // Return the query. 145 return $query; 146 } 147 148 // Set the restrict. 149 $restrict = false; 150 151 // Check if the request is for the main search query. 152 if ( $query->is_search && $query->is_main_query() ) { 153 // Set the restrict. 154 $restrict = true; 155 } 156 157 // Check if the request is a REST request. 158 if ( defined( 'REST_REQUEST' ) && REST_REQUEST && isset( $query->query_vars['s'] ) ) { 159 // Set the restrict. 160 $restrict = true; 161 } 162 163 // Check the restrict. 164 if ( $restrict ) { 165 // Set the meta_query. 166 $meta_query = array( 167 'relation' => 'OR', 168 array( 169 array( 170 'key' => 'page_access_restricted', 171 'value' => '0', 172 'compare' => '=', 173 ), 174 ), 175 array( 176 'key' => 'page_access_restricted', 177 'compare' => 'NOT EXISTS', 178 ), 179 ); 180 181 // Set the query. 182 $query->set( 'meta_query', $meta_query ); 183 } 184 185 // Return the query. 186 return $query; 134 187 } 135 188
Note: See TracChangeset
for help on using the changeset viewer.