From 2dc22039094b549e86b9b74fc676de57fe7d9d98 Mon Sep 17 00:00:00 2001 From: Dusty Reagan Date: Wed, 10 Apr 2024 00:39:06 -0500 Subject: [PATCH] Link Manager: Port "Check once rather than always force on" to jetpack_mu_wpcom (#36770) * Add links manager check * changelog * Run tools/fixup-project-versions.sh * Run tools/fixup-project-versions.sh --- .../changelog/add-links-manager-check | 4 +++ .../wpcom-site-menu/wpcom-site-menu.php | 34 +++++++++++++++++++ .../changelog/add-links-manager-check | 5 +++ 3 files changed, 43 insertions(+) create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/add-links-manager-check create mode 100644 projects/plugins/mu-wpcom-plugin/changelog/add-links-manager-check diff --git a/projects/packages/jetpack-mu-wpcom/changelog/add-links-manager-check b/projects/packages/jetpack-mu-wpcom/changelog/add-links-manager-check new file mode 100644 index 0000000000000..959cf0944f6a4 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/add-links-manager-check @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Conditionally enable link manager on Simple and Atomic sites diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php index c8941496b42c8..5c796f47fd8f9 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-site-menu/wpcom-site-menu.php @@ -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' ); diff --git a/projects/plugins/mu-wpcom-plugin/changelog/add-links-manager-check b/projects/plugins/mu-wpcom-plugin/changelog/add-links-manager-check new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/mu-wpcom-plugin/changelog/add-links-manager-check @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + +