Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#27536 closed defect (bug) (invalid)

AJAX call returns all page errors along with plugin's response

Reported by: justin-folvarcik's profile Justin Folvarcik Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8.1
Component: General Keywords:
Focuses: javascript Cc:

Description (last modified by SergeyBiryukov)

I'm working on a plugin which uses AJAX to get the titles of a page from a user-given URL. Everything works fine... until I get to the server's response.

function t3_set_handlers(){
    var input = jQuery('[id^=post-source], [id^=post-via]');
    input.each(function(){
        jQuery(this).on('change', function(){
 
            var data = {
                action:'t3_get_url_title',
                url:jQuery(this).val()
            };
            var currentbox = jQuery(this);
            jQuery.post(ajaxurl, data, function(response, status, xhr){
                xhr.done(function(){
                    console.log(response);
                    //var name = jQuery().attribute('id').split('-');
                    //jQuery('#post-'+name[1]+'-title-'+name[2]).val(title);
                }).fail(function(){
                    // Something went wrong, so we'll turn off the AJAX and let the user know.
                    alert('AJAX error encountered! Failed to retrieve title. If this problem persists, please send an' +
                        'email to justin@zeldawiki.org describing the issue.');
                    input.off();
                });
            });
        });
    });
}
jQuery(t3_set_handlers());

In this code, the response variable should contain what the server sent back (IE: my current debug value, a JSON type string which is simply

{ "name":"value" }

However, this is what I'm seeing in my console right now.

<br />
<b>Warning</b>:  copy(/var/www/html/temple3/wp-content/ewww/jpegtran): failed to open stream: Permission denied in <b>/var/www/html/temple3/wp-content/plugins/ewww-image-optimizer/ewww-image-optimizer.php</b> on line <b>753</b><br />
<br />
<b>Warning</b>:  copy(/var/www/html/temple3/wp-content/ewww/jpegtran-custom): failed to open stream: Permission denied in <b>/var/www/html/temple3/wp-content/plugins/ewww-image-optimizer/ewww-image-optimizer.php</b> on line <b>766</b><br />
<br />
<b>Warning</b>:  fileperms(): stat failed for /var/www/html/temple3/wp-content/ewww/jpegtran-custom in <b>/var/www/html/temple3/wp-content/plugins/ewww-image-optimizer/ewww-image-optimizer.php</b> on line <b>770</b><br />
<br />
<b>Warning</b>:  chmod(): No such file or directory in <b>/var/www/html/temple3/wp-content/plugins/ewww-image-optimizer/ewww-image-optimizer.php</b> on line <b>773</b><br />
<br />
<b>Warning</b>:  copy(/var/www/html/temple3/wp-content/ewww/gifsicle): failed to open stream: Permission denied in <b>/var/www/html/temple3/wp-content/plugins/ewww-image-optimizer/ewww-image-optimizer.php</b> on line <b>787</b><br />
<br />
<b>Warning</b>:  copy(/var/www/html/temple3/wp-content/ewww/optipng): failed to open stream: Permission denied in <b>/var/www/html/temple3/wp-content/plugins/ewww-image-optimizer/ewww-image-optimizer.php</b> on line <b>800</b><br />
<br />
<b>Warning</b>:  copy(/var/www/html/temple3/wp-content/ewww/pngquant): failed to open stream: Permission denied in <b>/var/www/html/temple3/wp-content/plugins/ewww-image-optimizer/ewww-image-optimizer.php</b> on line <b>813</b><br />
<div id='ewww-image-optimizer-warning-tool-install' class='error'><p><strong>EWWW Image Optimizer could not install tools in /var/www/html/temple3/wp-content/ewww/.</strong> Please adjust permissions or create the folder. If you have installed the tools elsewhere on your system, check the option to Use System Paths. For more details, visit the <a href='options-general.php?page=ewww-image-optimizer/ewww-image-optimizer.php'>Settings Page</a> or the <a href='http://wordpress.org/extend/plugins/ewww-image-optimizer/installation/'>Installation Instructions</a>.</p></div>.{"name":"value"} 

I'm not saying these errors are bugs. I know what they're from, but what I do NOT understand is why these are being outputted along with my response. According to all the documentation I've seen and the other people I've spoken with, my code is correct. I'll even provide the PHP:

function t3_get_url_title(){
    if(is_admin()){
        echo json_encode(array('name' => 'value'));
        die();
    }
}

The only logical reason I can come up with for this is that WordPress is doing something it shouldn't be. Or maybe everything I've heard and read is wrong and you can tell me why. I am submitting this as a bug report because I truly believe this is a bug. I have spoken with other developers, checked my code against the documentation and even other, working code examples. My syntax should be correct.

I would appreciate it if either this issue could be investigated or someone can tell me why I'm stupid and can't get this to work. Thanks in advance.

Change History (8)

#1 @Justin Folvarcik
10 years ago

I forgot to note that I do have the AJAX hooked with add_action('wp_ajax_t3_get_url_title');

#2 @nacin
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hi Justin, thanks for the report. Based on the errors there, this doesn't look like a bug in WordPress. You should be able to find some assistance in the support forums: http://wordpress.org/support/.

#3 @Justin Folvarcik
10 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

Sorry, but I'm not convinced. I'm also not convinced that you even read the report.

Re-read the entire report, and see if you can come up with a feasible reason that an AJAX call to my specific script is returning errors from other plugins in the response.

#4 @helen
10 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

Admin AJAX loads up WP - if another plugin is throwing errors, it'll still throw errors there, too.

#5 @nacin
10 years ago

I read the report. I have no idea why your AJAX call is returning errors from other plugins, but it's likely either the AJAX code or the other plugins. Not WordPress.

Please try the support forums; if there is a bug in WordPress, this ticket can always be reopened, no harm, no foul.

Please also see http://codex.wordpress.org/AJAX_in_Plugins for more documentation. You might ultimately be doing it correctly, but add_action('wp_ajax_t3_get_url_title'); requires a second argument, for example.

#6 follow-up: @Justin Folvarcik
10 years ago

Maybe I'm coming off as a bit rude, but that's because I've spent five hours now trying to debug this and the only reply I got was "Thanks, but no. Please go ask somewhere else for help." I've noticed that another plugin we have that uses AJAX is also returning other plugin errors, and it's echoing them right onto the page.

If what Helen says is true, then the WordPress AJAX has a huge hole in it which allows errors to potentially cripple plugins. That seems like a pretty big oversight to me, and that in and of itself sounds like something that should be addressed. But for now, I suppose I'll relent. Sorry for snapping.

#7 in reply to: ↑ 6 @nacin
10 years ago

Replying to Justin Folvarcik:

Maybe I'm coming off as a bit rude, but that's because I've spent five hours now trying to debug this and the only reply I got was "Thanks, but no. Please go ask somewhere else for help." I've noticed that another plugin we have that uses AJAX is also returning other plugin errors, and it's echoing them right onto the page.

If what Helen says is true, then the WordPress AJAX has a huge hole in it which allows errors to potentially cripple plugins. That seems like a pretty big oversight to me, and that in and of itself sounds like something that should be addressed. But for now, I suppose I'll relent. Sorry for snapping.

Understood, and no problem. You may be interested in #26262, in that case. PHP's display_errors should never be run in production, and many developers will log them to a file, so this is only an issue when one of those things is not true and when a plugin is doing something particularly harmful.

#8 @SergeyBiryukov
10 years ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.