PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / trunk
Responsive Lightbox & Gallery vtrunk
2.7.8 trunk 1.0.0 1.0.1 1.0.1.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.0.1 1.4.1 1.4.11 1.4.12 1.4.13 1.4.14 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3.1 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7
responsive-lightbox / includes / galleries / trait-gallery-preview.php
responsive-lightbox / includes / galleries Last commit date
class-gallery-api.php 4 months ago class-gallery-base.php 4 months ago class-gallery-config.php 4 months ago class-gallery-design.php 4 months ago class-gallery-field-provider.php 4 months ago class-gallery-images.php 4 months ago class-gallery-lightbox.php 4 months ago class-gallery-misc.php 4 months ago class-gallery-paging.php 4 months ago trait-gallery-ajax.php 4 months ago trait-gallery-duplicate.php 4 months ago trait-gallery-image-methods.php 2 weeks ago trait-gallery-preview.php 4 months ago trait-gallery-sanitize.php 4 months ago
trait-gallery-preview.php
121 lines
1 <?php
2 // exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) )
4 exit;
5
6 /**
7 * Responsive Lightbox Gallery Preview & Revision Trait.
8 *
9 * Handles gallery preview and revision functionality.
10 *
11 * @trait Responsive_Lightbox_Gallery_Preview
12 */
13 trait Responsive_Lightbox_Gallery_Preview {
14
15 /**
16 * Save gallery revision metadata.
17 *
18 * @param int $revision_id
19 * @return void
20 */
21 public function save_revision( $revision_id ) {
22 // get revision
23 $revision = get_post( $revision_id );
24
25 // get gallery ID
26 $post_id = $revision->post_parent;
27
28 // is it rl gallery?
29 if ( get_post_type( $post_id ) !== 'rl_gallery' )
30 return;
31
32 $this->revision_id = $revision_id;
33
34 if ( ! wp_is_post_revision( $revision_id ) || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || empty( $_POST['rl_gallery'] ) )
35 return;
36
37 // save revisioned meta data
38 $this->save_gallery( wp_unslash( $_POST ), $revision_id, true );
39 }
40
41 /**
42 * Update preview link.
43 *
44 * @param string $link Preview link
45 * @return string
46 */
47 public function preview_post_link( $link ) {
48 // add gallery revision id
49 if ( property_exists( $this, 'revision_id' ) && ! is_null( $this->revision_id ) ) {
50 $post_id = wp_get_post_parent_id( $this->revision_id );
51
52 // is it valid rl_gallery post?
53 if ( $post_id && get_post_type( $post_id ) === 'rl_gallery' )
54 return add_query_arg( 'rl_gallery_revision_id', $this->revision_id, $link );
55 }
56
57 return $link;
58 }
59
60 /**
61 * Delete gallery revision at shutdown.
62 *
63 * @global object $post
64 *
65 * @return void
66 */
67 public function shutdown_preview() {
68 // is it a frontend preview?
69 if ( is_preview() && isset( $_GET['rl_gallery_revision_id'] ) ) {
70 global $post;
71
72 // cast revision ID
73 $revision_id = (int) $_GET['rl_gallery_revision_id'];
74
75 // is it a valid revision?
76 if ( get_post_type( $post->ID ) === 'rl_gallery' && wp_is_post_revision( $revision_id ) === (int) $post->ID )
77 wp_delete_post_revision( $revision_id );
78 }
79 }
80
81 /**
82 * Filter gallery meta data needed for frontend gallery preview.
83 *
84 * @param mixed $value Meta value to filter
85 * @param int $object_id
86 * @param string $meta_key Meta key to filter a value for
87 * @param bool $single Whether to return a single value
88 * @return mixed
89 */
90 public function filter_preview_metadata( $value, $object_id, $meta_key, $single ) {
91 // ignore other post types
92 if ( get_post_type( $object_id ) !== 'rl_gallery' )
93 return $value;
94
95 // get current post
96 $post = get_post();
97
98 // prepare keys
99 $keys = array( '_rl_featured_image_type', '_rl_featured_image', '_rl_images_count', '_thumbnail_id' );
100
101 // add other metakeys
102 foreach ( array_keys( $this->tabs ) as $key ) {
103 $keys[] = '_rl_' . $key;
104 }
105
106 // restrict only to specified data
107 if ( empty( $post ) || (int) $post->ID !== (int) $object_id || ! in_array( $meta_key, $keys, true ) || $post->post_type === 'revision' )
108 return $value;
109
110 // grab the last autosave
111 $preview = wp_get_post_autosave( $post->ID );
112
113 // invalid revision?
114 if ( ! is_object( $preview ) )
115 return $value;
116
117 // finally replace metadata
118 return array( get_post_meta( $preview->ID, $meta_key, $single ) );
119 }
120 }
121