sewpafly / post-thumbnail-editor

Wordpress Plugin to manually edit post thumbnails
http://wordpress.org/extend/plugins/post-thumbnail-editor/
32 stars 18 forks source link

Links broken due to error in pte_url() function #92

Closed kimbo6365 closed 10 years ago

kimbo6365 commented 10 years ago

In version 2.3.0, I saw this change introduced:

function pte_url( $id ){
-       $pte_url = admin_url('upload.php')
-               . "?page=pte-edit&pte-id="
-               . $id;
+function pte_url( $id, $iframe=false ){
+       if ($iframe) {
+               $pte_url = admin_url( 'admin-ajax.php' )
+                       . "?action=pte_ajax&pte-action=iframe&pte-id=${id}"
+                       . "&TB_iframe=true";
+       }
+       else {
+               $pte_url = admin_url('upload.php')
+                       . "?page=pte-edit&pte-id=${id}";
+       }

        return $pte_url;
 }

It looks like the syntax around the variables is interfering with Maven on my server, which is preventing me from being able to edit any thumbnails.

I changed the syntax from "${variable}" to {$variable} in both instances inside this function, and now everything works as it did before:

function pte_url( $id, $iframe=false ){
        if ($iframe) {
                $pte_url = admin_url( 'admin-ajax.php' )
-                       . "?action=pte_ajax&pte-action=iframe&pte-id=${id}"
+                       . "?action=pte_ajax&pte-action=iframe&pte-id={$id}"
                        . "&TB_iframe=true";
        }
        else {
                $pte_url = admin_url('upload.php')
-                       . "?page=pte-edit&pte-id=${id}";
+                       . "?page=pte-edit&pte-id={$id}";
        }

        return $pte_url;
sewpafly commented 10 years ago

Interesting, it looks like I need to do some research on php's string interpolation. Thanks, for the fix, I'll throw it in the next version

kimbo6365 commented 10 years ago

Yeah, it seems like it's probably just an obscure conflict between Maven and PHP variable interpolation. For what it's worth, it seems like I only had problems with the ${id} variable. When I actually opened the plugin PHP file from the server, the function looked like this:

function pte_url( $id, $iframe=false ){
    if ($iframe) {
        $pte_url = admin_url( 'admin-ajax.php' )
            . "?action=pte_ajax&pte-action=iframe&pte-id=com.[domain].wordpress:wp-contrib:jar:1.5-SNAPSHOT"
            . "&TB_iframe=true";
    }
    else {
        $pte_url = admin_url('upload.php') 
            . "?page=pte-edit&pte-id=com.[domain].wordpress:wp-contrib:jar:1.5-SNAPSHOT";
    }

    return $pte_url;
}

But the same syntax in another function, pte_media_row_actions(), left the variable ${pte_url} alone. So I think that Maven uses ${id} to refer to the Snapshot id, breaking this particular function.

I can't say there will be many (or any) other people using Maven and this plugin, but just in case, I wanted to give you a heads-up. :)