| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if( ! class_exists( 'MywpControllerAbstractModule' ) ) { |
| 8 |
return false; |
| 9 |
} |
| 10 |
|
| 11 |
if ( ! class_exists( 'MywpControllerModuleFrontendAuthorArchive' ) ) : |
| 12 |
|
| 13 |
final class MywpControllerModuleFrontendAuthorArchive extends MywpControllerAbstractModule { |
| 14 |
|
| 15 |
static protected $id = 'frontend_author_archive'; |
| 16 |
|
| 17 |
public static function mywp_controller_initial_data( $initial_data ) { |
| 18 |
|
| 19 |
$initial_data['disable_archive'] = ''; |
| 20 |
|
| 21 |
return $initial_data; |
| 22 |
|
| 23 |
} |
| 24 |
|
| 25 |
public static function mywp_controller_default_data( $default_data ) { |
| 26 |
|
| 27 |
$default_data['disable_archive'] = false; |
| 28 |
|
| 29 |
return $default_data; |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
public static function mywp_wp_loaded() { |
| 34 |
|
| 35 |
if( is_admin() ) { |
| 36 |
|
| 37 |
return false; |
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
if( ! self::is_do_controller() ) { |
| 42 |
|
| 43 |
return false; |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
add_action( 'pre_get_posts' , array( __CLASS__ , 'disable_archive' ) ); |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
public static function disable_archive( $wp_query ) { |
| 52 |
|
| 53 |
if( ! self::is_do_function( __FUNCTION__ ) ) { |
| 54 |
|
| 55 |
return $wp_query; |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
if( empty( $wp_query->is_author ) ) { |
| 60 |
|
| 61 |
return $wp_query; |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
$setting_data = self::get_setting_data(); |
| 66 |
|
| 67 |
if( empty( $setting_data['disable_archive'] ) ) { |
| 68 |
|
| 69 |
return $wp_query; |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
$wp_query->set_404(); |
| 74 |
|
| 75 |
self::after_do_function( __FUNCTION__ ); |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
MywpControllerModuleFrontendAuthorArchive::init(); |
| 82 |
|
| 83 |
endif; |
| 84 |
|