From e7a01418226fdd8262087b6eef6615985a8364bc Mon Sep 17 00:00:00 2001 From: Miguel Torres <1233880+mmtr@users.noreply.github.com> Date: Tue, 23 Jul 2024 12:15:47 +0200 Subject: [PATCH] Footer credit: Render default credit on block themes (#38458) Stops overriding the default footer credit with a custom WP.com footer credit on block themes because such custom credit is unsupported in the site editor. --- .../block-theme-footer-credits.php | 25 --- ...class-wpcom-block-theme-footer-credits.php | 179 ------------------ .../remove-wpcomsh-footer-credit-block-themes | 4 + projects/plugins/wpcomsh/composer.json | 3 +- projects/plugins/wpcomsh/package.json | 2 +- projects/plugins/wpcomsh/wpcomsh.php | 5 +- 6 files changed, 8 insertions(+), 210 deletions(-) delete mode 100644 projects/plugins/wpcomsh/block-theme-footer-credits/block-theme-footer-credits.php delete mode 100644 projects/plugins/wpcomsh/block-theme-footer-credits/class-wpcom-block-theme-footer-credits.php create mode 100644 projects/plugins/wpcomsh/changelog/remove-wpcomsh-footer-credit-block-themes diff --git a/projects/plugins/wpcomsh/block-theme-footer-credits/block-theme-footer-credits.php b/projects/plugins/wpcomsh/block-theme-footer-credits/block-theme-footer-credits.php deleted file mode 100644 index 0e3c20561a5d4..0000000000000 --- a/projects/plugins/wpcomsh/block-theme-footer-credits/block-theme-footer-credits.php +++ /dev/null @@ -1,25 +0,0 @@ -should_update_footer_credits( $blog_id ) ) { - return; - } - - // Filter render blocks and find the footer. - add_filter( 'render_block', array( $this, 'maybe_add_markup_to_footer_template' ), 10, 2 ); - } - - /** - * Filters the blocks being rendered in render_block(), before it's processed, - * locate the footer template and update its content. - * - * @param string $block_content Block HTML content. - * @param array $block The block being rendered, as a single parsed block object. - * @return string The updated block HTML content. - */ - public function maybe_add_markup_to_footer_template( $block_content, $block ) { - - if ( $block['blockName'] !== 'core/template-part' || $block['attrs']['slug'] !== 'footer' ) { - return $block_content; - } - - // Try to find link to either WordPress.com or .org. - // Here we're expecting something along the lines of `

Powered by WordPress

` - $credit_regex = '/[^>]*)]*href="(http|https):\/\/(www\.)?wordpress.(org|com)(\/)?(\?\w+\=\w+)?"(\s?\w+\="[\w\-]+")*>.*<\/a>[^<]*/'; // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText - $credit_matches = preg_match( $credit_regex, $block_content ); - - // If there's a successful match, replace with our content. - if ( $credit_matches ) { - $new_value = $this->get_credit_link(); - return preg_replace( $credit_regex, $new_value, $block_content ); - } - - // If there is not a sucessful match append additional markup. - return $block_content . $this->get_credit_html(); - } - - /** - * Returns an HTML snipper with the WordPress.com link embedded. - * - * The innerHTML of the P tag may vary depending on which content the user has - * selected in the Customizer, if any. - * - * @return string The footer credit HTML with WordPress.com link. - */ - public function get_credit_html() { - $credit_link = $this->get_credit_link(); - if ( empty( $credit_link ) ) { - return ''; - } - return '
' . - '

' . - $credit_link . '

'; - } - - /** - * Returns the WordPress.com footer credit link HTML. - * - * @return string The footer link HTML - */ - public function get_credit_link() { - // Set any globals so the JS can access them. - $lang = get_bloginfo( 'language' ); - $credit_url = apply_filters( 'wpcom_better_footer_credit_url', 'https://wordpress.com/?ref=footer_blog', $lang ); - if ( ! empty( $credit_url ) ) { - $credit_link = sprintf( '%s.', esc_url( $credit_url ), __( 'Blog at WordPress.com', 'wpcomsh' ) ); - } else { - $credit_link = ''; - } - return apply_filters( 'wpcom_better_footer_credit_link', $credit_link, $lang ); - } - - /** - * Determines whether the footer credits bar should be updated for the current site. - * Should return as early as possible. - * Can be overridden with the WordPress filter: `wpcom_should_show_block_theme_footer_credits` - * - * @param int $blog_id current blog ID. - * @return boolean true if the credits should show, false otherwise. - */ - public function should_update_footer_credits( $blog_id ) { - // Reject empty argument. - if ( empty( $blog_id ) ) { - return false; - } - - // If we're not using the site editor-capable theme, don't show. - if ( ! $this->is_block_theme() ) { - return false; - } - - // If the current request is an API request, don't show. - if ( $this->is_api_request() ) { - return false; - } - - // Are we in Coming Soon mode? Don't show. - // Site members don't see the Coming Soon page when they're logged in. - // So we should also show the footer banner for those who can see the site. - // For all logged out coming soon page hits, we'll hide the banner. - if ( $this->is_coming_soon( $blog_id ) && ! $this->is_site_member_logged_in() ) { - return false; - } - - return apply_filters( 'wpcom_should_show_block_theme_footer_credits', true ); - } - - /** - * Determine if the current theme is a block theme. - * - * @return bool True if the theme is a block theme. False otherwise. - */ - public function is_block_theme() { - return function_exists( 'wp_is_block_theme' ) && wp_is_block_theme(); - } - - /** - * Determine if the current request is an API request - * - * @return bool True if the request is an API request, false otherwise. - */ - private function is_api_request() { - $is_api_request = defined( 'REST_API_REQUEST' ) && REST_API_REQUEST; - if ( $is_api_request ) { - return true; - } - - return false; - } - - /** - * Determine if the current site is in coming soon mode. - * - * @param int $blog_id The blog_id. - * @return bool True if the request is in coming soon mode, false otherwise. - */ - private function is_coming_soon( $blog_id ) { - if ( function_exists( 'is_wpcom_public_coming_soon_enabled' ) ) { - if ( is_wpcom_public_coming_soon_enabled( $blog_id ) ) { - return true; - } - } - return false; - } - - /** - * Checks if a site member is logged in while visiting the site. - * - * @return bool True if logged in, false otherwise. - */ - private function is_site_member_logged_in() { - if ( is_user_logged_in() && current_user_can( 'read' ) ) { - return true; - } - - return false; - } -} diff --git a/projects/plugins/wpcomsh/changelog/remove-wpcomsh-footer-credit-block-themes b/projects/plugins/wpcomsh/changelog/remove-wpcomsh-footer-credit-block-themes new file mode 100644 index 0000000000000..1f55120d196be --- /dev/null +++ b/projects/plugins/wpcomsh/changelog/remove-wpcomsh-footer-credit-block-themes @@ -0,0 +1,4 @@ +Significance: major +Type: removed + +Footer credit: Render default credit on block themes diff --git a/projects/plugins/wpcomsh/composer.json b/projects/plugins/wpcomsh/composer.json index 3f7e76782b4e1..7a187c79bc0a2 100644 --- a/projects/plugins/wpcomsh/composer.json +++ b/projects/plugins/wpcomsh/composer.json @@ -26,7 +26,6 @@ }, "autoload": { "classmap": [ - "block-theme-footer-credits", "customizer-fixes", "custom-colors", "endpoints", @@ -130,7 +129,7 @@ "composer/installers": true, "roots/wordpress-core-installer": true }, - "autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ4_1_0_alpha" + "autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ5_0_0_alpha" }, "extra": { "mirror-repo": "Automattic/wpcom-site-helper", diff --git a/projects/plugins/wpcomsh/package.json b/projects/plugins/wpcomsh/package.json index a3188ee997d8f..5f9e7b3935906 100644 --- a/projects/plugins/wpcomsh/package.json +++ b/projects/plugins/wpcomsh/package.json @@ -3,7 +3,7 @@ "name": "@automattic/jetpack-wpcomsh", "description": "A helper for connecting WordPress.com sites to external host infrastructure.", "homepage": "https://jetpack.com", - "version": "4.1.0-alpha", + "version": "5.0.0-alpha", "bugs": { "url": "https://github.com/Automattic/jetpack/labels/[Plugin] Wpcomsh" }, diff --git a/projects/plugins/wpcomsh/wpcomsh.php b/projects/plugins/wpcomsh/wpcomsh.php index 29cdc464af203..6dbd8cb8d5c3e 100644 --- a/projects/plugins/wpcomsh/wpcomsh.php +++ b/projects/plugins/wpcomsh/wpcomsh.php @@ -2,14 +2,14 @@ /** * Plugin Name: WordPress.com Site Helper * Description: A helper for connecting WordPress.com sites to external host infrastructure. - * Version: 4.1.0-alpha + * Version: 5.0.0-alpha * Author: Automattic * Author URI: http://automattic.com/ * * @package wpcomsh */ -define( 'WPCOMSH_VERSION', '4.1.0-alpha' ); +define( 'WPCOMSH_VERSION', '5.0.0-alpha' ); // If true, Typekit fonts will be available in addition to Google fonts add_filter( 'jetpack_fonts_enable_typekit', '__return_true' ); @@ -28,7 +28,6 @@ require_once __DIR__ . '/plugin-hotfixes.php'; require_once __DIR__ . '/footer-credit/footer-credit.php'; -require_once __DIR__ . '/block-theme-footer-credits/block-theme-footer-credits.php'; require_once __DIR__ . '/storefront/storefront.php'; require_once __DIR__ . '/custom-colors/colors.php'; require_once __DIR__ . '/storage/storage.php';