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

fix for aioseop_description filter #1468 #1470

Merged
merged 6 commits into from Jan 18, 2018

Conversation

EkoJR
Copy link
Contributor

@EkoJR EkoJR commented Jan 12, 2018

@EkoJR EkoJR requested a review from wpsmort January 12, 2018 14:32
@michaeltorbert
Copy link
Contributor

This *may fix #1469 as well.

@wpsmort
Copy link

wpsmort commented Jan 12, 2018

I have reproduced the problem reported in both issues and confirmed that this PR fixes the issue. The SEO and OG meta is back to how it was prior to v2.4.4. I have tested the different options under Autogenerate Descriptions and confirmed that they all work as normal.

@michaeltorbert michaeltorbert changed the title Hotfix for aioseop_description filter #1468 fix for aioseop_description filter #1468 Jan 12, 2018
@michaeltorbert michaeltorbert removed the request for review from wpsmort January 12, 2018 19:33
@EkoJR
Copy link
Contributor Author

EkoJR commented Jan 13, 2018

@wpsmort I added an update that will need retesting. I also have a filter that may need testing; which will force Truncate for those that still want to trim their manual descriptions ( #1469 ).

add_filter( 'aioseop_description', 'manual_description_force_truncate_old', 9, 2 );
function manual_description_force_truncate_old( $description, $dont_truncate_not_empty = false ) {
	global $aioseop_options;
	if ( $dont_truncate_not_empty && true === $aioseop_options['aiosp_dont_truncate_descriptions'] ) {
		$aioseop_options['aiosp_dont_truncate_descriptions'] = false;
	}

	return $description;
}

@wpsmort
Copy link

wpsmort commented Jan 15, 2018

@EkoJR I tested the latest code and it breaks the way the Never Shorten Long Descriptions option works.

If you have that unchecked then the meta description is auto generated from the post excerpt and is not truncated and changing the Never Shorten Long Descriptions option has no effect.

If you then check the Use Content For Autogenerated Descriptions option then the meta description is auto generated from the post content and is truncated and changing the Never Shorten Long Descriptions option has no effect.

To reproduce this, set up a post with a long excerpt and long content. Then check the auto generated descriptions when you enable and disable Use Content For Autogenerated Descriptions.

Regarding setting for Never Shorten Long Descriptions
@wpsmort
Copy link

wpsmort commented Jan 15, 2018

@EkoJR I tested and this is now working fine. I tested all of the options under Autogenerate Descriptions.

I also tested your new filter which works as long as Never Shorten Long Descriptions is not checked. I think this is a bug because the option for Never Shorten Long Descriptions should only apply to Autogenerated Descriptions and your filter should only apply to manually entered descriptions.

@wpsmort
Copy link

wpsmort commented Jan 16, 2018

@EkoJR I tested your latest code and there is still a bug with Never Shorten Long Descriptions. If that option is unchecked then manual descriptions get truncated. We shouldn't be truncating manual descriptions unless your new filter is used.

@EkoJR
Copy link
Contributor Author

EkoJR commented Jan 16, 2018

@wpsmort I've had to change the concept once more to keep from truncating in those conditions.

Note: I did have to change the 2nd filter param was being sent, which I was trying to avoid, but may not affect anyone since it operates the same way needed for the main filter-function. Basically, it sends a variable instead that has that conditional value.

@EkoJR
Copy link
Contributor Author

EkoJR commented Jan 16, 2018

@wpsmort I can't seem to figure out a way to update truncating for the main function, but here is the basic filter to force/manual truncate.

add_filter( 'aioseop_description', 'manual_description_force_truncate', 9, 2 );
function manual_description_force_truncate( $description, $truncate = false ) {
	return substr( $description, 0, 320 );
}

I was trying to keep it isolated from modifying the OpenGraph Descriptions since they all use the same hook and I can't seem to find any other way to identify what class the value is for.

Perhaps AIOSEOP & OG Description should be separate filters, or some form of identifier?

I could add a new filter to the plugin for $truncate itself, but I've been trying to figure out other methods without having to introduce a filter.

@wpsmort
Copy link

wpsmort commented Jan 17, 2018

@EkoJR I tested your latest changes and the new filter is truncating auto generated descriptions as well. Can you fix that please.

I agree that aioseop_description should be separated out into SEO and OG description. We have a separate issue open to review and improve this filter - #1474

@EkoJR
Copy link
Contributor Author

EkoJR commented Jan 17, 2018

@wpsmort This filter should force truncate manual descriptions, but also avoid the Auto-Descriptions. It also avoids being used when Never Shorten Long Descriptions is checked; just in case it is being used.

add_filter( 'aioseop_description', 'manual_description_force_truncate', 9, 2 );
function manual_description_force_truncate( $description, $truncate = false ) {
	global $aioseop_options;
	if ( 'on' !== $aioseop_options['aiosp_generate_descriptions']  &&  empty( $aioseop_options['aiosp_dont_truncate_descriptions'] ) ) {
		$description = substr( $description, 0, 320 );
	}
	return $description;
}

@wpsmort
Copy link

wpsmort commented Jan 17, 2018

@EkoJR I tested that filter but it is not truncating my manual description.

@EkoJR
Copy link
Contributor Author

EkoJR commented Jan 17, 2018

@wpsmort It should be working with Never Shorten Long Descriptions is unchecked. Without it, it would be.

add_filter( 'aioseop_description', 'manual_description_force_truncate', 9, 2 );
function manual_description_force_truncate( $description, $truncate = false ) {
	global $aioseop_options;
	if ( 'on' !== $aioseop_options['aiosp_generate_descriptions'] ) {
		$description = substr( $description, 0, 320 );
	}
	return $description;
}

@wpsmort
Copy link

wpsmort commented Jan 18, 2018

@EkoJR Here's what I'm seeing on a post with a manually entered SEO description that is 500 characters long:

  • When nothing is checked under All in One SEO > Advanced Settings and the filter is present the meta description is truncated. This is correct behavior

  • When Autogenerate Descriptions is checked, the meta description is not truncated. This is incorrect, it should be truncated because of the filter. The Autogenerate Descriptions option shouldn't affect the manually entered description or the filter.

I hope this helps.

@EkoJR
Copy link
Contributor Author

EkoJR commented Jan 18, 2018

@wpsmort One of the filters I posted did do that...but I thought that you didn't want it to truncate auto descriptions.

I tested your latest changes and the new filter is truncating auto generated descriptions as well. Can you fix that please.

@wpsmort
Copy link

wpsmort commented Jan 18, 2018

@EkoJR The filter should do one thing which is to allow users to truncate manually entered descriptions. This was added because in the last release we removed the ability to truncate manually entered descriptions because we decided that if a user enters a description that is 500 characters long then that's what we should output. Users didn't like this and wanted a way to truncate their manual descriptions again. As of the last release, the Never Shorten Long Descriptions option only applies to auto generated descriptions.

@EkoJR
Copy link
Contributor Author

EkoJR commented Jan 18, 2018

@wpsmort Ah, I see what's going on now. The Auto-Gen Setting and Auto-Gen Content were separate, and had me a little confused...

That would change the filter, and building off the previous, at Code 1, then to more strict/optimal filters, Code 3.

Start at Code 3, if you can. If not, decrease.

My worry now is the what descriptions gets truncated; which seem to mainly be Pages and Posts.

Code 1

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

	$aioseop_desc = '';
	if ( ! empty( $post->ID ) ) {
		$aioseop_desc = get_post_meta( $post->ID, '_aioseop_description', true );
	}

	if ( 'on' !== $aioseop_options['aiosp_generate_descriptions']  &&  empty( $aioseop_options['aiosp_dont_truncate_descriptions'] ) ) {
		$description = substr( $description, 0, 320 );
	} elseif ( ! empty( $aioseop_desc ) ) {
		$description = substr( $description, 0, 320 );
	}

	return $description;
}

Code 2

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

	$aioseop_desc = '';
	if ( ! empty( $post->ID ) ) {
		$aioseop_desc = get_post_meta( $post->ID, '_aioseop_description', true );
	}

	if ( ! empty( $aioseop_desc ) ) {
		$description = substr( $description, 0, 320 );
	}

	return $description;
}

Code 3

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 );
		}
	}

	return $description;
}

@wpsmort
Copy link

wpsmort commented Jan 18, 2018

@eko Good news! Code 2 worked. I tested it with all the combinations of settings from under Advanced Settings and I tested it with different post types as well as a dynamic and static homepage.

@michaeltorbert This is ready for code review.

@eko
Copy link

eko commented Jan 18, 2018

Hello there, great news! I am just tagging the right @EkoJR for this conversation ;)

@michaeltorbert michaeltorbert merged commit 320efb4 into awesomemotive:development Jan 18, 2018
@EkoJR EkoJR deleted the i-1468-desc-update branch December 14, 2018 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants