| @@ -30,13 +30,8 @@ | ||
| 30 | 30 | * @var bool |
| 31 | 31 | */ |
| 32 | 32 | public $enabled = false; |
| 33 | 33 | |
| 34 | - /** | |
| 35 | - * @var WP_Post | |
| 36 | - */ | |
| 37 | - private $post; | |
| 38 | - | |
| 39 | 34 | /** |
| 40 | 35 | * @param WP_Post|int $post |
| 41 | 36 | */ |
| 42 | 37 | public function __construct( $post ) { |
| @@ -45,11 +40,8 @@ | ||
| 45 | 40 | if( ! $post instanceof WP_Post ) { |
| 46 | 41 | $post = get_post( $post ); |
| 47 | 42 | } |
| 48 | 43 | |
| 49 | - // store ref to post | |
| 50 | - $this->post = $post; | |
| 51 | - | |
| 52 | 44 | // store ID in property for quick access |
| 53 | 45 | $this->ID = $post->ID; |
| 54 | 46 | |
| 55 | 47 | // store title in property |
| @@ -99,12 +91,9 @@ | ||
| 99 | 91 | 'trigger_time_on_site' => 0, |
| 100 | 92 | 'trigger_time_on_page' => 0, |
| 101 | 93 | 'animation' => 'fade', |
| 102 | 94 | 'auto_hide' => 0, |
| 103 | - 'screen_size_condition' => array( | |
| 104 | - 'condition' => 'larger', | |
| 105 | - 'value' => 0, | |
| 106 | - ), | |
| 95 | + 'hide_on_screen_size' => '', | |
| 107 | 96 | 'closable' => true, |
| 108 | 97 | ); |
| 109 | 98 | $box = $this; |
| 110 | 99 | |
| @@ -165,9 +154,9 @@ | ||
| 165 | 154 | |
| 166 | 155 | /** |
| 167 | 156 | * Get the content of this box |
| 168 | 157 | * |
| 169 | - * @return string | |
| 158 | + * @return mixed|void | |
| 170 | 159 | */ |
| 171 | 160 | public function get_content() { |
| 172 | 161 | $content = $this->content; |
| 173 | 162 | $box = $this; |
| @@ -181,36 +170,37 @@ | ||
| 181 | 170 | $content = apply_filters( 'boxzilla_box_content', $content, $box ); |
| 182 | 171 | return $content; |
| 183 | 172 | } |
| 184 | 173 | |
| 185 | - /** | |
| 186 | - * Get options object for JS script. | |
| 187 | - * | |
| 188 | - * @return array | |
| 189 | - */ | |
| 174 | + /** | |
| 175 | + * Get the minimum allowed screen size for this box | |
| 176 | + * | |
| 177 | + * @return int | |
| 178 | + */ | |
| 179 | + public function get_minimum_screen_size() { | |
| 180 | + | |
| 181 | + if( $this->options['hide_on_screen_size'] > 0 ) { | |
| 182 | + $minimum_screen_size = absint( $this->options['hide_on_screen_size'] ); | |
| 183 | + } else { | |
| 184 | + $minimum_screen_size = 0; | |
| 185 | + } | |
| 186 | + | |
| 187 | + return $minimum_screen_size; | |
| 188 | + } | |
| 189 | + | |
| 190 | 190 | public function get_client_options() { |
| 191 | 191 | $box = $this; |
| 192 | 192 | |
| 193 | 193 | $trigger = false; |
| 194 | 194 | if( $box->options['trigger'] ) { |
| 195 | - $trigger = array( | |
| 196 | - 'method' => $this->options['trigger'] | |
| 197 | - ); | |
| 198 | 195 | |
| 196 | + $trigger = array( 'method' => $this->options['trigger'] ); | |
| 197 | + | |
| 199 | 198 | if( isset( $this->options[ 'trigger_' . $this->options['trigger'] ] ) ) { |
| 200 | 199 | $trigger['value'] = $this->options[ 'trigger_' . $this->options['trigger'] ]; |
| 201 | 200 | } |
| 202 | 201 | } |
| 203 | 202 | |
| 204 | - // build screenWidthCondition object (or null) | |
| 205 | - $screen_width_condition = null; | |
| 206 | - if( $box->options['screen_size_condition']['value'] > 0 ) { | |
| 207 | - $screen_width_condition = array( | |
| 208 | - 'condition' => $box->options['screen_size_condition']['condition'], | |
| 209 | - 'value' => intval( $box->options['screen_size_condition']['value'] ), | |
| 210 | - ); | |
| 211 | - } | |
| 212 | - | |
| 213 | 203 | $client_options = array( |
| 214 | 204 | 'id' => $box->ID, |
| 215 | 205 | 'icon' => $box->get_close_icon(), |
| 216 | 206 | 'content' => $box->get_content(), |
| @@ -222,15 +212,10 @@ | ||
| 222 | 212 | 'dismissed' => absint( $box->options['cookie']['dismissed'] ), |
| 223 | 213 | ), |
| 224 | 214 | 'rehide' => (bool) $box->options['auto_hide'], |
| 225 | 215 | 'position' => $box->options['css']['position'], |
| 226 | - 'screenWidthCondition' => $screen_width_condition, | |
| 216 | + 'minimumScreenWidth' => $box->get_minimum_screen_size(), | |
| 227 | 217 | 'closable' => $box->options['closable'], |
| 228 | - 'post' => array( | |
| 229 | - 'id' => $this->post->ID, | |
| 230 | - 'title' => $this->post->post_title, | |
| 231 | - 'slug' => $this->post->post_name, | |
| 232 | - ), | |
| 233 | 218 | ); |
| 234 | 219 | |
| 235 | 220 | /** |
| 236 | 221 | * Filter the final options for the JS Boxzilla client. |