Собственно сам код. Нужно сделать его менее объемным, более грамотным.
public function widget($args, $instance){
echo $args['before_widget'];
if (is_single()) {
global $post;
echo '<script type="text/javascript">
function hide() {
document.getElementById("dllist").style.visibility = "visible";
}
</script>';
echo '<style>
.dllist{
display:none;
}
</style>';
$link1 = get_field('dl1', $post->ID);
$link2 = get_field('dl2', $post->ID);
$link3 = get_field('dl3', $post->ID);
$link4 = get_field('dl4', $post->ID);
$link5 = get_field('dl5', $post->ID);
$text1 = get_field('text1', $post->ID);
$text2 = get_field('text2', $post->ID);
$text3 = get_field('text3', $post->ID);
$text4 = get_field('text4', $post->ID);
$text5 = get_field('text5', $post->ID);
if(is_user_logged_in()) {
echo '<img src="/wp-content/uploads/2018/04/download.jpg" onclick="hide()" width="335px" height="120px">';
}
if($link5 && is_user_logged_in()) {
echo ' <div id="dllist" style="display:none">
<a href="' . $link1 . '" target="_blank" rel="nofollow" > ' . $text1 . ' </a><br>
<a href="' . $link2 . '" target="_blank" rel="nofollow" > ' . $text2 . ' </a><br>
<a href="' . $link3 . '" target="_blank" rel="nofollow" > ' . $text3 . ' </a><br>
<a href="' . $link4 . '" target="_blank" rel="nofollow" > ' . $text4 . ' </a><br>
<a href="' . $link5 . '" target="_blank" rel="nofollow" > ' . $text5 . ' </a>
</div> ';
}
elseif($link4 && is_user_logged_in()) {
echo ' <div id="dllist" style="display:none">
<a href="' . $link1 . '" target="_blank" rel="nofollow" > ' . $text1 . ' </a><br>
<a href="' . $link2 . '" target="_blank" rel="nofollow" > ' . $text2 . ' </a><br>
<a href="' . $link3 . '" target="_blank" rel="nofollow" > ' . $text3 . ' </a><br>
<a href="' . $link4 . '" target="_blank" rel="nofollow" > ' . $text4 . ' </a>
</div> ';
}
elseif($link3 && is_user_logged_in()) {
echo ' <div id="dllist" style="display:none">
<a href="' . $link1 . '" target="_blank" rel="nofollow" > ' . $text1 . ' </a><br>
<a href="' . $link2 . '" target="_blank" rel="nofollow" > ' . $text2 . ' </a><br>
<a href="' . $link3 . '" target="_blank" rel="nofollow" > ' . $text3 . ' </a>
</div> ';
}
elseif($link2 && is_user_logged_in()) {
echo ' <div id="dllist" style="visibility:hidden">
<a href="' . $link1 . '" target="_blank" rel="nofollow" > ' . $text1 . ' </a><br>
<a href="' . $link2 . '" target="_blank" rel="nofollow" > ' . $text2 . ' </a>
</div> ';
}
elseif($link1 && is_user_logged_in()) {
echo ' <div id="dllist" style="display:none">
<a href="' . $link1 . '" target="_blank" rel="nofollow" > ' . $text1 . ' </a>
</div> ';
}
else {
echo ' <a href="ссылка на регистрацию" target="_blank" rel="nofollow" ><img src="/wp-content/uploads/2018/04/fornonreg.jpg" width="335px" height="120px"></a>';
}
}
return $content;
}
Сборка персонального компьютера от Artline: умный выбор для современных пользователей