data = ! is_null( $data ) ? $data : new TipData(); } /** * Set Tip Data instance to use * * @param TipData $data Tip Data instance. * @return void */ public function set_data( TipData $data ) : void { $this->data = $data; } /** * Display tip content * * @param bool $show_hidden Show block as hidden. * @return void */ public function show( bool $show_hidden = false ) : void { $view = Ahrefs_Seo::get()->get_view(); if ( $show_hidden ) { $view->show_part( $this::TEMPLATE_SUBDIR . 'header-hidden', [ 'tip_id' => $this::ID, 'show_hidden' => $show_hidden, ] ); } $view->show_part( $this::TEMPLATE_SUBDIR . $this::TEMPLATE, [ 'tip_id' => $this::ID, 'show_hidden' => $show_hidden, ] ); if ( $show_hidden ) { $view->show_part( $this::TEMPLATE_SUBDIR . 'footer-hidden', [ 'tip_id' => $this::ID, 'show_hidden' => $show_hidden, ] ); } } /** * Display tip on screen if allowed. * * @return void */ public function maybe_show_tip() : void { if ( $this->need_to_show() ) { $this->show(); } } /** * Need to show the tip. * Basically when it was not closed by user. * * @return bool */ public function need_to_show() : bool { return ! $this->data->is_tip_closed( $this ); } /** * Hide tip when it was closed by user * * @return void */ public function hide() : void { $this->data->set_tip_closed( $this, true ); } /** * Allow to show tip, reset "closed by user" * * @return void */ public function allow() : void { $this->data->set_tip_closed( $this, false ); } }