-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into feature/9/caching-404s
- Loading branch information
Showing
19 changed files
with
547 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/alley/wp/alleyvate/features/class-disable-attachment-routing.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* Class file for Disable_Attachment_Routing | ||
* | ||
* (c) Alley <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package wp-alleyvate | ||
*/ | ||
|
||
namespace Alley\WP\Alleyvate\Features; | ||
|
||
use Alley\WP\Alleyvate\Feature; | ||
|
||
/** | ||
* Disable attachment routing. | ||
*/ | ||
final class Disable_Attachment_Routing implements Feature { | ||
/** | ||
* Boot the feature. | ||
*/ | ||
public function boot(): void { | ||
add_filter( 'pre_option_wp_attachment_pages_enabled', '__return_zero', 100 ); | ||
add_filter( 'rewrite_rules_array', [ self::class, 'filter__rewrite_rules_array' ] ); | ||
add_filter( 'attachment_link', [ self::class, 'filter__attachment_link' ] ); | ||
add_action( 'pre_get_posts', [ self::class, 'action__pre_get_posts' ] ); | ||
add_action( 'admin_bar_menu', [ self::class, 'action__admin_bar_menu' ], 100 ); | ||
} | ||
|
||
/** | ||
* Remove support for the attachment rewrite rule. | ||
* | ||
* @param array $rules Rewrite rules. | ||
* @return array | ||
*/ | ||
public static function filter__rewrite_rules_array( $rules ): array { | ||
foreach ( $rules as $regex => $query ) { | ||
if ( strpos( $regex, 'attachment' ) || strpos( $query, 'attachment' ) ) { | ||
unset( $rules[ $regex ] ); | ||
} | ||
} | ||
|
||
return $rules; | ||
} | ||
|
||
/** | ||
* Remove the attachment link. | ||
* | ||
* @param string $link Attachment link. | ||
* @return string | ||
*/ | ||
public static function filter__attachment_link( $link ): string { | ||
return ''; | ||
} | ||
|
||
/** | ||
* Ensure attachment pages return 404s. | ||
* | ||
* @param WP_Query $query WP_Query object. | ||
*/ | ||
public static function action__pre_get_posts( $query ) { | ||
if ( is_admin() || ! $query->is_main_query() ) { | ||
return; | ||
} | ||
|
||
if ( | ||
$query->queried_object instanceof \WP_Post | ||
&& 'attachment' === get_post_type( $query->get_queried_object_id() ) | ||
) { | ||
$query->set_404(); | ||
status_header( 404 ); | ||
} | ||
} | ||
|
||
/** | ||
* Remove attachment link from admin bar. | ||
* | ||
* @param \WP_Admin_Bar $wp_admin_bar Admin bar class. | ||
*/ | ||
public static function action__admin_bar_menu( $wp_admin_bar ): void { | ||
if ( 'attachment' === get_post_type() ) { | ||
$wp_admin_bar->remove_node( 'view' ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/alley/wp/alleyvate/features/class-disable-custom-fields-meta-box.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* Class file for Disable_Custom_Fields_Meta_Box | ||
* | ||
* (c) Alley <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package wp-alleyvate | ||
*/ | ||
|
||
namespace Alley\WP\Alleyvate\Features; | ||
|
||
use Alley\WP\Alleyvate\Feature; | ||
|
||
/** | ||
* Disable the custom fields meta box. | ||
*/ | ||
final class Disable_Custom_Fields_Meta_Box implements Feature { | ||
/** | ||
* Boot the feature. | ||
*/ | ||
public function boot(): void { | ||
add_action( 'add_meta_boxes', [ self::class, 'action__add_meta_boxes' ], 9999 ); | ||
} | ||
|
||
/** | ||
* Remove the "Custom Fields" meta box. | ||
* | ||
* It generates an expensive query and is almost never used in practice. | ||
*/ | ||
public static function action__add_meta_boxes(): void { | ||
remove_meta_box( 'postcustom', null, 'normal' ); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/alley/wp/alleyvate/features/class-disable-password-change-notification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Class file for Disable_Password_Change_Notification | ||
* | ||
* (c) Alley <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package wp-alleyvate | ||
*/ | ||
|
||
namespace Alley\WP\Alleyvate\Features; | ||
|
||
use Alley\WP\Alleyvate\Feature; | ||
|
||
/** | ||
* Fully disables password change notifications. | ||
*/ | ||
final class Disable_Password_Change_Notification implements Feature { | ||
/** | ||
* Boot the feature. | ||
*/ | ||
public function boot(): void { | ||
remove_action( 'after_password_reset', 'wp_password_change_notification' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.