PluginProbe
WP Ultimate Post Grid / 2.3
WP Ultimate Post Grid v2.3
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.3, at helpers/grid_save.php

157 lines 5.9 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 rules
46
47 $limit_rules = array();
48
49 if( isset( $_POST['wpupg_limit_posts_rule'] ) ) {
50 foreach( $_POST['wpupg_limit_posts_rule'] as $id => $limit_rule ) {
51 if($id != 0) {
52 $field = $limit_rule['field'];
53 $type = $limit_rule['type'];
54
55 $field_parts = explode( '|', $field );
56 $values_name = 'values_' . $field_parts[0] . '_' . $field_parts[1];
57
58 if( isset( $limit_rule[$values_name] ) && $limit_rule[$values_name] ) {
59 $values = $limit_rule[$values_name];
60
61 if( !is_array( $values ) ) $values = explode( ';', $values );
62
63 $limit_rules[] = array(
64 'field' => $field,
65 'post_type' => $field_parts[0],
66 'taxonomy' => $field_parts[1],
67 'values' => $values,
68 'type' => $type,
69 );
70 }
71 }
72 }
73 }
74
75 update_post_meta( $post_id, 'wpupg_limit_rules', $limit_rules );
76
77 // Filter Taxonomies
78 $post_type = $_POST['wpupg_post_types'];
79
80 if( isset( $_POST['wpupg_filter_taxonomy_' . $post_type] ) ) {
81 $filter_taxonomies = $_POST['wpupg_filter_taxonomy_' . $post_type];
82 update_post_meta( $post_id, 'wpupg_filter_taxonomies', $filter_taxonomies );
83 }
84
85 // Filter Limit Terms
86 $filter_limit_terms = array();
87 if( isset( $filter_taxonomies ) ) {
88 foreach( $filter_taxonomies as $filter_taxonomy ) {
89 if( isset( $_POST['wpupg_filter_limit_terms_' . $filter_taxonomy] ) ) {
90 $filter_limit_terms[$filter_taxonomy] = $_POST['wpupg_filter_limit_terms_' . $filter_taxonomy];
91 }
92 }
93 }
94 update_post_meta( $post_id, 'wpupg_filter_limit_terms', $filter_limit_terms );
95
96 // Filter Dropdown Labels
97 $filter_dropdown_labels = array();
98 if( isset( $filter_taxonomies ) ) {
99 foreach( $filter_taxonomies as $filter_taxonomy ) {
100 if( isset( $_POST['wpupg_filter_dropdown_label_' . $filter_taxonomy] ) ) {
101 $filter_dropdown_labels[$filter_taxonomy] = $_POST['wpupg_filter_dropdown_label_' . $filter_taxonomy];
102 }
103 }
104 }
105 update_post_meta( $post_id, 'wpupg_filter_dropdown_labels', $filter_dropdown_labels );
106
107 // Filter style metadata
108 $styles = $grid->filter_style_fields();
109 $filter_style = array();
110
111 foreach( $styles as $style => $fields ) {
112 $filter_style[$style] = array();
113
114 foreach( $fields as $field => $default ) {
115 $field_name = 'wpupg_' . $style . '_filter_style_' . $field;
116 if( isset( $_POST[$field_name] ) ) {
117 $filter_style[$style][$field] = $_POST[$field_name];
118 }
119 }
120 }
121
122 update_post_meta( $post_id, 'wpupg_filter_style', $filter_style );
123
124 // Pagination metadata
125 $pagination_fields = $grid->pagination_fields();
126 $pagination = array();
127
128 foreach( $pagination_fields as $type => $fields ) {
129 $pagination[$type] = array();
130
131 foreach( $fields as $field => $default ) {
132 $field_name = 'wpupg_pagination_' . $type . '_' . $field;
133 if( isset( $_POST[$field_name] ) ) {
134 $pagination[$type][$field] = $_POST[$field_name];
135 }
136 }
137 }
138
139 update_post_meta( $post_id, 'wpupg_pagination', $pagination );
140
141 // Pagination style metadata
142 $pagination_style_fields = $grid->pagination_style_fields();
143 $pagination_style = array();
144
145 foreach( $pagination_style_fields as $field => $default ) {
146 $field_name = 'wpupg_pagination_style_' . $field;
147 if( isset( $_POST[$field_name] ) ) {
148 $pagination_style[$field] = $_POST[$field_name];
149 }
150 }
151
152 update_post_meta( $post_id, 'wpupg_pagination_style', $pagination_style );
153
154 // Cache gets automatically generated in WPUPG_Grid_Cache
155 }
156 }
157 }