[wp-trac] [WordPress Trac] #31010: Frontend / Admin specifications for AJAX

WordPress Trac noreply at wordpress.org
Wed Jan 14 14:25:35 UTC 2015


#31010: Frontend / Admin specifications for AJAX
--------------------------+-----------------------------
 Reporter:  danielpataki  |      Owner:
     Type:  enhancement   |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 I recently ran into an issue, not sure where this belongs exactly. If you
 load posts in Twenty Fifteen via AJAX (by detecting pagination clicks) the
 images will be narrower, take a look:

 http://cl.ly/image/2M15133q2U1D

 This happens because when an image is shown, somewhere down the line the
 image_constrain_size_for_editor() function is called which is in
 media.php. If a context is not given it uses is_admin() to detect where
 the request is from.

 The problem is that admin-ajax.php is always considered to be in the
 admin, since it technically is. However, the AJAX request comes from the
 front-end and the response is used on the front end as well. Here is one
 method to get around this problem:

 {{{
 $posts = new WP_Query( $query_vars );
 add_filter( 'editor_max_image_size', 'my_image_size_override' );
 if( ! $posts->have_posts() ) {
     get_template_part( 'content', 'none' );
 }
 else {
     while ( $posts->have_posts() ) {
         $posts->the_post();
         get_template_part( 'content', get_post_format() );
     }
 }
 remove_filter( 'editor_max_image_size', 'my_image_size_override' );
 }}}

 This could also be addressed by providing a parameter that is passed to
 admin-ajax. Just as action is used to transfer the action, another
 parameter could be added to indicate the origin. I'm not a huge AJAX
 expert and I'm not sure if this causes any security issues so I am
 refraining from adding any patches. Aside from the security issue I assume
 this would affect a lot of functions.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/31010>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list