public function postTypeSave()
    {
        global $post;

        if (!isset($post)) {
            return false;
        }

        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return $post->ID;
        }

        // Get contents
        $slug = $post->post_type;

        // Check metaboxes and slug
        if (empty($this->metaboxes) || $slug !== $this->slug) {
            return;
        }

        // Remove action hook and add it again later for no infinite loop
        remove_action('save_post', [&$this, 'postTypeSave']);

        /**
         * Fires for all post's fields through metaboxes.
         *
         * @var string $slug
         * @param int $post_id
         * @param array $metaboxes
         */
        do_action('ol_zeus_posttypehook_save_'.$slug, $post->ID, $this->metaboxes);

        // Update all metas
        foreach ($this->metaboxes as $metabox) {
            if (!$metabox) {
                continue;
            }

            // Get contents
            $id = (integer) $metabox->getModel()->getId();
            $title = (string) $metabox->getModel()->getTitle();
            $fields = (array) $metabox->getModel()->getFields();

            // Check fields
            if (empty($fields)) {
                continue;
            }

            // Get all values
            foreach ($fields as $field) {
                if (!$field) {
                    continue;
                }

                // Build contents
                $ctn = (array) $field->getModel()->getContents();
                $hasId = (boolean) $field->getModel()->getHasId();

                // Check ID
                if ($hasId && (!isset($ctn['id']) || empty($ctn['id']))) {
                    continue;
                }

                // Gets the value
                $value = Request::post($ctn['id'], null);

                // Check value
                if (is_null($value)) {
                    $value = Option::getPostMeta($post->ID, $slug.'-'.$ctn['id']);
                }

                /**
                 * Filter the value content.
                 *
                 * @var string $current
                 * @param int $post_id
                 * @param string $option_name
                 * @param object $value
                 * @return object $value
                 */
                $value = apply_filters('ol_zeus_posttypehook_save_'.$slug.'_field', $value, $post->ID, $slug.'-'.$ctn['id']);

                // Updates meta
                Option::updatePostMeta($post->ID, $slug.'-'.$ctn['id'], $value);
            }
        }

        // Add back action hook again for no infinite loop
        add_action('save_post', [&$this, 'postTypeSave']);

        return true;
    }
public function postTypeSave()
    {
        global $post;

        if (!isset($post)) {
            return false;
        }

        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return $post->ID;
        }

        // Get contents
        $slug = $post->post_type;

        // Check metaboxes and slug
        if (empty($this->metaboxes) || $slug !== $this->slug) {
            return;
        }

        // Remove action hook and add it again later for no infinite loop
        remove_action('save_post', [&$this, 'postTypeSave']);

        /**
         * Fires for all post's fields through metaboxes.
         *
         * @var string $slug
         * @param int $post_id
         * @param array $metaboxes
         */
        do_action('ol_zeus_posttypehook_save_'.$slug, $post->ID, $this->metaboxes);

        // Update all metas
        foreach ($this->metaboxes as $metabox) {
            if (!$metabox) {
                continue;
            }

            // Get contents
            $id = (integer) $metabox->getModel()->getId();
            $title = (string) $metabox->getModel()->getTitle();
            $fields = (array) $metabox->getModel()->getFields();

            // Check fields
            if (empty($fields)) {
                continue;
            }

            // Get all values
            foreach ($fields as $field) {
                if (!$field) {
                    continue;
                }

                // Build contents
                $ctn = (array) $field->getModel()->getContents();
                $hasId = (boolean) $field->getModel()->getHasId();

                // Check ID
                if ($hasId && (!isset($ctn['id']) || empty($ctn['id']))) {
                    continue;
                }

                // Gets the value
                $value = Request::post($ctn['id'], null);

                // Check value
                if (is_null($value)) {
                    $value = Option::getPostMeta($post->ID, $slug.'-'.$ctn['id']);
                }

                /**
                 * Filter the value content.
                 *
                 * @var string $current
                 * @param int $post_id
                 * @param string $option_name
                 * @param object $value
                 * @return object $value
                 */
                $value = apply_filters('ol_zeus_posttypehook_save_'.$slug.'_field', $value, $post->ID, $slug.'-'.$ctn['id']);

                // Updates meta
                Option::updatePostMeta($post->ID, $slug.'-'.$ctn['id'], $value);
            }
        }

        // Add back action hook again for no infinite loop
        add_action('save_post', [&$this, 'postTypeSave']);

        return true;
    }
public function postTypeSave ( ) { global $ post ; if ( ! isset ( $ post ) ) { return false ; } if ( defined ( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $ post -> ID ; } // Get contents $ slug = $ post -> post_type ; // Check metaboxes and slug if ( empty ( $ this -> metaboxes ) || $ slug !== $ this -> slug ) { return ; } // Remove action hook and add it again later for no infinite loop remove_action ( 'save_post' , [ & $ this , 'postTypeSave' ] ) ; /**
         * Fires for all post's fields through metaboxes.
         *
         * @var string $slug
         * @param int $post_id
         * @param array $metaboxes
         */ do_action ( 'ol_zeus_posttypehook_save_' . $ slug , $ post -> ID , $ this -> metaboxes ) ; // Update all metas foreach ( $ this -> metaboxes as $ metabox ) { if ( ! $ metabox ) { continue ; } // Get contents $ id = ( integer ) $ metabox -> getModel ( ) -> getId ( ) ; $ title = ( string ) $ metabox -> getModel ( ) -> getTitle ( ) ; $ fields = ( array ) $ metabox -> getModel ( ) -> getFields ( ) ; // Check fields if ( empty ( $ fields ) ) { continue ; } // Get all values foreach ( $ fields as $ field ) { if ( ! $ field ) { continue ; } // Build contents $ ctn = ( array ) $ field -> getModel ( ) -> getContents ( ) ; $ hasId = ( boolean ) $ field -> getModel ( ) -> getHasId ( ) ; // Check ID if ( $ hasId && ( ! isset ( $ ctn [ 'id' ] ) || empty ( $ ctn [ 'id' ] ) ) ) { continue ; } // Gets the value $ value = Request :: post ( $ ctn [ 'id' ] , null ) ; // Check value if ( is_null ( $ value ) ) { $ value = Option :: getPostMeta ( $ post -> ID , $ slug . '-' . $ ctn [ 'id' ] ) ; } /**
                 * Filter the value content.
                 *
                 * @var string $current
                 * @param int $post_id
                 * @param string $option_name
                 * @param object $value
                 * @return object $value
                 */ $ value = apply_filters ( 'ol_zeus_posttypehook_save_' . $ slug . '_field' , $ value , $ post -> ID , $ slug . '-' . $ ctn [ 'id' ] ) ; // Updates meta Option :: updatePostMeta ( $ post -> ID , $ slug . '-' . $ ctn [ 'id' ] , $ value ) ; } } // Add back action hook again for no infinite loop add_action ( 'save_post' , [ & $ this , 'postTypeSave' ] ) ; return true ; }
Hook saving custom fields for Post types.
Hook saving custom fields for Post types .