Skip to content

Exception thrown on transition_post_status #52

Description

@tzkmx

Beginning to use this awesome plugin and found just a glitch, fired when some is saving the post, it currently causes that custom fields added by SEO Yoast plugin, can't be saved because an unhandled exception from TimberStream is fired.

I actually don't understand why in the last call before throwing, a TimberStream without a $post_id it's created, since on null argument, TimberPost it's built taking the ID of the current post being edited, but the check insider TimberStream, that throws an Exception because is not a 'sm_stream' post_type, bails the saving of custom meta boxes, like the ones added by SEO Yoast Plugin.

The only workaround I've found to this is catching the thrown Exception inside the constructor itself, just logging the Exception and the trace, that I can provide to you if that's of any help (logged lot of events, every one with the same calls, justs different WP_Post objects).

This is my workaround on the TimberStream::__construct method:

  public function __construct($pid = null) {
    parent::__construct($pid);
    try {
    if ($this->post_type !== 'sm_stream') {
      throw new Exception("TimberStream of $pid is not of sm_stream post type");
    }
    if ( !$this->post_content ) $this->post_content = serialize(array());
    $this->options = array_merge( $this->default_options, unserialize($this->post_content) );
    $this->options['query'] = apply_filters('stream-manager/query', $this->options['query']);
    $this->options = apply_filters( 'stream-manager/options/id=' . $this->ID, $this->options, $this );
    $this->options = apply_filters( 'stream-manager/options/'.$this->slug, $this->options, $this );

    $taxes = apply_filters( 'stream-manager/taxonomy/'.$this->slug, array(), $this );
    if (is_array($taxes) && !empty($taxes)) {
      $taxes = StreamManagerUtilities::build_tax_query($taxes);
      if (isset($this->options['query']['tax_query'])) {
        $this->options['query']['tax_query'] = array_merge($this->options['query']['tax_query'], $taxes);
      } else {
        $this->options['query']['tax_query'] = $taxes;
      }
    }
    } catch(Exception $e) {
        error_log('Dumped error trace: ' . var_export($e, true), 0);
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions