PluginProbe ʕ •ᴥ•ʔ
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel / trunk
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel vtrunk
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
admin 7 months ago compatibility 7 months ago extensions 7 months ago foopluginbase 7 months ago public 7 months ago thumbs 7 months ago .DS_Store 7 months ago class-attachment-filters.php 7 months ago class-foogallery-animated-gif-support.php 7 months ago class-foogallery-attachment-custom-class.php 7 months ago class-foogallery-attachment-type.php 7 months ago class-foogallery-attachment.php 7 months ago class-foogallery-cache.php 7 months ago class-foogallery-common-fields.php 7 months ago class-foogallery-crop-position.php 7 months ago class-foogallery-datasource-media_library.php 7 months ago class-foogallery-debug.php 7 months ago class-foogallery-extensions-compatibility.php 7 months ago class-foogallery-force-https.php 7 months ago class-foogallery-lazyload.php 7 months ago class-foogallery-lightbox.php 7 months ago class-foogallery-paging.php 7 months ago class-foogallery-password-protect.php 7 months ago class-foogallery-sitemaps.php 7 months ago class-foogallery-widget.php 7 months ago class-foogallery.php 7 months ago class-gallery-advanced-settings.php 7 months ago class-il8n.php 7 months ago class-override-thumbnail.php 7 months ago class-posttypes.php 7 months ago class-retina.php 7 months ago class-thumbnail-dimensions.php 7 months ago class-thumbnails.php 7 months ago class-version-check.php 7 months ago constants.php 7 months ago functions.php 7 months ago includes.php 7 months ago index.php 11 years ago render-functions.php 7 months ago
class-posttypes.php
204 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
39 /**
40 * Registers the custom post type for galleries.
41 *
42 * This function is responsible for registering the custom post type 'gallery' used by the FooGallery plugin.
43 * It now includes custom capabilities and adds filters for custom capability mapping and menu visibility control.
44 */
45 function register() {
46
47 $args = array(
48 'labels' => array(
49 'name' => __( 'Galleries', 'foogallery' ),
50 'singular_name' => __( 'Gallery', 'foogallery' ),
51 'add_new' => __( 'Add Gallery', 'foogallery' ),
52 'add_new_item' => __( 'Add New Gallery', 'foogallery' ),
53 'edit_item' => __( 'Edit Gallery', 'foogallery' ),
54 'new_item' => __( 'New Gallery', 'foogallery' ),
55 'view_item' => __( 'View Gallery', 'foogallery' ),
56 'search_items' => __( 'Search Galleries', 'foogallery' ),
57 'not_found' => __( 'No Galleries found', 'foogallery' ),
58 'not_found_in_trash' => __( 'No Galleries found in Trash', 'foogallery' ),
59 'menu_name' => foogallery_plugin_name(),
60 'all_items' => __( 'Galleries', 'foogallery' ),
61 ),
62 'hierarchical' => false,
63 'public' => false, // set to false to make the post type private
64 'rewrite' => false,
65 'show_ui' => true,
66 'show_in_menu' => true,
67 'menu_icon' => 'dashicons-format-gallery',
68 'supports' => array( 'title', 'thumbnail' ),
69 'capabilities' => FooGallery_PostTypes::GALLERY_CAPABILITIES
70 );
71
72 $args = apply_filters( 'foogallery_gallery_posttype_register_args', $args );
73 register_post_type( FOOGALLERY_CPT_GALLERY, $args );
74 }
75
76 /**
77 * Adds capabilities to the allowed roles, based on the gallery creator role that is set.
78 *
79 * @return void
80 */
81 function add_capabilities( $force = false ) {
82 global $foogallery_adding_capabilities;
83
84 $gallery_creator_role = foogallery_setting_gallery_creator_role();
85 $previous_capabilities = get_option('foogallery_capabilities_set' );
86
87 if ( $force || $gallery_creator_role !== $previous_capabilities ) {
88
89 $foogallery_adding_capabilities = true;
90 update_option( 'foogallery_capabilities_set', $gallery_creator_role );
91 $foogallery_adding_capabilities = false;
92
93 // Get the roles
94 $roles = foogallery_get_roles_and_higher( $gallery_creator_role );
95
96 foreach ( $roles as $the_role ) {
97 $role = get_role( $the_role );
98
99 if ( !is_null( $role ) ) {
100
101 foreach ( FooGallery_PostTypes::GALLERY_CAPABILITIES as $cap_key => $cap ) {
102 $role->add_cap( $cap );
103 }
104 }
105 }
106 }
107 }
108
109 /**
110 * Clears the capabilities based on the new value, old value, and option.
111 *
112 * @param mixed $old_value The old value.
113 * @param mixed $value The new value.
114 * @param string $option The option.
115 */
116 function clear_capabilities( $old_value, $value, $option ) {
117 global $foogallery_adding_capabilities;
118 // Get out early, if we are busy updating capabilities.
119 if ( $foogallery_adding_capabilities ) {
120 return;
121 }
122
123 if ( $old_value === $value ) {
124 return;
125 }
126
127 $gallery_creator_role = foogallery_setting_gallery_creator_role();
128 $previous_capabilities = get_option('foogallery_capabilities_set' );
129
130 if ( $gallery_creator_role !== $previous_capabilities ) {
131
132 // Get all roles
133 $roles = wp_roles()->get_names();
134
135 // Loop through each role and remove the capabilities
136 foreach ( $roles as $role => $name ) {
137 $role_obj = get_role($role);
138 if (!is_null($role_obj)) {
139 foreach ( FooGallery_PostTypes::GALLERY_CAPABILITIES as $cap_key => $cap ) {
140 $role_obj->remove_cap($cap);
141 }
142 }
143 }
144
145 do_action('foogallery_gallery_posttype_clear_capabilities');
146 $this->add_capabilities( true );
147 }
148 }
149
150 /**
151 * Customize the update messages for a gallery.
152 *
153 * @global object $post The current post object.
154 *
155 * @param array $messages Array of default post updated messages.
156 *
157 * @return array $messages Amended array of post updated messages.
158 */
159 public function update_messages( $messages ) {
160 global $post;
161
162 // Add our gallery messages.
163 $messages[FOOGALLERY_CPT_GALLERY] = apply_filters( 'foogallery_gallery_posttype_update_messages',
164 array(
165 0 => '',
166 1 => __( 'Gallery updated.', 'foogallery' ),
167 2 => __( 'Gallery custom field updated.', 'foogallery' ),
168 3 => __( 'Gallery custom field deleted.', 'foogallery' ),
169 4 => __( 'Gallery updated.', 'foogallery' ),
170 5 => isset($_GET['revision']) ? sprintf( __( 'Gallery restored to revision from %s.', 'foogallery' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
171 6 => __( 'Gallery published.', 'foogallery' ),
172 7 => __( 'Gallery saved.', 'foogallery' ),
173 8 => __( 'Gallery submitted.', 'foogallery' ),
174 9 => sprintf( __( 'Gallery scheduled for: <strong>%1$s</strong>.', 'foogallery' ), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) ),
175 10 => __( 'Gallery draft updated.', 'foogallery' )
176 )
177 );
178
179 return $messages;
180 }
181
182 /**
183 * Customize the bulk update messages for a gallery
184 *
185 * @param array $bulk_messages Array of default bulk updated messages.
186 * @param array $bulk_counts Array containing count of posts involved in the action.
187 *
188 * @return array mixed Amended array of bulk updated messages.
189 */
190 function update_bulk_messages( $bulk_messages, $bulk_counts ) {
191 $bulk_messages[FOOGALLERY_CPT_GALLERY] = apply_filters( 'foogallery_gallery_posttype_bulk_update_messages',
192 array(
193 'updated' => _n( '%s Gallery updated.', '%s Galleries updated.', $bulk_counts['updated'], 'foogallery' ),
194 'locked' => _n( '%s Gallery not updated, somebody is editing it.', '%s Galleries not updated, somebody is editing them.', $bulk_counts['locked'], 'foogallery' ),
195 'deleted' => _n( '%s Gallery permanently deleted.', '%s Galleries permanently deleted.', $bulk_counts['deleted'], 'foogallery' ),
196 'trashed' => _n( '%s Gallery moved to the Trash.', '%s Galleries moved to the Trash.', $bulk_counts['trashed'], 'foogallery' ),
197 'untrashed' => _n( '%s Gallery restored from the Trash.', '%s Galleries restored from the Trash.', $bulk_counts['untrashed'], 'foogallery' ),
198 )
199 );
200
201 return $bulk_messages;
202 }
203 }
204 }