Skip to content

Commit 225a7c7

Browse files
authored
Merge pull request #53 from Upstatement/52-constructor-exception
Set constructor to use conditional instead of throwing an exception
2 parents 2a23f7a + 1ba2080 commit 225a7c7

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

includes/timber-stream.php

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,42 @@ class TimberStream extends TimberPost {
7676
public $options = null;
7777

7878
/**
79-
* Init Stream object
79+
* Construct Timber\Post, kick off stream init
8080
*
8181
* @param integer|boolean|string $pid Post ID or slug
8282
*
8383
* @todo allow creating a TimberStream w/out database
8484
*/
8585
public function __construct($pid = null) {
8686
parent::__construct($pid);
87-
if ($this->post_type !== 'sm_stream') {
88-
throw new Exception("TimberStream of $pid is not of sm_stream post type");
89-
}
90-
if ( !$this->post_content ) $this->post_content = serialize(array());
91-
$this->options = array_merge( $this->default_options, unserialize($this->post_content) );
92-
$this->options['query'] = apply_filters('stream-manager/query', $this->options['query']);
93-
$this->options = apply_filters( 'stream-manager/options/id=' . $this->ID, $this->options, $this );
94-
$this->options = apply_filters( 'stream-manager/options/'.$this->slug, $this->options, $this );
95-
96-
$taxes = apply_filters( 'stream-manager/taxonomy/'.$this->slug, array(), $this );
97-
if (is_array($taxes) && !empty($taxes)) {
98-
$taxes = StreamManagerUtilities::build_tax_query($taxes);
99-
if (isset($this->options['query']['tax_query'])) {
100-
$this->options['query']['tax_query'] = array_merge($this->options['query']['tax_query'], $taxes);
101-
} else {
102-
$this->options['query']['tax_query'] = $taxes;
87+
$this->init_stream($pid);
88+
}
89+
90+
/**
91+
* Init Stream object
92+
*
93+
* @param integer|boolean|string $pid Post ID or slug
94+
*
95+
*/
96+
public function init_stream($pid) {
97+
if ($this->post_type === 'sm_stream') {
98+
if ( !$this->post_content ) $this->post_content = serialize(array());
99+
$this->options = array_merge( $this->default_options, unserialize($this->post_content) );
100+
$this->options['query'] = apply_filters('stream-manager/query', $this->options['query']);
101+
$this->options = apply_filters( 'stream-manager/options/id=' . $this->ID, $this->options, $this );
102+
$this->options = apply_filters( 'stream-manager/options/'.$this->slug, $this->options, $this );
103+
104+
$taxes = apply_filters( 'stream-manager/taxonomy/'.$this->slug, array(), $this );
105+
if (is_array($taxes) && !empty($taxes)) {
106+
$taxes = StreamManagerUtilities::build_tax_query($taxes);
107+
if (isset($this->options['query']['tax_query'])) {
108+
$this->options['query']['tax_query'] = array_merge($this->options['query']['tax_query'], $taxes);
109+
} else {
110+
$this->options['query']['tax_query'] = $taxes;
111+
}
103112
}
104113
}
114+
105115
}
106116

107117
/**

0 commit comments

Comments
 (0)