PluginProbe
WP Ultimate Post Grid / 4.0.1
WP Ultimate Post Grid v4.0.1
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / includes / public / class-wpupg-grid-saver.php

class-wpupg-grid-saver.php in WP Ultimate Post Grid 4.0.1, at includes/public/class-wpupg-grid-saver.php

145 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Responsible for saving grids.
4 *
5 * @link https://bootstrapped.ventures
6 * @since 3.0.0
7 *
8 * @package WP_Ultimate_Post_Grid
9 * @subpackage WP_Ultimate_Post_Grid/includes/admin
10 */
11
12 /**
13 * Responsible for saving grids.
14 *
15 * @since 3.0.0
16 * @package WP_Ultimate_Post_Grid
17 * @subpackage WP_Ultimate_Post_Grid/includes/admin
18 * @author Brecht Vandersmissen <[email protected]>
19 */
20 class WPUPG_Grid_Saver {
21 /**
22 * Create a new grid.
23 *
24 * @since 3.0.0
25 * @param array $grid Grid fields to save.
26 */
27 public static function create_grid( $grid ) {
28 $post = array(
29 'post_type' => WPUPG_POST_TYPE,
30 'post_status' => 'publish',
31 );
32
33 $grid_id = wp_insert_post( $post );
34 WPUPG_Grid_Saver::update_grid( $grid_id, $grid );
35
36 return $grid_id;
37 }
38
39 /**
40 * Save grid fields.
41 *
42 * @since 3.0.0
43 * @param int $id Post ID of the grid.
44 * @param array $grid Grid fields to save.
45 */
46 public static function update_grid( $id, $grid ) {
47 $meta = array();
48
49 // Meta Fields.
50 $allowed_meta = array(
51 'version',
52 // General.
53 // Data Source.
54 'type',
55 'post_types',
56 'post_status',
57 'post_status_require_permission',
58 'taxonomies',
59 'password_protected',
60 'language',
61 'order_by',
62 'order',
63 'order_custom_key',
64 'order_custom_key_numeric',
65 'terms_order',
66 'terms_order_by',
67 // Limit Items.
68 'limit_posts_offset',
69 'limit_posts_number',
70 'images_only',
71 'terms_images_only',
72 'terms_hide_empty',
73 'limit_terms',
74 'limit_terms_terms',
75 'limit_terms_type',
76 'limit_posts',
77 'limit_rules',
78 // Filters.
79 'filters_enabled',
80 'filters',
81 'filters_style',
82 'filters_relation',
83 'filters_no_selection',
84 'responsive_toggle_style',
85 'responsive_toggle_style_closed',
86 'responsive_toggle_style_open',
87 // Layout.
88 'layout_mode',
89 'centered',
90 'rtl_mode',
91 'layout_desktop_sizing',
92 'layout_desktop_sizing_columns',
93 'layout_desktop_sizing_fixed',
94 'layout_desktop_sizing_margin',
95 'layout_tablet_different',
96 'layout_tablet_sizing',
97 'layout_tablet_sizing_columns',
98 'layout_tablet_sizing_fixed',
99 'layout_tablet_sizing_margin',
100 'layout_mobile_different',
101 'layout_mobile_sizing',
102 'layout_mobile_sizing_columns',
103 'layout_mobile_sizing_fixed',
104 'layout_mobile_sizing_margin',
105 // Template.
106 'template',
107 'use_image',
108 'link',
109 'link_type',
110 'link_target',
111 // Pagination.
112 'pagination_type',
113 'pagination',
114 // Other.
115 'metadata',
116 'metadata_name',
117 'metadata_description',
118 'deeplinking',
119 'deeplinking_jump',
120 'empty_message',
121 );
122
123 foreach ( $allowed_meta as $field ) {
124 if ( isset( $grid[ $field ] ) ) {
125 $meta[ 'wpupg_' . $field ] = $grid[ $field ];
126 }
127 }
128
129 $meta = apply_filters( 'wpupg_grid_save_meta', $meta, $id, $grid );
130
131 // Post Fields.
132 $post = array(
133 'ID' => $id,
134 'post_status' => 'publish',
135 'meta_input' => $meta,
136 );
137
138 if ( isset( $grid['name'] ) ) { $post['post_title'] = $grid['name']; }
139 if ( isset( $grid['slug'] ) ) { $post['post_name'] = $grid['slug']; }
140
141 WPUPG_Grid_Manager::invalidate_grid( $id );
142 wp_update_post( $post );
143 }
144 }
145