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 / admin / class-demo-content.php
foogallery / includes / admin Last commit date
class-admin-notice-custom-css.php 4 weeks ago class-admin-notices.php 4 weeks ago class-admin.php 4 weeks ago class-attachment-fields.php 4 weeks ago class-columns.php 4 weeks ago class-demo-content.php 4 weeks ago class-extensions.php 4 weeks ago class-gallery-attachment-modal.php 4 weeks ago class-gallery-datasources.php 4 weeks ago class-gallery-editor.php 4 weeks ago class-gallery-metabox-fields.php 4 weeks ago class-gallery-metabox-items.php 4 weeks ago class-gallery-metabox-settings-helper.php 4 weeks ago class-gallery-metabox-settings.php 4 weeks ago class-gallery-metabox-template.php 4 weeks ago class-gallery-metaboxes.php 4 weeks ago class-menu.php 4 weeks ago class-pro-promotion.php 4 weeks ago class-settings.php 4 weeks ago class-silent-installer-skin.php 4 weeks ago class-trial-mode.php 4 weeks ago demo-content-galleries.php 4 weeks ago demo-content-images.php 4 weeks ago index.php 4 weeks ago pro-features.php 4 weeks ago view-features.php 4 weeks ago view-help-demos.php 4 weeks ago view-help-getting-started.php 4 weeks ago view-help-pro.php 4 weeks ago view-help.php 4 weeks ago view-system-info.php 4 weeks ago
class-demo-content.php
157 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /*
8 * FooGallery Admin Demo Content class
9 */
10
11 if ( ! class_exists( 'FooGallery_Admin_Demo_Content' ) ) {
12
13 class FooGallery_Admin_Demo_Content {
14
15 /**
16 * Import attachments and galleries
17 *
18 * @return int[]
19 */
20 function import_demo_content() {
21 //import all the images first, so that we can get attachment ID's
22 $image_data = include( FOOGALLERY_PATH . 'includes/admin/demo-content-images.php' );
23
24 $images_imported = 0;
25 $attachment_mappings = array();
26
27 foreach ( $image_data as $attachment_data ) {
28 $result = $this->import_attachment( $attachment_data );
29 if ( $result !== false ) {
30 if ( $result['imported'] ) {
31 $images_imported++;
32 }
33 $attachment_mappings[ $result['key'] ] = intval( $result['attachment_id'] );
34 }
35 }
36
37 $gallery_data = include( FOOGALLERY_PATH . 'includes/admin/demo-content-galleries.php' );
38
39 $galleries_imported = 0;
40
41 foreach ( $gallery_data as $post_data ) {
42 //create the post
43 $result = $this->import_gallery( $post_data, $attachment_mappings );
44 if ( $result !== false ) {
45 if ( $result['imported'] ) {
46 $galleries_imported++;
47 }
48 }
49 }
50
51 return array(
52 'attachments' => $images_imported,
53 'galleries' => $galleries_imported
54 );
55 }
56
57 function import_gallery( $gallery_data, $attachment_mappings ) {
58 $imported_galleries = get_option( FOOGALLERY_OPTION_DEMO_CONTENT_GALLERIES, array() );
59
60 $key = $gallery_data['key'];
61
62 //check to see if the gallery has already been imported
63 if ( array_key_exists( $key, $imported_galleries ) ) {
64 $gallery_id = $imported_galleries[ $key ];
65 //check that the gallery actually exists
66 if ( get_post_status ( $gallery_id ) ) {
67 return array(
68 'id' => $gallery_id,
69 'imported' => false
70 );
71 }
72 }
73
74 $items = $gallery_data['items'];
75 unset( $gallery_data['items'] );
76 unset( $gallery_data['key'] );
77
78 $gallery_id = wp_insert_post( $gallery_data, true );
79 $imported = true;
80
81 if ( !is_wp_error( $gallery_id ) ) {
82
83 if ( $imported ) {
84 //save the gallery to options so we can delete easily it later
85 $imported_galleries = get_option( FOOGALLERY_OPTION_DEMO_CONTENT_GALLERIES, array() );
86 $imported_galleries[ $key ] = $gallery_id;
87 update_option( FOOGALLERY_OPTION_DEMO_CONTENT_GALLERIES, $imported_galleries );
88 }
89
90 $attachments = array();
91
92 //get the attachment ID's and set the attachment metadata
93 foreach ( $items as $item ) {
94 if ( array_key_exists( $item, $attachment_mappings ) ) {
95 $attachments[] = $attachment_mappings[ $item ];
96 }
97 }
98
99 update_post_meta( $gallery_id, FOOGALLERY_META_ATTACHMENTS, $attachments );
100
101 return array(
102 'id' => $gallery_id,
103 'imported' => $imported
104 );
105 }
106
107 return false;
108 }
109
110 /**
111 * Import an attachment into the media library
112 *
113 * @param $attachment_data
114 *
115 * @return array|bool
116 */
117 function import_attachment( $attachment_data ) {
118
119 $imported_attachments = get_option( FOOGALLERY_OPTION_DEMO_CONTENT_ATTACHMENTS, array() );
120
121 //check to see if the image has already been imported
122 if ( array_key_exists( $attachment_data['key'], $imported_attachments ) ) {
123 $attachment_id = $imported_attachments[ $attachment_data['key'] ];
124 //check that the attachment actually exists
125 if ( get_post_status ( $attachment_id ) ) {
126 return array(
127 'key' => $attachment_data['key'],
128 'attachment_id' => $attachment_id,
129 'imported' => false
130 );
131 }
132 }
133
134 $attachment_id = foogallery_import_attachment( $attachment_data );
135
136 if ( ! is_wp_error( $attachment_id ) && intval( $attachment_id ) > 0 ) {
137
138 $imported_attachments[ $attachment_data['key'] ] = $attachment_id;
139
140 update_option( FOOGALLERY_OPTION_DEMO_CONTENT_ATTACHMENTS, $imported_attachments );
141
142 return array(
143 'key' => $attachment_data['key'],
144 'attachment_id' => $attachment_id,
145 'imported' => true,
146 );
147 }
148
149 return array(
150 'key' => $attachment_data['key'],
151 'attachment_id' => false,
152 'imported' => false,
153 );
154 }
155 }
156 }
157