← All changes
|
classes/Controllers/Frontend/Restrictions/MainQuery.php
+24
-16
2.0.4
→
2.6.1
View file →
| @@ -43,8 +43,10 @@ | ||
| 43 | 43 | * Handle a restriction on the main query. |
| 44 | 44 | * |
| 45 | 45 | * NOTE: This is only for redirecting or replacing pages and |
| 46 | 46 | * should not be used to filter or hide post contents. |
| 47 | + * | |
| 48 | + * @return void | |
| 47 | 49 | */ |
| 48 | 50 | public function restrict_main_query() { |
| 49 | 51 | if ( ! \is_main_query() || protection_is_disabled() ) { |
| 50 | 52 | return; |
| @@ -58,8 +60,10 @@ | ||
| 58 | 60 | * Handle restrictions on the main query. |
| 59 | 61 | * |
| 60 | 62 | * NOTE: This is only for redirecting or replacing archives and |
| 61 | 63 | * should not be used to filter or hide post contents. |
| 64 | + * | |
| 65 | + * @return void | |
| 62 | 66 | */ |
| 63 | 67 | public function check_main_query() { |
| 64 | 68 | // Bail if we didn't match any restrictions. |
| 65 | 69 | if ( content_is_restricted() ) { |
| @@ -67,9 +71,9 @@ | ||
| 67 | 71 | |
| 68 | 72 | /** |
| 69 | 73 | * Use this filter to prevent a post from being restricted, or to handle it yourself. |
| 70 | 74 | * |
| 71 | - * @param null $pre Whether to prevent the post from being restricted. | |
| 75 | + * @param null|mixed $pre Whether to prevent the post from being restricted. | |
| 72 | 76 | * @param null|\ContentControl\Models\Restriction $restriction Restriction object. |
| 73 | 77 | * @return null|mixed |
| 74 | 78 | */ |
| 75 | 79 | if ( null !== apply_filters( 'content_control/pre_restrict_main_query', null, $restriction ) ) { |
| @@ -82,16 +86,18 @@ | ||
| 82 | 86 | * @param \ContentControl\Models\Restriction $restriction Restriction object. |
| 83 | 87 | */ |
| 84 | 88 | do_action( 'content_control/restrict_main_query', $restriction ); |
| 85 | 89 | |
| 86 | - switch ( $restriction->protection_method ) { | |
| 90 | + $method = $restriction->get_setting( 'protectionMethod' ); | |
| 91 | + | |
| 92 | + switch ( $method ) { | |
| 87 | 93 | case 'redirect': |
| 88 | - redirect( $restriction->redirect_type, $restriction->redirect_url ); | |
| 94 | + redirect( $restriction->get_setting( 'redirectType' ), $restriction->get_setting( 'redirectUrl' ) ); | |
| 89 | 95 | return; |
| 90 | 96 | |
| 91 | 97 | case 'replace': |
| 92 | - if ( 'page' === $restriction->replacement_type ) { | |
| 93 | - set_query_to_page( $restriction->replacement_page ); | |
| 98 | + if ( 'page' === $restriction->get_setting( 'replacementType' ) ) { | |
| 99 | + set_query_to_page( $restriction->get_setting( 'replacementPage' ) ); | |
| 94 | 100 | return; |
| 95 | 101 | } |
| 96 | 102 | } |
| 97 | 103 | } |
| @@ -101,8 +107,10 @@ | ||
| 101 | 107 | * Handle restrictions on the main query posts. |
| 102 | 108 | * |
| 103 | 109 | * NOTE: This is only for redirecting or replacing archives and |
| 104 | 110 | * should not be used to filter or hide post contents. |
| 111 | + * | |
| 112 | + * @return void | |
| 105 | 113 | */ |
| 106 | 114 | public function check_main_query_posts() { |
| 107 | 115 | $query = get_main_wp_query(); |
| 108 | 116 | |
| @@ -134,14 +142,18 @@ | ||
| 134 | 142 | * @var \ContentControl\Models\Restriction |
| 135 | 143 | */ |
| 136 | 144 | $restriction = $post_restriction['restriction']; |
| 137 | 145 | |
| 138 | - if ( 'redirect' === $restriction->archive_handling || 'replace_archive_page' === $restriction->archive_handling ) { | |
| 146 | + if ( 'redirect' === $restriction->get_setting( 'archiveHandling' ) || 'replace_archive_page' === $restriction->get_setting( 'archiveHandling' ) ) { | |
| 139 | 147 | $restriction_match = $post_restriction; |
| 140 | 148 | break; |
| 141 | 149 | } |
| 142 | 150 | } |
| 143 | 151 | |
| 152 | + if ( false === $restriction_match ) { | |
| 153 | + return; | |
| 154 | + } | |
| 155 | + | |
| 144 | 156 | /** |
| 145 | 157 | * Restriction object. |
| 146 | 158 | * |
| 147 | 159 | * @var \ContentControl\Models\Restriction |
| @@ -148,18 +160,14 @@ | ||
| 148 | 160 | */ |
| 149 | 161 | $restriction = $restriction_match['restriction']; |
| 150 | 162 | $post_ids = $restriction_match['post_ids']; |
| 151 | 163 | |
| 152 | - if ( is_int( $post_ids ) ) { | |
| 153 | - $post_ids = [ $post_ids ]; | |
| 154 | - } | |
| 155 | - | |
| 156 | 164 | /** |
| 157 | 165 | * Use this filter to prevent a post from being restricted, or to handle it yourself. |
| 158 | 166 | * |
| 159 | - * @param null $pre Whether to prevent the post from being restricted. | |
| 167 | + * @param null|mixed $pre Whether to prevent the post from being restricted. | |
| 160 | 168 | * @param null|\ContentControl\Models\Restriction $restriction Restriction object. |
| 161 | - * @param int[] $post_id Post ID. | |
| 169 | + * @param int[] $post_id Post ID. | |
| 162 | 170 | * |
| 163 | 171 | * @return null|mixed |
| 164 | 172 | */ |
| 165 | 173 | if ( null !== apply_filters( 'content_control/pre_restrict_main_query_post', null, $restriction, $post_ids ) ) { |
| @@ -169,18 +177,18 @@ | ||
| 169 | 177 | /** |
| 170 | 178 | * Fires when a post is restricted, but before the restriction is handled. |
| 171 | 179 | * |
| 172 | 180 | * @param \ContentControl\Models\Restriction $restriction Restriction object. |
| 173 | - * @param int[] $post_id Post ID. | |
| 181 | + * @param int[] $post_id Post ID. | |
| 174 | 182 | */ |
| 175 | 183 | do_action( 'content_control/restrict_main_query_post', $restriction, $post_ids ); |
| 176 | 184 | |
| 177 | - switch ( $restriction->archive_handling ) { | |
| 185 | + switch ( $restriction->get_setting( 'archiveHandling' ) ) { | |
| 178 | 186 | case 'replace_archive_page': |
| 179 | - set_query_to_page( $restriction->archive_replacement_page ); | |
| 187 | + set_query_to_page( $restriction->get_setting( 'archiveReplacementPage' ) ); | |
| 180 | 188 | break; |
| 181 | 189 | case 'redirect': |
| 182 | - redirect( $restriction->archive_redirect_type, $restriction->archive_redirect_url ); | |
| 190 | + redirect( $restriction->get_setting( 'archiveRedirectType' ), $restriction->get_setting( 'archiveRedirectUrl' ) ); | |
| 183 | 191 | break; |
| 184 | 192 | } |
| 185 | 193 | } |
| 186 | 194 | } |