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

Remove warnings and notices #2154

Closed
andremacola opened this issue Apr 21, 2019 · 12 comments
Closed

Remove warnings and notices #2154

andremacola opened this issue Apr 21, 2019 · 12 comments

Comments

@andremacola
Copy link

How to remove all the warnings and notices from the post edit page? Classical and Block editor.

@amedina
Copy link
Member

amedina commented Apr 21, 2019

Which notices are you referring to? Please provide screenshots or other pointers.

@westonruter
Copy link
Member

If referring to the AMP validation error warnings, the way to hide them is to accept the validation errors.

@amedina We may want to make that explicit in the warning. I realize that we may not explain how to get rid of that warning. Currently it says:

There is 1 issue from AMP validation which needs review. 1 issue is directly due to content here. However, your site is configured to automatically accept sanitization of the offending markup. Review issues

This could be amended with more details.

@andremacola Please confirm the notices you are referring to.

@andremacola
Copy link
Author

andremacola commented Apr 21, 2019

@westonruter yes this is the notices.

I work for a relative big newspaper and this notices is annoying for the journalists. I think they need to appear (in our case) only for developers and the main editor.

We had some hard-working to migrate all of our system to Gutenberg, the journalists (specially the old ones) don't care about blocks and this kind of technical notice, they just want to write their text.

What I am doing right now is using get_amp_validation_error action to return false on post screens, but I do not known if this is the right solution. I miss some kind in-depth documentation.

Captura de Tela 2019-04-21 às 16 39 49

@westonruter
Copy link
Member

Wouldn't it be important for the writers to know that some of the blocks they are authoring are going to be stripped from the AMP page? It seems an important tool for them to report a block problem to you.

Also, what are the validation errors you are seeing? Can't you mark the validation errors as accepted and then the writers won't see the warnings anymore?

@andremacola
Copy link
Author

andremacola commented Apr 21, 2019

Not all the writers. Just the editors.

The editor in our case is the guy who manage the team, approve the content and publish to the home and other types of media like a physical newspaper.

One of the notices is the video embed from the other ticket and some of our own stuff that for now is not amp compatible.

@westonruter
Copy link
Member

OK, I think if we can fix the problem with #2156 then I can share a couple other filters which will reduce the noise for the validation errors that you are getting. Namely, the amp_validation_error filter can be used to normalize the validation errors (to reduce duplicates) and the amp_validation_error_sanitized filter can be used to programmatically accept sanitization and thus bypass the warning notice.

@andremacola
Copy link
Author

Nice. get_amp_validation_error hook is solving the problem for now. It's time to translate the plugin to my language now.

Thks for the help @westonruter

@westonruter
Copy link
Member

@andremacola You mean the amp_validation_error hook, right?

Would you mind sharing examples of how you are using it? This would be helpful to know how useful it is for developers.

@andremacola
Copy link
Author

andremacola commented Apr 22, 2019

@westonruter actually is get_amp_validation_error. I do not remember where I saw this, I think I got from a global wp_filter

It's very simple by the way. It's like:

add_action('get_amp_validation_error', 'onyx_amp_disable_notices', 10, 1);
function onyx_amp_disable_notices($args) {
	global $typenow;
	if ( $typenow == 'post' && !current_user_can('manage_options') ) {
		return false;
	} else {
		return $args;
	}
}

I'll check the amp_validation_error

@westonruter
Copy link
Member

@andremacola I don't see get_amp_validation_error anywhere in the codebase. I don't see how your code snippet would work.

The intended usage of the amp_validation_error filter is like this:

Given you have some HTML like this:

<iframe src="https://example.com/video/12345" onload="Foo.loaded(this)"></iframe>

Consider 12345 being a video ID that is unique. This would have a validation error that looks like this:

image

Now consider you have thousands such iframes, where the src is different for each. Without doing anything, there would be thousands of unique validation errors because a validation error includes the attributes of the invalid element. For example:

{
    "element_attributes": {
        "src": "https://example.com/video/12345",
        "onload": "Foo.loaded(this)",
        "sandbox": "allow-scripts allow-same-origin",
        "height": "400",
        "layout": "fixed-height"
    },
    "node_name": "onload",
    "parent_name": "amp-iframe",
    "code": "invalid_attribute",
    "type": "js_error"
}

So what is needed is to normalize the error across all instances. And this can be done in this example as follows:

add_filter(
	'amp_validation_error',
	function ( $error ) {
		$video_base_url  = 'https://example.com/video/';
		$is_video_iframe = (
			isset( $error['node_name'], $error['parent_name'], $error['element_attributes']['src'] )
			&&
			'onload' === $error['node_name']
			&&
			'amp-iframe' === $error['parent_name']
			&&
			substr( $error['element_attributes']['src'], 0, strlen( $video_base_url ) ) === $video_base_url
		);
		if ( $is_video_iframe ) {
			// Normalize URL across validation errors.
			$error['element_attributes']['src'] = $video_base_url . '{id}';
		}
		return $error;
	}
);

Now with this in place, every validation error for every such video iframe will look like this instead:

image

And now you can just accept this one validation error once and every other instance of the validation error will have that same status, and the writer will not be shown a validation error in the editor.

This is the intended usage of the amp_validation_error filter.

@andremacola
Copy link
Author

andremacola commented Apr 22, 2019

hey @westonruter I known, I searched inside the plugin files and did not find the get_amp_validation_error. I really do not remember where I saw this. I think I was debugging wordpress filters and hooks inside admin and I saw this.

hook2

I'll try to find again when the time permit.

I just want to disable all kind of warnings from some kind os users, and believe, the simple little hook it just works for me.

@westonruter
Copy link
Member

We're going to work toward making the warnings more user-friendly for non-administrators, including providing them a way to easily escalate the issue to the administrator. See #2316.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants