Skip to content

Commit

Permalink
Hide suggestions if the blogroll is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Apr 29, 2022
1 parent fb12d9c commit 41cd6f6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
7 changes: 3 additions & 4 deletions friends-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,13 @@ jQuery( function( $ ) {

searchTimeout = setTimeout( function() {
wp.ajax.post( 'friends_search_links', {
_ajax_nonce: $( 'ul.friend-suggestions' ).data( 'nonce' ),
_ajax_nonce: $( 'tr.friend-suggestions' ).data( 'nonce' ),
search: search
} ).done( function( response ) {
if ( response.data ) {
$( 'ul.friend-suggestions' ).html( response.data.content );
$( 'ul.friend-suggestions' ).closest( 'tr' ).show();
$( 'tr.friend-suggestions' ).show().find( 'td' ).html( response.data.content ).show();
} else {
$( 'ul.friend-suggestions' ).closest( 'tr' ).hide();
$( 'tr.friend-suggestions' ).hide();
}
} );
}, 50 );
Expand Down
3 changes: 1 addition & 2 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,7 @@ public function ajax_search_links() {
'admin/links',
null,
array(
'skip_ul' => true,
'links' => $links,
'links' => $links,
)
);
$content = ob_get_contents();
Expand Down
24 changes: 10 additions & 14 deletions templates/admin/add-friend.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
*/

$quick_subscribe = _x( 'Quick Subscribe', 'button', 'friends' );
$links = get_bookmarks(
array(
'orderby' => 'updated',
'limit' => 15,
)
);

?><div class="wrap"><form method="post">
<?php wp_nonce_field( 'add-friend' ); ?>
Expand All @@ -30,23 +36,13 @@
</p>
</td>
</tr>
<tr class="friend-suggestions" data-nonce="<?php echo esc_attr( wp_create_nonce( 'friends-links' ) ); ?>" style="display: <?php echo empty( $links ) ? 'none' : 'table-row'; ?>">
<th scope="row"><?php esc_html_e( 'Suggestions', 'friends' ); ?></label></th>
<td>
<?php

Friends\Friends::template_loader()->get_template_part(
'admin/links',
null,
array(
'links' => get_bookmarks(
array(
'orderby' => 'updated',
'limit' => 15,
)
),
)
);

if ( ! empty( $links ) ) {
Friends\Friends::template_loader()->get_template_part( 'admin/links', null, array( 'links' => $links ) );
}
?>
<p class="description" id="friend-suggestions">

Expand Down
13 changes: 5 additions & 8 deletions templates/admin/links.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
* @package Friends
*/

if ( ! isset( $args['skip_ul'] ) ) {
?><ul class="friend-suggestions" data-nonce="<?php echo esc_attr( wp_create_nonce( 'friends-links' ) ); ?>">
<?php
}
?>
<ul class="friend-suggestions"">
<?php

if ( empty( $args['links'] ) ) {
?>
Expand All @@ -29,8 +28,6 @@
</li>
<?php
}
if ( ! isset( $args['skip_ul'] ) ) {
?>

?>
</ul>
<?php
}

0 comments on commit 41cd6f6

Please sign in to comment.