Showing posts with label bugs. Show all posts
Showing posts with label bugs. Show all posts

2014-02-26

"An error occurred in the upload..." (WordPress Media)

Seeing "An error occurred in the upload..." message when calling WP Media interface on the front?

I believe, that's a core problem, but here is a workaround that I am using quite often in my projects.

Admins won't have this bug, but regular users - will. Because we are on a page, which $post was not created by this regular user, so he does not have the editing capabilities... and Media needs them.

// Preserve the current Post
// (just in case, you may not need it)
$oldPost = $GLOBALS['post'];
// Make it a dummy
$GLOBALS['post'] = 0;

// For example, the editor, with "Media" button:
wp_editor($content, $editor_id, $settings);
// Or "Upload Avatar" code from the WPUA plugin
do_action( 'show_user_profile', $current_user );

// Restore
$GLOBALS['post'] = $oldPost;

// Be happy

2011-12-19

IE7 text-indent bug

I've been debugging an HTML/CSS combination that was supposed to show a button with a nice background while keeping the button text still available (for accessibility, SEO, etc. - have no idea, the code wasn't mine). Users with IE7 (sigh) could not see the button.

The bottom line: there is a situation when IE7 moves the parent element together with its text, having a text-indent CSS rule. Below is a code demonstrating this behavior:

<!DOCTYPE html>
<html>
<head>
<style>
.notxt {
width: 100px;
text-indent: -9000px;
}
</style>
</head>
<body>
<!-- This button will be shown with no text, AS EXPECTED -->
<form>&nbsp;
<button class="notxt">AAAAA</button>
</form>
<!-- This button will not be shown at all -->
<form>
<button class="notxt">AAAAA</button>
</form>


</body>
</html>


Note the &nbsp; between the form and button tags in the first form. This is the "cure" for the IE7 bug. Any text will work, including <br>.

See also a solution that did NOT work for me but might work in some other related cases:
http://css-tricks.com/snippets/css/remove-button-text-in-ie7/

2010-05-06

PDO bug: exception caught but reappears in foreach() loop

I was experimenting with PDO/MySQL trying to see how a PHP code will behave with a single static DB connection, multiple connections but declared as "persistent", unbuffered MySQL queries and so on - and discovered a bug which I'd like to show here, because it took me a while to find any reference to it.
I tested it with PHP 5.2.13 under both UNIX and Windows.
Below is the code that demonstrates the problem, and two solutions/workarounds:

#
# PDO foreach exception bug
# Demonstration code
# Author: http://www.tiv.net
# 2010-05-06
#
# Note: same results will appear if using "while fetch()"
# instead of "foreach()" loop
#

print 'This code works OK (Exception is cleaned artificially)
';
$conn = new PDO( 'mysql:host=localhost', 'test', 'test' );
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$oRS = $conn->query( "select 'OK'" );
foreach ( $oRS as $row ) {
    try {
        $conn->query( 'Bogus SQL' );
    } catch (PDOException $e) {}
    if ( $conn->errorCode() !== '00000' ) {
        $conn->query( "select 'CLEAN_PDO_ERROR'" );
    }
print 'NO exception will be thrown.
';
}

print 'This code works OK (two separate connections)
';
$conn = new PDO( 'mysql:host=localhost', 'test', 'test' );
$conn2 = new PDO( 'mysql:host=localhost', 'test', 'test' );
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$oRS = $conn->query( "select 'OK'" );
foreach ( $oRS as $row ) {
    try {
        $conn2->query( 'Bogus SQL' );
    } catch (PDOException $e) {}
print 'NO exception will be thrown.
';
}


print 'This code throws unexpected exception in foreach
';
$conn = new PDO( 'mysql:host=localhost', 'test', 'test' );
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$oRS = $conn->query( "select 'OK'" );
foreach ( $oRS as $row ) {
    try {
        $conn->query( 'Bogus SQL' );
    } catch (PDOException $e) {}
print 'Exception will be thrown after this...
';
}
?>