PluginProbe
WP Ultimate Post Grid / 2.7.0
WP Ultimate Post Grid v2.7.0
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 / helpers / grid_save.php

grid_save.php in WP Ultimate Post Grid 2.7.0, at helpers/grid_save.php

170 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class WPUPG_Grid_Save {
4
5 public function __construct()
6 {
7 add_action( 'save_post', array( $this, 'save' ), 10, 2 );
8 }
9
10 public function save( $post_id, $post )
11 {
12 if( $post->post_type == WPUPG_POST_TYPE )
13 {
14 if ( !isset( $_POST['wpupg_nonce'] ) || !wp_verify_nonce( $_POST['wpupg_nonce'], 'grid' ) ) {
15 return;
16 }
17
18 $grid = new WPUPG_Grid( $post_id );
19
20 // Basic metadata
21 $fields = $grid->fields();
22
23 foreach ( $fields as $field )
24 {
25 $old = get_post_meta( $post_id, $field, true );
26 $new = isset( $_POST[$field] ) ? $_POST[$field] : null;
27
28 // Field specific adjustments
29 if( isset( $new ) && $field == 'wpupg_post_types' ) {
30 $new = array( $new );
31 }
32
33 if( isset( $new ) && $field == 'wpupg_taxonomies' ) {
34 $new = array( $new );
35 }
36
37 // Update or delete meta data if changed
38 if( isset( $new ) && $new != $old ) {
39 update_post_meta( $post_id, $field, $new );
40 } elseif ( $new == '' && $old ) {
41 delete_post_meta( $post_id, $field, $old );
42 }
43 }
44
45 // Limit terms
46 if( isset( $_POST['wpupg_limit_terms'] ) && $_POST['wpupg_limit_terms'] ) {
47 $taxonomy = isset( $_POST['wpupg_taxonomies'] ) ? $_POST['wpupg_taxonomies'] : false;
48
49 if ( $taxonomy ) {
50 $limit_terms_terms = isset( $_POST['wpupg_form_limit_terms_' . $taxonomy . '_terms'] ) ? $_POST['wpupg_form_limit_terms_' . $taxonomy . '_terms'] : array();
51 $limit_terms_type = isset( $_POST['wpupg_form_limit_terms_' . $taxonomy . '_type'] ) ? $_POST['wpupg_form_limit_terms_' . $taxonomy . '_type'] : 'restrict';
52
53 update_post_meta( $post_id, 'wpupg_limit_terms_terms', $limit_terms_terms );
54 update_post_meta( $post_id, 'wpupg_limit_terms_type', $limit_terms_type );
55 }
56 }
57
58 // Limit rules
59
60 $limit_rules = array();
61
62 if( isset( $_POST['wpupg_limit_posts_rule'] ) ) {
63 foreach( $_POST['wpupg_limit_posts_rule'] as $id => $limit_rule ) {
64 if($id != 0) {
65 $field = $limit_rule['field'];
66 $type = $limit_rule['type'];
67
68 $field_parts = explode( '|', $field );
69 $values_name = 'values_' . $field_parts[0] . '_' . $field_parts[1];
70
71 if( isset( $limit_rule[$values_name] ) && $limit_rule[$values_name] ) {
72 $values = $limit_rule[$values_name];
73
74 if( !is_array( $values ) ) $values = explode( ';', $values );
75
76 $limit_rules[] = array(
77 'field' => $field,
78 'post_type' => $field_parts[0],
79 'taxonomy' => $field_parts[1],
80 'values' => $values,
81 'type' => $type,
82 );
83 }
84 }
85 }
86 }
87
88 update_post_meta( $post_id, 'wpupg_limit_rules', $limit_rules );
89
90 // Filter Taxonomies
91 $post_type = $_POST['wpupg_post_types'];
92
93 if( isset( $_POST['wpupg_filter_taxonomy_' . $post_type] ) ) {
94 $filter_taxonomies = $_POST['wpupg_filter_taxonomy_' . $post_type];
95 update_post_meta( $post_id, 'wpupg_filter_taxonomies', $filter_taxonomies );
96 }
97
98 // Filter Limit Terms
99 $filter_limit_terms = array();
100 if( isset( $filter_taxonomies ) ) {
101 foreach( $filter_taxonomies as $filter_taxonomy ) {
102 if( isset( $_POST['wpupg_filter_limit_terms_' . $filter_taxonomy] ) ) {
103 $filter_limit_terms[$filter_taxonomy] = $_POST['wpupg_filter_limit_terms_' . $filter_taxonomy];
104 }
105 }
106 }
107 update_post_meta( $post_id, 'wpupg_filter_limit_terms', $filter_limit_terms );
108
109 // Filter Dropdown Labels
110 $filter_dropdown_labels = array();
111 if( isset( $filter_taxonomies ) ) {
112 foreach( $filter_taxonomies as $filter_taxonomy ) {
113 if( isset( $_POST['wpupg_filter_dropdown_label_' . $filter_taxonomy] ) ) {
114 $filter_dropdown_labels[$filter_taxonomy] = $_POST['wpupg_filter_dropdown_label_' . $filter_taxonomy];
115 }
116 }
117 }
118 update_post_meta( $post_id, 'wpupg_filter_dropdown_labels', $filter_dropdown_labels );
119
120 // Filter style metadata
121 $styles = $grid->filter_style_fields();
122 $filter_style = array();
123
124 foreach( $styles as $style => $fields ) {
125 $filter_style[$style] = array();
126
127 foreach( $fields as $field => $default ) {
128 $field_name = 'wpupg_' . $style . '_filter_style_' . $field;
129 if( isset( $_POST[$field_name] ) ) {
130 $filter_style[$style][$field] = $_POST[$field_name];
131 }
132 }
133 }
134
135 update_post_meta( $post_id, 'wpupg_filter_style', $filter_style );
136
137 // Pagination metadata
138 $pagination_fields = $grid->pagination_fields();
139 $pagination = array();
140
141 foreach( $pagination_fields as $type => $fields ) {
142 $pagination[$type] = array();
143
144 foreach( $fields as $field => $default ) {
145 $field_name = 'wpupg_pagination_' . $type . '_' . $field;
146 if( isset( $_POST[$field_name] ) ) {
147 $pagination[$type][$field] = $_POST[$field_name];
148 }
149 }
150 }
151
152 update_post_meta( $post_id, 'wpupg_pagination', $pagination );
153
154 // Pagination style metadata
155 $pagination_style_fields = $grid->pagination_style_fields();
156 $pagination_style = array();
157
158 foreach( $pagination_style_fields as $field => $default ) {
159 $field_name = 'wpupg_pagination_style_' . $field;
160 if( isset( $_POST[$field_name] ) ) {
161 $pagination_style[$field] = $_POST[$field_name];
162 }
163 }
164
165 update_post_meta( $post_id, 'wpupg_pagination_style', $pagination_style );
166
167 // Cache gets automatically generated in WPUPG_Grid_Cache
168 }
169 }
170 }