| 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( 'MywpControllerModuleSitePostType' ) ) : |
| 12 |
|
| 13 |
final class MywpControllerModuleSitePostType extends MywpControllerAbstractModule { |
| 14 |
|
| 15 |
static protected $id = 'site_post_type'; |
| 16 |
|
| 17 |
public static function mywp_controller_initial_data( $initial_data ) { |
| 18 |
|
| 19 |
$initial_data['change_cap_create_posts'] = ''; |
| 20 |
|
| 21 |
return $initial_data; |
| 22 |
|
| 23 |
} |
| 24 |
|
| 25 |
public static function mywp_controller_default_data( $default_data ) { |
| 26 |
|
| 27 |
$default_data['change_cap_create_posts'] = false; |
| 28 |
|
| 29 |
return $default_data; |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
protected static function after_init() { |
| 34 |
|
| 35 |
if( ! self::is_do_controller() ) { |
| 36 |
|
| 37 |
return false; |
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
add_action( 'registered_post_type' , array( __CLASS__ , 'change_cap_create_posts' ) , 10 , 2 ); |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
public static function change_cap_create_posts( $post_type , $post_type_object ) { |
| 46 |
|
| 47 |
if( ! self::is_do_function( __FUNCTION__ ) ) { |
| 48 |
|
| 49 |
return false; |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
if( empty( $post_type ) or empty( $post_type_object ) ) { |
| 54 |
|
| 55 |
return false; |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
if( empty( $post_type_object->cap ) or empty( $post_type_object->cap->create_posts ) ) { |
| 60 |
|
| 61 |
return false; |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
if( strpos( $post_type_object->cap->create_posts , 'edit_' ) === false ) { |
| 66 |
|
| 67 |
return false; |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
$exclude = array( 'custom_css' ); |
| 72 |
|
| 73 |
if( in_array( $post_type , $exclude ) ) { |
| 74 |
|
| 75 |
return false; |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
$setting_data = self::get_setting_data(); |
| 80 |
|
| 81 |
if( empty( $setting_data['change_cap_create_posts'] ) ) { |
| 82 |
|
| 83 |
return false; |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
$post_type_object->cap->create_posts = str_replace( 'edit_' , 'create_' , $post_type_object->cap->create_posts ); |
| 88 |
|
| 89 |
self::after_do_function( __FUNCTION__ ); |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
MywpControllerModuleSitePostType::init(); |
| 97 |
|
| 98 |
endif; |
| 99 |
|