init_hooks();
}
private function init_hooks( ) {
add_filter( 'wpforo_template_buttons',
function( $html, $button, $forum, $topic, $post ){
if( $button === 'bookmark' ){
$post['forumid'] = (int) wpfval( $forum, 'forumid' );
$html .= $this->button( $post );
}
return $html;
},
10, 5
);
}
/**
* @param array $post
*
* @return string
*/
public function button( $post ) {
if(
( $postid = wpforo_bigintval( wpfval( $post, 'postid' ) ) )
&& ( $forumid = wpforo_bigintval( wpfval( $post, 'forumid' ) ) )
&& WPF()->perm->forum_can( 'l', $forumid )
) {
$is_bookmarked = WPF()->bookmark->is_user_bookmarked_this( $postid );
return $this->_button( ! $is_bookmarked );
}
return '';
}
/**
* @param bool $status
*
* @return string
*/
public function _button( $status, $onlyicon = true ) {
return sprintf(
'%3$s %4$s',
( $status ? 'wpforo-bookmark' : 'wpforo-unbookmark' ),
( $status ? wpforo_phrase( 'Bookmark', false ) : wpforo_phrase( 'Unbookmark', false ) ),
( $status ? '' : '' ),
(
! $onlyicon ?
sprintf(
'%1$s',
( $status ? wpforo_phrase( 'Bookmark', false ) : wpforo_phrase( 'Unbookmark', false ) )
) : ''
)
);
}
}