From 70e465030b0e62e654328cc956646a79454b6dbb Mon Sep 17 00:00:00 2001 From: Mahdi Yazdani Date: Thu, 22 Aug 2024 22:13:40 +0300 Subject: [PATCH] Fix Breadcrumbs Trails (#4) * feat: install wp-breadcrumbs package * bump plugin version * refactor: breadcrumbs generator * add changelog * fix: remove extra line break * Generated * fix: update breadcrumbs package --- composer.json | 5 +-- composer.lock | 66 ++++++++++++++++++++++++++++++++++++-- languages/seo-ready.pot | 16 +++++----- readme.txt | 8 +++-- seo-ready.php | 70 +++++++---------------------------------- 5 files changed, 90 insertions(+), 75 deletions(-) diff --git a/composer.json b/composer.json index bd2d59e..5fbab83 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "archive": { "exclude": [ "!/languages", - "vendor", + "!vendor/*", "node_modules", "CODE_OF_CONDUCT.md", "composer.json", @@ -41,7 +41,8 @@ "license": "GPL-3.0", "name": "mypreview/seo-ready", "require": { - "php": ">=7.4" + "php": ">=7.4", + "mahdiyazdani/wp-breadcrumbs": "^1.0" }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "0.7.2", diff --git a/composer.lock b/composer.lock index 681ddc9..a1adb18 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,68 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "919962b5d14c234b81969f6c3412163b", - "packages": [], + "content-hash": "b1c81f532ecf544b188054265d23f5f8", + "packages": [ + { + "name": "mahdiyazdani/wp-breadcrumbs", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/mahdiyazdani/wp-breadcrumbs.git", + "reference": "743dd87a87ccddc02733e28d2e18378b492d1ee8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mahdiyazdani/wp-breadcrumbs/zipball/743dd87a87ccddc02733e28d2e18378b492d1ee8", + "reference": "743dd87a87ccddc02733e28d2e18378b492d1ee8", + "shasum": "" + }, + "require": { + "php": ">=7.4" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "0.7.2", + "php-parallel-lint/php-parallel-lint": "1.3.2", + "phpcompatibility/phpcompatibility-wp": "2.1.3", + "phpunit/phpunit": "9.5.24", + "squizlabs/php_codesniffer": "3.7.1", + "wp-coding-standards/wpcs": "2.3.0" + }, + "type": "wordpress-plugin", + "extra": { + "scripts-description": { + "lint:wpcbf": "Fix coding standards warnings/errors automatically with PHP Code Beautifier", + "lint:wpcs": "Analyze code against the WordPress coding standards with PHP_CodeSniffer" + } + }, + "autoload": { + "classmap": [ + "src" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0" + ], + "authors": [ + { + "name": "Breadcrumbs for WordPress", + "homepage": "https://mahdiyazdani.one" + } + ], + "description": "Library to be bundled with WordPress themes and plugins to display a simple and easy to use breadcrumbs.", + "homepage": "https://github.com/mahdiyazdani/wp-breadcrumbs", + "keywords": [ + "plugin", + "wordpress" + ], + "support": { + "issues": "https://github.com/mahdiyazdani/wp-breadcrumbs/issues", + "source": "https://github.com/mahdiyazdani/wp-breadcrumbs/tree/1.0.0" + }, + "time": "2024-08-22T18:25:16+00:00" + } + ], "packages-dev": [ { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -2933,5 +2993,5 @@ "php": ">=7.4" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/languages/seo-ready.pot b/languages/seo-ready.pot index efd2ce1..410f38d 100644 --- a/languages/seo-ready.pot +++ b/languages/seo-ready.pot @@ -2,14 +2,14 @@ # This file is distributed under the GPL-3.0. msgid "" msgstr "" -"Project-Id-Version: SEO Ready 2.3.0\n" +"Project-Id-Version: SEO Ready 2.3.1\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/seo-ready\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2024-08-19T12:45:57+00:00\n" +"POT-Creation-Date: 2024-08-22T18:16:34+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.8.1\n" "X-Domain: seo-ready\n" @@ -34,34 +34,34 @@ msgid "MyPreview" msgstr "" #. translators: 1: Open anchor tag, 2: Close anchor tag. -#: seo-ready.php:79 +#: seo-ready.php:86 msgctxt "plugin link" msgid "%1$sCommunity support%2$s" msgstr "" #. translators: 1: Open anchor tag, 2: Close anchor tag. -#: seo-ready.php:81 +#: seo-ready.php:88 msgctxt "plugin link" msgid "%1$sDonate%2$s" msgstr "" #. translators: 1: Open anchor tag, 2: Close anchor tag. -#: seo-ready.php:81 +#: seo-ready.php:88 msgid "Donate to support this plugin" msgstr "" -#: seo-ready.php:222 +#: seo-ready.php:229 msgid "Est. reading time" msgstr "" #. translators: %s: Estimated reading time in minutes. -#: seo-ready.php:224 +#: seo-ready.php:231 msgid "%s minute" msgid_plural "%s minutes" msgstr[0] "" msgstr[1] "" -#: seo-ready.php:226 +#: seo-ready.php:233 msgid "Written by" msgstr "" diff --git a/readme.txt b/readme.txt index 3cf322e..a2a0db6 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Donate link: https://www.buymeacoffee.com/mahdiyazdani Requires at least: 5.5 Tested up to: 6.6 Requires PHP: 7.4 -Stable tag: 2.3.0 +Stable tag: 2.3.1 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -27,7 +27,7 @@ Enhance your website's search engine visibility while optimizing content for bot Optimize the way search engines understand and display your content. Selecting relevant schema types will improve how pages and posts are interpreted and make them more likely to display in rich snippets, potentially increasing visibility in search results. The article type dropdown menu will also allow you to customize the schema settings based on the content, thus properly presenting the content in the search engine listings. ## Social Media Integration -Control over how the content appears on platforms like Facebook and Twitter/X, including what images, titles, and descriptions to use ensures posts look their best when shared, captures attention and generates engagement. +Control over how the content appears on platforms like Facebook and Twitter/X, including what images, titles, and descriptions to use ensures posts look their best when shared, captures attention and generates engagement. ## Breadcrumbs Block The schema-enhanced Breadcrumbs block helps boost both user navigation and SEO. Breadcrumbs not only help users understand their location on a site but also provide search engines with valuable context. @@ -36,7 +36,6 @@ The Breadcrumbs block settings will allow you to personalize the delimiter, hide ## Why Choose SEO Ready? SEO Ready delivers all the essential tools needed to optimize your WordPress website for search engines and social media, helping you reach a wider audience and significantly improving your site’s visibility. Its user-friendly interface and comprehensive feature set make SEO Ready the perfect choice for anyone looking to enhance their SEO efforts with minimal hassle. - == Installation == = Minimum Requirements = @@ -92,6 +91,9 @@ Yes, our dedicated support team is ready to assist you with any questions or iss 3. Customize how your content appears on Facebook and Twitter/X with the SEO Ready plugin's social media settings. == Changelog === += 2.3.1 = +* Fix blog breadcrumb trails not displaying in the single post view. + = 2.3.0 = * Add "Breadcrumbs" editor block. diff --git a/seo-ready.php b/seo-ready.php index 5d974a7..0567b7c 100644 --- a/seo-ready.php +++ b/seo-ready.php @@ -26,7 +26,7 @@ * Plugin Name: SEO Ready * Plugin URI: https://mypreview.one * Description: A lightweight SEO plugin to generate most commonly used meta tags. Designed for privacy, speed, and accessibility. - * Version: 2.3.0 + * Version: 2.3.1 * Author: MyPreview * Author URI: https://mypreview.one * Requires at least: 5.9 @@ -37,6 +37,8 @@ * Domain Path: /languages */ +use SEO_Ready\Breadcrumbs; + if ( ! defined( 'ABSPATH' ) ) { header( 'Status: 403 Forbidden' ); header( 'HTTP/1.1 403 Forbidden' ); @@ -45,6 +47,11 @@ define( 'SEO_READY_VERSION', '2.3.0' ); +/** + * Loads the PSR-4 autoloader implementation. + */ +require_once untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/vendor/autoload.php'; + /** * Load the plugin text domain for translation. * @@ -723,37 +730,7 @@ function seo_ready_estimated_reading_time_minutes( $post_id ) { */ function seo_ready_generate_breadcrumbs_trails( $post_id = null, $attributes = array() ) { - $post_id = seo_ready_get_localized_post_id(); - - // Leave early if no post id is found. - if ( ! seo_ready_is_post_exists( $post_id ) ) { - return array(); - } - - $post_type = get_post_type( $post_id ); - - if ( false === $post_type ) { - return array(); - } - - $ancestor_ids = array(); - $has_post_hierarchy = is_post_type_hierarchical( $post_type ); - - if ( $has_post_hierarchy ) { - if ( ! empty( $ancestor_ids ) ) { - $ancestor_ids = get_post_ancestors( $post_id ); - } - } else { - $terms = get_the_terms( $post_id, 'category' ); - - if ( $terms && ! is_wp_error( $terms ) ) { - $term = get_term( $terms[0], 'category' ); - $ancestor_ids[] = $term->term_id; - $ancestor_ids = array_merge( $ancestor_ids, get_ancestors( $term->term_id, 'category' ) ); - } - } - - $trails = array(); + $breadcrumbs = new Breadcrumbs\Trails(); // Prepend site title breadcrumb if available and set to show. $site_title = get_bloginfo( 'name' ); @@ -761,36 +738,11 @@ function seo_ready_generate_breadcrumbs_trails( $post_id = null, $attributes = a if ( $site_title && empty( $attributes['hideSiteTitle'] ) ) { $site_title = ! empty( $site_title_override ) ? $site_title_override : $site_title; - $trails[] = array( - $site_title, - get_bloginfo( 'url' ), - ); - } - if ( $has_post_hierarchy ) { - // Construct remaining breadcrumbs from ancestor ids. - foreach ( array_reverse( $ancestor_ids ) as $ancestor_id ) { - $trails[] = array( - get_the_title( $ancestor_id ), - get_the_permalink( $ancestor_id ), - ); - } - } else { - foreach ( array_reverse( $ancestor_ids ) as $ancestor_id ) { - $trails[] = array( - get_cat_name( $ancestor_id ), - get_category_link( $ancestor_id ), - ); - } + $breadcrumbs->add_crumb( $site_title, get_bloginfo( 'url' ) ); } - // Append current page title if set to show. - if ( empty( $attributes['hideCurrentPageTrail'] ) ) { - $trails[] = array( - get_the_title( $post_id ), - get_the_permalink( $post_id ), - ); - } + $trails = $breadcrumbs->generate(); seo_ready_generate_breadcrumb_list_item( $trails );