PluginProbe
WP Ultimate Post Grid / 2.2
WP Ultimate Post Grid v2.2
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 / post_save.php

post_save.php in WP Ultimate Post Grid 2.2, at helpers/post_save.php

47 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class WPUPG_Post_Save {
4
5 public function __construct()
6 {
7 add_action( 'save_post', array( $this, 'save' ), 10, 2 );
8 add_action( 'edit_attachment', array( $this, 'save_attachment' ) );
9 }
10
11 public function save_attachment( $post_id )
12 {
13 $post = get_post( $post_id );
14 $this->save( $post_id, $post );
15 }
16
17 public function save( $post_id, $post )
18 {
19 if( $post->post_type != WPUPG_POST_TYPE )
20 {
21 if ( !isset( $_POST['wpupg_nonce'] ) || !wp_verify_nonce( $_POST['wpupg_nonce'], 'grid' ) ) {
22 return;
23 }
24
25 // Basic metadata
26 $fields = array(
27 'wpupg_custom_link',
28 'wpupg_custom_link_behaviour',
29 'wpupg_custom_image',
30 'wpupg_custom_image_id',
31 );
32
33 foreach ( $fields as $field )
34 {
35 $old = get_post_meta( $post_id, $field, true );
36 $new = isset( $_POST[$field] ) ? $_POST[$field] : null;
37
38 // Update or delete meta data if changed
39 if( isset( $new ) && $new != $old ) {
40 update_post_meta( $post_id, $field, $new );
41 } elseif ( $new == '' && $old ) {
42 delete_post_meta( $post_id, $field, $old );
43 }
44 }
45 }
46 }
47 }