id = $id;
$this->link = $link;
$this->group = $group;
if ( ! $badge_group_names instanceof Badge_Group_Names ) {
$badge_group_names = new Badge_Group_Names();
}
$this->badge_group_names = $badge_group_names;
}
/**
* Presents the New Badge. If a link has been passed, the badge is presented with the link.
* Otherwise a static badge is presented.
*
* @return string The styled New Badge.
*/
public function present() {
if ( ! $this->is_group_still_new() ) {
return '';
}
if ( $this->link !== '' ) {
return \sprintf(
'%3$s',
\esc_attr( $this->id ),
\esc_url( $this->link ),
\esc_html__( 'New', 'wordpress-seo' )
);
}
return \sprintf(
'%2$s',
\esc_attr( $this->id ),
\esc_html__( 'New', 'wordpress-seo' )
);
}
/**
* Check whether the new badge should be shown according to the group it is in.
*
* @return bool True if still new.
*/
public function is_group_still_new() {
// If there's no group configured, the new badge is always active.
if ( ! $this->group ) {
return true;
}
return $this->badge_group_names->is_still_eligible_for_new_badge( $this->group );
}
}