Add save hooks
@param integer $post_id
TODO add nonce check
487883
public function addSaveHooks($post_id)
    {
        global $post;
        $class = get_called_class();
        $old_entry = new $class;
        $old_entry->load($post_id);

        // Make sure we have the right post type
        // Without this, you'll get weird cross-polination errors across post types
        if (!is_object($post) || $post->post_type !== $this->getPostType()) {
            return;
        }

        // Check autosave
        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return $post_id;
        }
        
        // Check that a post_type is defined. It's not in the case of a delete.
        if (!array_key_exists('post_type', $_POST)) {
            return $post_id;
        }
        
        // Check perms
        $check = ($_POST['post_type'] === 'page') ? 'edit_page' : 'edit_post';
        if (!current_user_can($check, $post_id)) {
            return $post_id;
        }

        // Get fields to assign
        $updated_entry = new $class;
        $field_keys = array_merge(static::getCoreFieldKeys(), $this->getMetaFieldKeys());

        // Assign vars
        foreach ($_POST as $k => $v) {
            if (in_array($k, $field_keys)) {
                $updated_entry->set($k, $v);
            }
        }

        return $updated_entry->save(true);
    }
298350
private function is_valid_update( $post_status, $post_type ) {
		return ! $this->app->utility->defined( 'DOING_AUTOSAVE' ) && in_array( $post_status, [
				'publish',
				'future',
				'draft',
				'draft',
				'pending',
				'private',
			] ) && $this->is_valid_custom_post_type( $post_type ) && 'untrash' !== $this->app->input->get( 'action' );
	}
1305275
function save_user( $user_id )
	{
		// verify nonce
		if( !isset($_POST['acf_nonce']) || !wp_verify_nonce($_POST['acf_nonce'], 'input') )
		{
			return $user_id;
		}
		
		
		// $post_id to save against
		$post_id = 'user_' . $user_id;

		
		// update the post
		do_action('acf/save_post', $post_id);
				
	}
429136
def add_or_update(uid, post_data):
        '''
        
        '''
        cur_rec = MPost.get_by_uid(uid)
        if cur_rec:
            MPost.update(uid, post_data)
        else:
            MPost.create_post(uid, post_data)
1159226
public function exists($post_id, string $key = ''): bool
    {
        return (bool) $this->collect($post_id, $key);
    }
425574
public function save_post_detect_new( $new_status, $old_status, $post ) {

		if ( $post ) {
			self::$old_post_status[ $post->post_type ] = $old_status;
		}

	}
321315
function mf_save_post_data( $post_id ) {
    global $wpdb;

    //@todo hay que ponerle nonce a una de las metaboxes
    /*if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename(__FILE__) ) ) {*/
      //return $post_id;
    /*}*/

    if ( !current_user_can( 'edit_post', $post_id ) )
      return $post_id;

     //just in case if the post_id is a post revision and not the post inself
    if ( $the_post = wp_is_post_revision( $post_id ) ) {
      $post_id = $the_post;
    }

    // Check if the post_type has page attributes
    // if is the case is necessary need save the page_template
    if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != 'page' && isset($_REQUEST['page_template'])) {
      add_post_meta($post_id, '_wp_mf_page_template', $_POST['page_template'], true) or update_post_meta($post_id, '_wp_mf_page_template', $_POST['page_template']);
    }

    if (!empty($_POST['magicfields'])) {

      $customfields = $_POST['magicfields'];

      /** Deleting the old values **/
      $sql_delete = $wpdb->prepare( "DELETE FROM ".MF_TABLE_POST_META." WHERE post_id = %s",$post_id );
      $wpdb->query($sql_delete);

      foreach ( $customfields as $field_name => $field ) {
        delete_post_meta($post_id, $field_name);
      }
      /** / Deleting the old values **/

      //creating the new values
      foreach( $customfields as $field_name => $groups ) {

        $group_count = 1;
        foreach( $groups as $fields ) {
          $field_count = 1;
          foreach( $fields as $value ) {
            //here if the value of the field needs a process before to be saved
            //should be trigger that method here
            //$value =  mf_process_value_by_type($field_name,$value);

            // Adding field value meta data
            add_post_meta($post_id, "{$field_name}", $value);

            $meta_id = $wpdb->insert_id;

            $sql_insert = $wpdb->prepare(
              "INSERT INTO " . MF_TABLE_POST_META .
              " ( meta_id, field_name, field_count, group_count, post_id ) " .
              " VALUES " .
              " (%s,'%s',%s,%s,%s) ",
              $meta_id,
              $field_name,
              $field_count,
              $group_count,
              $post_id
            );

            $wpdb->query($sql_insert);

            $field_count++;
          }
          $group_count++;
        }
      }
    }
  }
