Changeset 12687
- Timestamp:
- 07/03/2023 06:19:58 PM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/moderation.php
r12551 r12687 64 64 65 65 /** 66 * Adds the 'Photos Moderator' role. 67 */ 68 public static function add_roles() { 69 add_role( 70 'photos_moderator', 71 __( 'Photos Moderator', 'wporg-photos' ), 72 [ 73 // Capabilities for photo posts. 74 'read' => true, 75 'edit_photos' => true, 76 'delete_photos' => true, 77 'publish_photos' => true, 78 'edit_others_photos' => true, 79 'delete_others_photos' => true, 80 'edit_published_photos' => true, 81 'delete_published_photos' => true, 66 * Returns all capabilities for photos-related roles. 67 * 68 * @param bool $for_photos_admin Optional. Should capabilites include those 69 * exclusive to Photo Admins? 70 * Default false. 71 * @return array 72 */ 73 public static function get_photos_caps( $for_photos_admin = false ) { 74 $caps = [ 75 // Capabilities for photo posts. 76 'read' => true, 77 'edit_photos' => true, 78 'delete_photos' => true, 79 'publish_photos' => true, 80 'edit_others_photos' => true, 81 'delete_others_photos' => true, 82 'edit_published_photos' => true, 83 'delete_published_photos' => true, 84 'upload_files' => true, 85 ]; 86 87 if ( $for_photos_admin ) { 88 $caps = array_merge( $caps, [ 89 // Manage flagged and private photos. 90 'manage_flagged_photos' => true, 91 'delete_private_photos' => true, 82 92 'edit_private_photos' => true, 83 'delete_private_photos' => true,84 93 'read_private_photos' => true, 85 'upload_files' => true,86 94 // Capabilities for posts and media. 87 95 'edit_posts' => true, … … 92 100 'edit_published_posts' => true, 93 101 'delete_published_posts' => true, 94 'edit_private_posts' => true,95 'delete_private_posts' => true,96 'read_private_posts' => true,97 102 'edit_post' => true, 98 103 'delete_post' => true, 99 104 'read_post' => true, 100 ] 101 ); 105 ] ); 106 } 107 108 return $caps; 109 } 110 111 /** 112 * Adds the photos-specific roles. 113 * 114 * Adds: 115 * - photos_moderator: User who can moderate photos. 116 * - photos_administrator: Same as photos moderator, but can additionally: 117 * - Access and manage private (aka flagged) photos. 118 * - Create/edit/delete posts. 119 */ 120 public static function add_roles() { 121 // Remove the roles first, in case the permission set has changed. 122 remove_role( 'photos_moderator' ); 123 remove_role( 'photos_administrator' ); 124 125 add_role( 126 'photos_moderator', 127 __( 'Photo Moderator', 'wporg-photos' ), 128 self::get_photos_caps() 129 ); 130 131 $admin_caps = self::get_photos_caps( true ); 132 133 add_role( 134 'photos_administrator', 135 __( 'Photo Admin', 'wporg-photos' ), 136 $admin_caps 137 ); 138 139 // Add capabilites to administrator role. 140 $admin = get_role( 'administrator' ); 141 if ( $admin ) { 142 foreach ( $admin_caps as $cap => $val ) { 143 $admin->add_cap( $cap ); 144 } 145 } 146 } 147 148 /** 149 * Removes the photo-specific roles. 150 * 151 * Removes: 152 * - photos_moderator 153 * - photos_administrator 154 */ 155 public static function remove_roles() { 156 remove_role( 'photos_moderator' ); 157 remove_role( 'photos_administrator' ); 158 159 // Remove added capabilites from administrator role. 160 $admin = get_role( 'administrator' ); 161 foreach ( self::get_photos_caps( true ) as $cap => $val ) { 162 // Only remove photos-specific caps. 163 if ( false !== strpos( $cap, 'photo' ) ) { 164 $admin->remove_cap( $cap ); 165 } 166 } 102 167 } 103 168 … … 562 627 } 563 628 564 $content .= '<h 2>' . __( 'Submissions awaiting moderation', 'wporg-photos' ) . "</h2>\n";629 $content .= '<h3>' . __( 'Submissions awaiting moderation', 'wporg-photos' ) . "</h3>\n"; 565 630 $content .= '<p>'; 566 631 $max_pending_submissions = User::get_concurrent_submission_limit( $user_id ); … … 661 726 662 727 register_activation_hook( WPORG_PHOTO_DIRECTORY_DIRECTORY . '/photo-directory.php', [ __NAMESPACE__ . '\Moderation', 'add_roles' ] ); 728 register_deactivation_hook( WPORG_PHOTO_DIRECTORY_DIRECTORY . '/photo-directory.php', [ __NAMESPACE__ . '\Moderation', 'remove_roles' ] ); 663 729 664 730 add_action( 'plugins_loaded', [ __NAMESPACE__ . '\Moderation', 'init' ] );
Note: See TracChangeset
for help on using the changeset viewer.