/**
  * Save relations when save object.
  *
  * @param string $post_ID
  * @param object $post
  * @return boolean
  * @author Amaury Balmer
  */
 public static function save_post($post_ID = 0, $post = null)
 {
     // Don't do anything when autosave
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return false;
     }
     // Save only when relation post type is called before.
     if (!isset($_POST['post-relation-post-types']) || $_POST['post-relation-post-types'] != 1) {
         return false;
     }
     // Get current post object
     if (!isset($post) || is_null($post)) {
         $post = get_post($post_ID);
     }
     // Take post type from arg !
     $post_type = $post->post_type;
     // Prepare admin type for each relations box !
     $current_options = get_option(RPT_OPTION);
     // All tag-style post taxonomies
     foreach ((array) $current_options as $current_post_type => $_post_types) {
         foreach ((array) $_post_types as $_post_type) {
             if ($_post_type != $post_type) {
                 continue;
             }
             if (isset($_POST['action']) && !isset($_POST['relations'][$current_post_type])) {
                 rpt_delete_object_relation($post_ID, array($current_post_type));
             } elseif (isset($_POST['relations'][$current_post_type])) {
                 // Secure datas
                 if (is_array($_POST['relations'][$current_post_type])) {
                     $_POST['relations'][$current_post_type] = array_map('intval', $_POST['relations'][$current_post_type]);
                     $_POST['relations'][$current_post_type] = array_unique($_POST['relations'][$current_post_type]);
                 } else {
                     $_POST['relations'][$current_post_type] = (int) $_POST['relations'][$current_post_type];
                 }
                 rpt_set_object_relation($post_ID, $_POST['relations'][$current_post_type], $current_post_type, false);
             }
         }
     }
     return true;
 }
Example #2
0
 function save($values, $args)
 {
     if (isset($values['name'])) {
         $values = $values['name'];
     }
     if (empty($values)) {
         rpt_delete_object_relation($args['post_id'], array($this->post_type));
     }
     // Secure datas
     if (is_array($values)) {
         $values = array_map('intval', $values);
     } else {
         $values = (int) $values;
     }
     rpt_set_object_relation($args['post_id'], $values, $this->post_type, false);
     return 1;
 }