1011932
public static function addSaveHooks($term_id)
    {
        // Assign vars
        $class = get_called_class();
        $instance = new $class;
        $updated_entry = new $class;
        $field_keys = array_merge(
            static::getCoreFieldKeys(),
            array_keys($instance->getFields())
        );
        foreach ($_POST as $k => $v) {
            if (in_array($k, $field_keys)) {
                $updated_entry->set($k, $v);
            }
        }

        // Not sure why WordPress uses tag_ID here and term_id otherwise
        if (array_key_exists('tag-name', $_POST)) {
            $updated_entry->set('name', $_POST['tag-name']);
        }
        if (array_key_exists('tag_ID', $_POST)) {
            $updated_entry->set(self::ID, $_POST['tag_ID']);
        }

        // Forcing $exclude_core to be true prevents an infinite loop
        return $updated_entry->save(true);
        // return $updated_entry->save(array_key_exists(self::ID, $updated_entry->getInfo()));
    }
889542
public function votePlus($post_id)
    {
        $this->checkId($post_id);

        return $this->vote($post_id, self::VOTE_PLUS);
    }
198723
public function save_post( $post_id ) {

		if (
			empty( $_POST['rock-layout-nonce'] )
			||
			! wp_verify_nonce( $_POST['rock-layout-nonce'], basename( __FILE__ ) )
		) {

			return;

		}

		$override = ! empty( $_POST['rock-layout-override'] );
		$current  = $this->get_post_layout( $post_id );

		if ( ! $override && $current ) {

			delete_post_meta( $post_id, 'rock_layout' );

			return;

		}

		$layout = isset( $_POST['rock-layout'] ) ? sanitize_key( $_POST['rock-layout'] ) : null;

		if ( ! $override || ! $this->layout_exists( $layout ) || $layout === $current ) {

			return;

		}

		update_post_meta( $post_id, 'rock_layout', $layout );

	}
944719
public function save()
    {
        if (!$this->isValidPostSave()) {
            return;
        }

        // Check if post id is valid
        if (!isset($_REQUEST['id']) || empty($_REQUEST['id'])) {
            return trigger_error('Invalid post id. Please contact system administrator.');
        }

        $this->savePost();

        // If this is an ajax post, return "success" as plain text
        if (defined('DOING_AJAX') && DOING_AJAX) {
            echo "success";
            wp_die();
        }

        $this->notice(__('Modules saved', 'modularity'), ['updated']);
    }
686201
public function save_post($post_id, \WP_Post $post ){
        // Skip auto save
        if( wp_is_post_revision($post) || wp_is_post_autosave($post) ){
            return;
        }
        // Check Nonce
        if( !$this->verify_nonce() ){
            return;
        }
        // O.K., let's save
        foreach( $this->loop_fields() as $field ){
            try{
                if( is_wp_error($field) ){
                    /** @var \WP_Error $field */
                    throw new \Exception($field->get_error_message(), $field->get_error_code());
                }
                if( !$this->is_override_field($field->name) ){
                    /** @var \WPametu\UI\Field\Base $field */
                    $field->update($this->input->post($field->name), $post);
                }
            }catch ( \Exception $e ){
                $this->prg->addErrorMessage($e->getMessage());
            }

        }
    }
1363604
public function voteMinus($post_id)
    {
        $this->checkId($post_id);

        return $this->vote($post_id, self::VOTE_MINUS);
    }
232109
public function saveHideTitleCheckbox($postId, $post)
    {
        if (substr($post->post_type, 0, 4) != 'mod-') {
            return;
        }

        if (!isset($_POST['modularity-module-hide-title'])) {
            update_post_meta($post->ID, 'modularity-module-hide-title', 0);
            return;
        }

        update_post_meta($post->ID, 'modularity-module-hide-title', 1);
        return;
    }
952827
public function collect($post_id, string $key = ''): array
    {
        $post_id = (int) ($post_id ?? get_the_ID());

        if (!$post_id) { // Empty key is OK here.
            return []; // Not possible; empty array.
        }
        $value        = get_post_meta($post_id, $this->key($key), false);
        return $value = !is_array($value) ? [] : $value;
    }
1313266
public function getCommentsForPost($post_id)
    {
        $this->checkId($post_id);

        return $this->adapter->get(sprintf('/comments/%d', $post_id));
    }
551925
public function addPostToFavorite($post_id)
    {
        $this->checkId($post_id);

        return $this->adapter->put(sprintf('/post/%d/favorite', $post_id));
    }