Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

broken aioseop_description filter #1468

Closed
michaeltorbert opened this issue Jan 12, 2018 · 7 comments

Comments

Projects
None yet
3 participants
@michaeltorbert
Copy link
Member

commented Jan 12, 2018

2.4.4 possibly broke the aioseop_description filter in some cases.
Reported here: https://wordpress.org/support/topic/apply_filters-aioseop_description/

We should try and reproduce this and determine under what conditions it would be the case.
I'd say at a minimum, it probably happens when there's a manually entered description.

Try and find anything moving the filter may have broken.

@michaeltorbert

This comment has been minimized.

Copy link
Member Author

commented Jan 12, 2018

Reported again by Marco via email:

i use this filter:

add_filter( 'aioseop_description', 'sfwd_description_comment_page_num' );
function sfwd_description_comment_page_num( $description ) {
$cpage = get_query_var( 'cpage' );
if ( !empty( $cpage ) ) $description = "Pag. n.$cpage - " . $description;
return $description;
}

Unfortunately, it doesn't work anymore after the latest update

@michaeltorbert michaeltorbert modified the milestones: 2.4.5, 2.4.4.1 Jan 12, 2018

@EkoJR

This comment has been minimized.

Copy link
Member

commented Jan 12, 2018

Solution

Looking into the issue I found the following code modifications had to occur...

Place the the apply_filter('aioseop_description') back to where it was.

Then apply truncate with the global variable $aioseop_options['aiosp_dont_truncate_descriptions'] since it seems to be based on it and doesn't appear to be set anywhere. Still unsure if it is implemented elsewhere

Inside All_in_One_SEO_Pack::filter_description() had to add a boolean check instead of just checking ! empty(). Which appears to be a function bug where the string is trimmed even if the value is false.

if ( ! empty( $truncate ) && $truncate )
	$value = $this->trim_excerpt_without_filters( $value );
// Encode to valid SEO html entities
return $this->seo_entity_encode( $value );
@michaeltorbert

This comment has been minimized.

Copy link
Member Author

commented Jan 12, 2018

Marco confirmed that for him, the problem occurs for a manually entered meta description (not being able to filter it).
We need to make sure the fix doesn't break anything else.

@michaeltorbert

This comment has been minimized.

Copy link
Member Author

commented Jan 12, 2018

Possibly related to #1469

michaeltorbert added a commit that referenced this issue Jan 18, 2018

Merge pull request #1470 from EkoJr/i-1468-desc-update
fix for aioseop_description filter #1468
@wpsmort

This comment has been minimized.

Copy link
Member

commented Jan 18, 2018

@EkoJR I missed one problem with the filter code in PR #1470. That filter doesn't work for taxonomies because it's using get_post_meta. I believe you need to add get_term_meta for taxonomies.

Note that SEO for taxonomies is only for AIOSEOP Pro. You can detect if you're in Pro by looking for the AIOSEOPPRO constant boolean.

@EkoJR

This comment has been minimized.

Copy link
Member

commented Jan 19, 2018

@wpsmort Looks like the initial filter still works. This is the 3rd truncate code though, which seemed to give you trouble. Let me know where any issues continue.

add_filter( 'aioseop_description', 'manual_description_force_truncate_3', 9, 2 );
function manual_description_force_truncate_3( $description, $truncate = false ) {
	global $post;

	$aioseop_desc = '';
	if ( is_front_page() || is_single() || is_page() || is_attachment() || is_home() ) {
		if ( ! empty( $post->ID ) ) {
			$aioseop_desc = get_post_meta( $post->ID, '_aioseop_description', true );
		}

		if ( ! empty( $aioseop_desc ) ) {
			$description = substr( $description, 0, 320 );
		}
	} else if ( is_category() || is_tag() || is_tax() ) {
		if ( AIOSEOPPRO ) {
			$queried_object = get_queried_object();
			$term_meta = '';
			if ( ! empty( $queried_object ) && ! empty( $queried_object->term_id ) ) {
				$term_meta = get_term_meta( $queried_object->term_id, '_aioseop_description', true );
			}
			if ( ! empty( $term_meta ) ) {
				$description = substr( $description, 0, 320 );
			}
		}
	}

	return $description;
}
@wpsmort

This comment has been minimized.

Copy link
Member

commented Feb 7, 2018

I have confirmed that the filter above works for taxonomies. I have added documentation on this filter here - https://semperplugins.com/documentation/truncate-manually-entered-seo-descriptions/

@wpsmort wpsmort closed this Feb 7, 2018

@wpsmort wpsmort removed the Initial Review label Feb 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.