Skip to content

Commit

Permalink
Link Manager: Port "Check once rather than always force on" to jetpac…
Browse files Browse the repository at this point in the history
…k_mu_wpcom (#36770)

* Add links manager check

* changelog

* Run tools/fixup-project-versions.sh

* Run tools/fixup-project-versions.sh
  • Loading branch information
DustyReagan authored Apr 10, 2024
1 parent 0094941 commit 2dc2203
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Conditionally enable link manager on Simple and Atomic sites
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,37 @@ function hide_customizer_menu_on_block_theme() {
}
}
add_action( 'init', 'hide_customizer_menu_on_block_theme' );

/**
* Links were removed in 3.5 core, but we've kept them active on dotcom.
*
* This function will check to see if Links should be enabled based on the number of links in the database
* and then set an option to minimize repeat queries later. The Links menu is visible when the Link Manager is enabled.
*
* @return void
*/
function wpcom_maybe_enable_link_manager() {
if ( get_option( 'link_manager_check' ) ) {
return;
}

// The max ID number of the auto-generated links.
// See /wp-content/mu-plugins/wpcom-wp-install-defaults.php in WP.com.
$max_default_id = 10;

// We are only checking the latest entry link_id so are limiting the query to 1.
$link_manager_links = get_bookmarks(
array(
'orderby' => 'link_id',
'order' => 'DESC',
'limit' => 1,
'hide_invisible' => 0,
)
);

$has_links = is_countable( $link_manager_links ) && count( $link_manager_links ) > 0 && $link_manager_links[0]->link_id > $max_default_id;

update_option( 'link_manager_enabled', intval( $has_links ) );
update_option( 'link_manager_check', time() );
}
add_action( 'init', 'wpcom_maybe_enable_link_manager' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


0 comments on commit 2dc2203

Please sign in to comment.