Support » Plugin: AMP » AMP Plugin Breaks Button Plugin

  • Resolved PayDelete

    (@paydelete)


    I recently received a report of the AMP plugin running on a page featuring the DeadDelete Plugin. Reportedly the AMP Plugin rewrote output of DeadDelete causing the from and input tags not to render properly, caused the page layout to break, and caused the button to function improperly when clicked.

    I developed DeadDelete and would like to know what I can do to make DeadDelete work with AMP.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter PayDelete

    (@paydelete)

    So far the best things the user can do to use AMP with DeadDelete is disable AMP for posts.

    Plugin Support Milind More

    (@milindmore22)

    Hello @paydelete

    Thank you for the support topic, As I tested your plugin for AMP compatibility I did find some issues, the issues occur on non-AMP pages too.

    1) Notice:
    Notice: is_singular was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.0.) in wp-includes/functions.php on line 5663

    It can be fixed by removing a line of code from deadelte.php also it’s not needed.
    apply_filters('the_content', 'deaddelete_deleteButton');

    2) Warning:
    Warning: DOMDocument::loadHTML(): Tag figure invalid in Entity, line: 14 in wp-content/plugins/deaddelete/deaddelete.php on line 93
    it’s worth adding a isset() or ! empty() check

    you can also customize success and error messages by adding additional tags conditionally using amp_is_request function

    eg:

    $tagarray = array( 'form' => array('name' => array(),'method' => array(),'id' => array()), 'input' => array('type' => array(),'name' => array(),'value' => array()));
    			if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
    				$tagarray['div'] = array(
    						'submit-success' => array(),
    						'submit-error'   => array(),
    					);
    				$tagarray['template'] = array(
    						'type' => array(),
    					);
    				$buttonHtml = wp_kses('<form name="post" method="post" id="post"><input type="submit" name="removepost" value="Remove Dead Link" /><div submit-success><template type="amp-mustache">Links Removed successfully, Pleaase refresh!</template></div><div submit-error><template type="amp-mustache">Links Removal failed!</template></div></form>',$tagarray);
    			} else {
    				$buttonHtml = wp_kses('<form name="post" method="post" id="post"><input type="submit" name="removepost" value="Remove Dead Link" /></form>',$tagarray);
    			}

    I am not sure how the plugin should work/function but it will be good practice to restrict non-admin users from deleting posts or it can be exploited to remove other posts.
    eg: adding something like is recommended.

    
    if ( ! current_user_can( 'manage_options' ) ) {
     return;
    }
    
    Thread Starter PayDelete

    (@paydelete)

    @milindmore22 thanks for the reply. The plugin works by allowing any user to delete posts from aggregators if the source URL return a 404 error. It is designed to be used by feed aggregators that feature source attribution links in their posts. In order for a post to be removable that link must return a 404 status code or a 301 to a 404.

    Thread Starter PayDelete

    (@paydelete)

    @milindmore22 if I change line 93 to

    if(!empty($dom))

    Won’t the new DOMDocument() always be empty at that point?

    Thread Starter PayDelete

    (@paydelete)

    @milindmore22 You code has the same problem that the default AMP code has. When the button is clicked and an error has to be echo’d out it considers a successful click of the button a success regardless of the result. If I click the button and the post is not deleted then I still get an AMP success message. This is obviously because at that point the click is a success regardless of how it is processed. How do I echo an error in AMP format?

    See the parts of my code that create a strong element with a message based on the http status code of the source link after the button is pushed? I need the AMP message to be the same. I’m thinking maybe of just using a div tag there and forego using the so called mustache at all.

    • This reply was modified 1 month, 4 weeks ago by PayDelete.
    Thread Starter PayDelete

    (@paydelete)

    Even when I replace the strong element with div tags they still don’t show up when I click the button. It seems like only the AMP formatted stuff shows up.

    Plugin Support Milind More

    (@milindmore22)

    Hello @paydelete

    Please give me some time to set up a demo site, additionally please share your plugins repo link, where we can contribute (github)

    Thread Starter PayDelete

    (@paydelete)

    @milindmore22 I just created my first repo and uploaded the plugin code. From what I’ve read I need to allow you access to do that since its a private repo.

    Plugin Support Milind More

    (@milindmore22)

    Hello @paydelete

    Yes you can send me an invite using my GitHub ID milindmore22, in case your plugin is non-commercial (has GPLv2 license) you can also make the repo public so others can also report issues or contribute by forking that repo.

    Plugin Support Milind More

    (@milindmore22)

    Hello @paydelete

    I have accepted an invitation to contribute to your plugin to make AMP compatible, I will start contributing from 18th Oct (Monday), I will mark this topic as resolved, we can discuss further on GitHub issues or on Merge Requests on Repo.

    I will mark this topic as resolved, feel free to open a new support topic if you require further assistance using the AMP plugin.

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.