pmpro_page_save

The Paid Memberships Pro pmpro page save function.

Description

pmpro_page_save( $post_id ); 

Parameters (1)

0. $post_id
The post id.

Usage

  1. if ( !function_exists( 'pmpro_page_save' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/metaboxes.php'; 
  3.  
  4. // The post id. 
  5. $post_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = pmpro_page_save($post_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/metaboxes.php  
  1. function pmpro_page_save($post_id) 
  2. global $wpdb; 
  3.  
  4. if(empty($post_id)) 
  5. return false; 
  6.  
  7. if (!empty($_POST['pmpro_noncename']) && !wp_verify_nonce( $_POST['pmpro_noncename'], plugin_basename(__FILE__) )) { 
  8. return $post_id; 
  9.  
  10. // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want 
  11. // to do anything 
  12. if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
  13. return $post_id; 
  14.  
  15. // Check permissions 
  16. if(!empty($_POST['post_type']) && 'page' == $_POST['post_type'] ) 
  17. if ( !current_user_can( 'edit_page', $post_id ) ) 
  18. return $post_id; 
  19. else 
  20. if ( !current_user_can( 'edit_post', $post_id ) ) 
  21. return $post_id; 
  22.  
  23. // OK, we're authenticated: we need to find and save the data  
  24. if(isset($_POST['pmpro_noncename'])) 
  25. if(!empty($_POST['page_levels'])) 
  26. $mydata = $_POST['page_levels']; 
  27. else 
  28. $mydata = NULL; 
  29.  
  30. //remove all memberships for this page 
  31. $wpdb->query("DELETE FROM {$wpdb->pmpro_memberships_pages} WHERE page_id = '$post_id'"); 
  32.  
  33. //add new memberships for this page 
  34. if(is_array($mydata)) 
  35. foreach($mydata as $level) 
  36. $wpdb->query("INSERT INTO {$wpdb->pmpro_memberships_pages} (membership_id, page_id) VALUES('" . intval($level) . "', '" . intval($post_id) . "')"); 
  37.  
  38. return $mydata; 
  39. else 
  40. return $post_id;