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