PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.1.36
Gallery : FooGallery v3.1.36
3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / class-posttypes.php
foogallery / includes Last commit date
abilities 2 months ago admin 2 months ago compatibility 2 months ago extensions 2 months ago foopluginbase 2 months ago public 2 months ago thumbs 2 months ago asset-manifest.php 2 months ago class-attachment-filters.php 2 months ago class-command-palette.php 2 months ago class-foogallery-animated-gif-support.php 2 months ago class-foogallery-attachment-custom-class.php 2 months ago class-foogallery-attachment-filename.php 2 months ago class-foogallery-attachment-type.php 2 months ago class-foogallery-attachment.php 2 months ago class-foogallery-cache.php 2 months ago class-foogallery-common-fields.php 2 months ago class-foogallery-crop-position.php 2 months ago class-foogallery-datasource-media_library.php 2 months ago class-foogallery-debug.php 2 months ago class-foogallery-delayed-runtime-loader.php 2 months ago class-foogallery-extensions-compatibility.php 2 months ago class-foogallery-force-https.php 2 months ago class-foogallery-lazyload.php 2 months ago class-foogallery-license-constant-handler.php 2 months ago class-foogallery-lightbox.php 2 months ago class-foogallery-paging.php 2 months ago class-foogallery-password-protect.php 2 months ago class-foogallery-sitemaps.php 2 months ago class-foogallery-widget.php 2 months ago class-foogallery.php 2 months ago class-gallery-advanced-settings.php 2 months ago class-il8n.php 2 months ago class-override-thumbnail.php 2 months ago class-posttypes.php 2 months ago class-previews.php 2 months ago class-retina.php 2 months ago class-thumbnail-dimensions.php 2 months ago class-thumbnails.php 2 months ago class-version-check.php 2 months ago constants.php 2 months ago functions.php 2 months ago includes.php 2 months ago index.php 2 months ago render-functions.php 2 months ago
class-posttypes.php
227 lines
1 <?php
2 /*
3 * FooGallery Custom Post Types and Custom Taxonomy Registration class
4 */
5
6 if ( ! class_exists( 'FooGallery_PostTypes' ) ) {
7
8 class FooGallery_PostTypes {
9
10 const GALLERY_CAPABILITIES = array(
11 'edit_post' => 'edit_foogallery',
12 'read_post' => 'read_foogallery',
13 'delete_post' => 'delete_foogallery',
14 'edit_posts' => 'edit_foogalleries',
15 'edit_others_posts' => 'edit_others_foogalleries',
16 'delete_posts' => 'delete_foogalleries',
17 'publish_posts' => 'publish_foogalleries',
18 'read_private_posts' => 'read_private_foogalleries',
19 'create_posts' => 'create_foogalleries'
20 );
21
22 function __construct() {
23 //register the post types
24 add_action( 'init', array( $this, 'register' ) );
25
26 //register the custom capabilities.
27 add_action( 'admin_init', array( $this, 'add_capabilities' ) );
28
29 //update post type messages
30 add_filter( 'post_updated_messages', array( $this, 'update_messages' ) );
31
32 //update post bulk messages
33 add_filter( 'bulk_post_updated_messages', array( $this, 'update_bulk_messages' ), 10, 2 );
34
35 //clear capabilities after option update.
36 add_action( 'update_option_foogallery', array( $this, 'clear_capabilities' ), 10, 3 );
37
38 // Keep galleries in the classic editor when editor support is enabled for descriptions.
39 add_filter( 'use_block_editor_for_post_type', array( $this, 'force_classic_editor' ), 10, 2 );
40 }
41
42 /**
43 * Registers the custom post type for galleries.
44 *
45 * This function is responsible for registering the custom post type 'gallery' used by the FooGallery plugin.
46 * It now includes custom capabilities and adds filters for custom capability mapping and menu visibility control.
47 */
48 function register() {
49
50 $args = array(
51 'labels' => array(
52 'name' => __( 'Galleries', 'foogallery' ),
53 'singular_name' => __( 'Gallery', 'foogallery' ),
54 'add_new' => __( 'Add Gallery', 'foogallery' ),
55 'add_new_item' => __( 'Add New Gallery', 'foogallery' ),
56 'edit_item' => __( 'Edit Gallery', 'foogallery' ),
57 'new_item' => __( 'New Gallery', 'foogallery' ),
58 'view_item' => __( 'View Gallery', 'foogallery' ),
59 'search_items' => __( 'Search Galleries', 'foogallery' ),
60 'not_found' => __( 'No Galleries found', 'foogallery' ),
61 'not_found_in_trash' => __( 'No Galleries found in Trash', 'foogallery' ),
62 'menu_name' => foogallery_plugin_name(),
63 'all_items' => __( 'Galleries', 'foogallery' ),
64 ),
65 'hierarchical' => false,
66 'public' => false, // set to false to make the post type private
67 'rewrite' => false,
68 'show_ui' => true,
69 'show_in_menu' => true,
70 'show_in_rest' => true,
71 'rest_base' => 'foogallery',
72 'menu_icon' => 'dashicons-format-gallery',
73 'supports' => array( 'title', 'thumbnail' ),
74 'map_meta_cap' => true,
75 'capabilities' => FooGallery_PostTypes::GALLERY_CAPABILITIES
76 );
77
78 $args = apply_filters( 'foogallery_gallery_posttype_register_args', $args );
79 register_post_type( FOOGALLERY_CPT_GALLERY, $args );
80 }
81
82 /**
83 * Force galleries to use the classic editor.
84 *
85 * @param bool $use_block_editor Whether the post type should use the block editor.
86 * @param string $post_type The post type being checked.
87 *
88 * @return bool
89 */
90 public function force_classic_editor( $use_block_editor, $post_type ) {
91 if ( FOOGALLERY_CPT_GALLERY === $post_type ) {
92 return false;
93 }
94
95 return $use_block_editor;
96 }
97
98 /**
99 * Adds capabilities to the allowed roles, based on the gallery creator role that is set.
100 *
101 * @return void
102 */
103 function add_capabilities( $force = false ) {
104 global $foogallery_adding_capabilities;
105
106 $gallery_creator_role = foogallery_setting_gallery_creator_role();
107 $previous_capabilities = get_option('foogallery_capabilities_set' );
108
109 if ( $force || $gallery_creator_role !== $previous_capabilities ) {
110
111 $foogallery_adding_capabilities = true;
112 update_option( 'foogallery_capabilities_set', $gallery_creator_role );
113 $foogallery_adding_capabilities = false;
114
115 // Get the roles
116 $roles = foogallery_get_roles_and_higher( $gallery_creator_role );
117
118 foreach ( $roles as $the_role ) {
119 $role = get_role( $the_role );
120
121 if ( !is_null( $role ) ) {
122
123 foreach ( FooGallery_PostTypes::GALLERY_CAPABILITIES as $cap_key => $cap ) {
124 $role->add_cap( $cap );
125 }
126 }
127 }
128 }
129 }
130
131 /**
132 * Clears the capabilities based on the new value, old value, and option.
133 *
134 * @param mixed $old_value The old value.
135 * @param mixed $value The new value.
136 * @param string $option The option.
137 */
138 function clear_capabilities( $old_value, $value, $option ) {
139 global $foogallery_adding_capabilities;
140 // Get out early, if we are busy updating capabilities.
141 if ( $foogallery_adding_capabilities ) {
142 return;
143 }
144
145 if ( $old_value === $value ) {
146 return;
147 }
148
149 $gallery_creator_role = foogallery_setting_gallery_creator_role();
150 $previous_capabilities = get_option('foogallery_capabilities_set' );
151
152 if ( $gallery_creator_role !== $previous_capabilities ) {
153
154 // Get all roles
155 $roles = wp_roles()->get_names();
156
157 // Loop through each role and remove the capabilities
158 foreach ( $roles as $role => $name ) {
159 $role_obj = get_role($role);
160 if (!is_null($role_obj)) {
161 foreach ( FooGallery_PostTypes::GALLERY_CAPABILITIES as $cap_key => $cap ) {
162 $role_obj->remove_cap($cap);
163 }
164 }
165 }
166
167 do_action('foogallery_gallery_posttype_clear_capabilities');
168 $this->add_capabilities( true );
169 }
170 }
171
172 /**
173 * Customize the update messages for a gallery.
174 *
175 * @global object $post The current post object.
176 *
177 * @param array $messages Array of default post updated messages.
178 *
179 * @return array $messages Amended array of post updated messages.
180 */
181 public function update_messages( $messages ) {
182 global $post;
183
184 // Add our gallery messages.
185 $messages[FOOGALLERY_CPT_GALLERY] = apply_filters( 'foogallery_gallery_posttype_update_messages',
186 array(
187 0 => '',
188 1 => __( 'Gallery updated.', 'foogallery' ),
189 2 => __( 'Gallery custom field updated.', 'foogallery' ),
190 3 => __( 'Gallery custom field deleted.', 'foogallery' ),
191 4 => __( 'Gallery updated.', 'foogallery' ),
192 5 => isset($_GET['revision']) ? sprintf( __( 'Gallery restored to revision from %s.', 'foogallery' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
193 6 => __( 'Gallery published.', 'foogallery' ),
194 7 => __( 'Gallery saved.', 'foogallery' ),
195 8 => __( 'Gallery submitted.', 'foogallery' ),
196 9 => sprintf( __( 'Gallery scheduled for: <strong>%1$s</strong>.', 'foogallery' ), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) ),
197 10 => __( 'Gallery draft updated.', 'foogallery' )
198 )
199 );
200
201 return $messages;
202 }
203
204 /**
205 * Customize the bulk update messages for a gallery
206 *
207 * @param array $bulk_messages Array of default bulk updated messages.
208 * @param array $bulk_counts Array containing count of posts involved in the action.
209 *
210 * @return array mixed Amended array of bulk updated messages.
211 */
212 function update_bulk_messages( $bulk_messages, $bulk_counts ) {
213 $bulk_messages[FOOGALLERY_CPT_GALLERY] = apply_filters( 'foogallery_gallery_posttype_bulk_update_messages',
214 array(
215 'updated' => _n( '%s Gallery updated.', '%s Galleries updated.', $bulk_counts['updated'], 'foogallery' ),
216 'locked' => _n( '%s Gallery not updated, somebody is editing it.', '%s Galleries not updated, somebody is editing them.', $bulk_counts['locked'], 'foogallery' ),
217 'deleted' => _n( '%s Gallery permanently deleted.', '%s Galleries permanently deleted.', $bulk_counts['deleted'], 'foogallery' ),
218 'trashed' => _n( '%s Gallery moved to the Trash.', '%s Galleries moved to the Trash.', $bulk_counts['trashed'], 'foogallery' ),
219 'untrashed' => _n( '%s Gallery restored from the Trash.', '%s Galleries restored from the Trash.', $bulk_counts['untrashed'], 'foogallery' ),
220 )
221 );
222
223 return $bulk_messages;
224 }
225 }
226 }
227