Plugin Directory

Changeset 3454310


Ignore:
Timestamp:
02/05/2026 07:25:27 AM (2 months ago)
Author:
cifi
Message:

Fix - Tag, category and author pages details to show the correct language

Location:
squirrly-seo/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • squirrly-seo/trunk/models/Frontend.php

    r3359108 r3454310  
    781781
    782782    /**
    783      * Get the keyword fof this URL
     783     * Get the keyword for this URL
    784784     *
    785785     * @param $post
     
    787787     * @return array|false|WP_Error|WP_Term
    788788     */
    789     private function getTagDetails( $post ) {
    790         $temp = str_replace( '…', '...', single_tag_title( '', false ) );
    791 
    792         foreach ( get_taxonomies() as $tax ) {
    793             if ( $tax <> 'category' ) {
    794 
    795                 if ( $tag = get_term_by( 'name', $temp, $tax ) ) {
    796                     if ( ! is_wp_error( $tag ) ) {
    797                         return $tag;
    798                     }
    799                 }
    800             }
    801         }
    802 
    803         if ( $tag = get_term_by( 'id', $post->term_id, $post->taxonomy ) ) {
    804             if ( ! is_wp_error( $tag ) ) {
    805                 return $tag;
     789    private function getTagDetails( $post = null ) {
     790
     791        if ( ! is_tag() ) {
     792            return false;
     793        }
     794
     795        // Best: WP already gives you the tag term
     796        $term = get_queried_object();
     797        if ( $term instanceof WP_Term && $term->taxonomy === 'post_tag' && ! is_wp_error( $term ) ) {
     798            return $term;
     799        }
     800
     801        // Fallback: tag ID from query var
     802        $tag_id = (int) get_queried_object_id();
     803        if ( $tag_id ) {
     804            $term = get_term( $tag_id, 'post_tag' );
     805            if ( $term && ! is_wp_error( $term ) ) {
     806                return $term;
     807            }
     808        }
     809
     810        // Final fallback (only if you truly have it)
     811        if ( $post && ! empty($post->term_id) ) {
     812            $term = get_term( (int) $post->term_id, 'post_tag' );
     813            if ( $term && ! is_wp_error( $term ) ) {
     814                return $term;
    806815            }
    807816        }
     
    810819    }
    811820
     821
     822
    812823    /**
    813824     * Get the taxonomies details for this URL
     
    817828     * @return array|bool|false|mixed|null|object|string|WP_Error|WP_Term
    818829     */
    819     private function getTaxonomyDetails( $post ) {
    820         if ( $id = get_queried_object_id() ) {
    821             $term = get_term( $id, '' );
    822             if ( ! is_wp_error( $term ) ) {
     830    private function getTaxonomyDetails( $post = null ) {
     831
     832        if ( ! is_tax() ) {
     833            return false;
     834        }
     835
     836        // Best: WP already resolved the current term for this taxonomy archive
     837        $term = get_queried_object();
     838        if ( $term instanceof WP_Term && ! is_wp_error( $term ) ) {
     839            return $term;
     840        }
     841
     842        // Fallback: use query vars (taxonomy + term id)
     843        $term_id  = (int) get_queried_object_id();
     844        $taxonomy = get_query_var( 'taxonomy' ); // e.g. 'product_cat', 'portfolio_tag', etc.
     845
     846        if ( $term_id && $taxonomy ) {
     847            $term = get_term( $term_id, $taxonomy );
     848            if ( $term && ! is_wp_error( $term ) ) {
    823849                return $term;
    824850            }
    825851        }
    826852
    827         if ( $term = get_term_by( 'id', $post->term_id, $post->taxonomy ) ) {
    828             if ( ! is_wp_error( $term ) ) {
     853        // Final fallback: if you truly have it in $post
     854        if ( $post && ! empty($post->term_id) && ! empty($post->taxonomy) ) {
     855            $term = get_term_by( 'id', (int) $post->term_id, $post->taxonomy );
     856            if ( $term && ! is_wp_error( $term ) ) {
    829857                return $term;
    830858            }
     
    834862    }
    835863
     864
     865
    836866    /**
    837867     * Get the category details for this URL
     
    841871     * @return array|false|object|WP_Error|null
    842872     */
    843     private function getCategoryDetails( $post ) {
    844 
    845         if ( $term = get_category( get_query_var( 'cat' ), false ) ) {
    846             if ( ! is_wp_error( $term ) ) {
     873    private function getCategoryDetails( $post = null ) {
     874
     875        if ( ! is_category() ) {
     876            return false;
     877        }
     878
     879        // Best: already-resolved term object for the current category archive
     880        $term = get_queried_object();
     881        if ( $term instanceof WP_Term && $term->taxonomy === 'category' && ! is_wp_error( $term ) ) {
     882            return $term;
     883        }
     884
     885        // Fallback: category ID from query var
     886        $cat_id = (int) get_query_var( 'cat' );
     887        if ( $cat_id ) {
     888            $term = get_term( $cat_id, 'category' ); // or get_category($cat_id)
     889            if ( $term && ! is_wp_error( $term ) ) {
    847890                return $term;
    848891            }
    849892        }
    850893
    851         if ( $tag = get_term_by( 'id', $post->term_id, $post->taxonomy ) ) {
    852             if ( ! is_wp_error( $tag ) ) {
     894        // Final fallback (only if you truly have it)
     895        if ( $post && ! empty($post->term_id) ) {
     896            $term = get_term( (int) $post->term_id, 'category' );
     897            if ( $term && ! is_wp_error( $term ) ) {
    853898                return $term;
    854899            }
     
    858903    }
    859904
     905
     906
    860907    /**
    861908     * Get the profile details for this URL
    862909     *
    863      * @return object
     910     * @return false|object
    864911     */
    865912    public function getAuthorDetails() {
    866         $author = false;
    867         global $authordata;
    868         if ( isset( $authordata->data ) ) {
    869             $author              = $authordata->data;
    870             $author->description = get_the_author_meta( 'description' );
    871         }
    872 
    873         return $author;
    874     }
     913        if ( ! is_author() ) {
     914            return false;
     915        }
     916
     917        // On author archives this should be the WP_User object
     918        $author = get_queried_object();
     919        if ( $author instanceof WP_User ) {
     920            // Keep your expected "description" field
     921            $author->description = get_user_meta( $author->ID, 'description', true );
     922            return $author;
     923        }
     924
     925        // Fallback: author ID from query var
     926        $author_id = (int) get_query_var('author');
     927        if ( $author_id ) {
     928            $user = get_userdata( $author_id );
     929            if ( $user ) {
     930                $user->description = get_user_meta( $user->ID, 'description', true );
     931                return $user;
     932            }
     933        }
     934
     935        return false;
     936    }
     937
     938
    875939
    876940    /**
  • squirrly-seo/trunk/readme.txt

    r3435711 r3454310  
    44Tags: SEO, AI, XML sitemap, google search console, schema
    55Requires at least: 5.3
    6 Tested up to: 6.8
     6Tested up to: 6.9
    77Stable tag: 12.4.15
    88Requires PHP: 7.0
     
    258258* Fix - Correct the automation patterns for publish time
    259259* Fix - Javascript error on automation patterns
     260* Fix - Tag, category and author pages details to show the correct language
    260261
    261262= 12.4.14 =
Note: See TracChangeset for help on using the changeset viewer.