• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

My Monkey Do

A Log of Coding Solutions

  • Home
  • Web Hosts
  • Tools
  • About

debug

Cannot redeclare class require_once

June 12, 2012 by Webhead

Problem

I’m using classes and making each class a file. when I’m including dependet classess, I use require_once to avoid multiple declarations – yet I get a Fatal error: Cannot redeclare class…

 

Solution

Make sure all files that require the class have require_once and also make sure that the path that is required is the same case in all situations.  For example, my problem was that I was including a “/Users/name/xxx.php” and “/users/name/xxx.php”.  These paths are different and so PHP includes both of these.

 

keywords: Cannot redeclare class require_once
source: http://bytes.com/topic/php/answers/461064-require_once-doesnt-work-cannot-redeclare-class

 

Filed Under: Coding Tagged With: debug, php

Other Languages showing as ??? in WordPress

May 29, 2012 by Webhead

Problem

I copy-pasted some Japanese text into the WordPress editor and it shows as ????.  On another server, pasting the same japanese text shows the japanese text on the page.  No plugins seem to be affecting this.  Something with the server or WordPress configuration must be affecting displaying the foreign characters.

Solution

The problem was caused by using the Fantastico automatic install from the cpanel.  When Fantastico installs wordpress all the fields in the database have a data type of “latin1_swedish_ci”.  Using this data type, characters like Japanese and Chinese are not supported.  You’ll need to change the data type of the fields to “utf8_general_ci”.  I changed post_title, post_content, and post_excerpt fields in wp_posts and it seems to be enough.  It depends how much you will have foreign characters though, you may have to change more fields.  More info can be found in the source below.

 

Source: http://wordpress.org/support/topic/special-characters-converted-to-question-marks-on-save
keywords: wordpress not saving japanese characters

Filed Under: Coding Tagged With: debug, wordpress

WordPress debugging

May 25, 2012 by Webhead

Some useful tips for debugging wordpress will be listed here for future reference.

Display All Hooks

If you need to display all hooks, use the command below.  It is useful when trying to find a hook to alter some part of wordpress.

add_action( 'all', create_function( '', 'var_dump( current_filter() ); ' ) );

Display all for a Specific Hook

use the following code:

global $wp_filter;
print_r($wp_filter[$hook_name]);

Display Queries

To display any queries run by wordpress you can set SAVEQUERIES to be true and then print out the queries.

define( 'SAVEQUERIES', true );

Then place the following right after your query:

var_dump($wpdb->queries);exit;

 

Filed Under: Coding Tagged With: debug, php, wordpress

WordPress Deactive Plugin

April 5, 2012 by Webhead

Problem

I had a wordpress site where the public side was fine, but the admin side was throwing a Internal Server Error 500 intermittently.   I couldn’t figure out what was wrong since I had done no changes, and my host said nothing was wrong with the server.  To solve mysterious crashing errors in WordPress, the standard procedure is to first deactivate all your plugins.  However, I could not log in, so how was I to deactivate them?

Solution

A very smart fellow on the wordpress.org forums suggested to log into phpMyAdmin, and look at the wp_options table.  Then look for ‘active_plugins’ string under the option_name field.  Once located, change the option value to  a:0:{}

This deactivates all plugins.  Once deactivated, I re-activated each plugin and found the culprit.  It turned out the plugin was contacting its creator’s server and the creator’s server was down at the time.

source: http://wordpress.org/support/topic/500-internal-server-error-wp-admin-only

Filed Under: Coding Tagged With: debug, mysql, wordpress

iPhone Viewport and position absolute

January 20, 2012 by Webhead

Problem

I have a div with id “stripe” that is using absolute positioning to be at the top of the page and span 100% of the page width.  It overlays the top part of the website.  The rest of my page is 1000px wide.  When viewing on the iPhone, the “stripe” div is only a portion of the screen width.  Why?

 

Solution

If you debug the website for the iPhone, you’ll see that the width of the “stripe” dive is only 320px.  Sound familiar?  That’s because the width of the iPhone is 320px and so 100% of the viewport is 320px according to the iphone.  There are many possible solutions for this.  One solution is to make the “stripe” div’s position relative.  The relative allows the 100% width expand the entire 1000px .  Then in the following div set the margin-top to negative of whatever the “stripe” div’s height is.

Filed Under: Coding Tagged With: css, debug, firebug, iPhone

Firebug

May 14, 2011 by Webhead

I don’t know how I used to develop web pages before Firebug.  It is the single best tool you can have when debugging a webpage.  If something doesn’t look right I open Firebug and find out what styles are being inherited.  If some javascript functionality is not working I open Firebug and enter debug statements.   If some ajax call is messing up and the page isn’t showing the response correctly, I open Firebug.

Installation

The best thing about Firebug is how much time it saves you on debugging.  Even better than it being free.  That’s a lot considering how I watch my money.   I only use Firebug with Firefox.  It can be downloaded at https://addons.mozilla.org/en-us/firefox/addon/firebug/.  What’s good is that it’s available on both Mac and PC.   Just click on the Add to Firefox button and it’s mostly done for you.  That easy.  A firebug was also developed for IE but I haven’t tried it recently.  I tried it a couple years ago and it didn’t help me very much so I stuck with just using the Firefox one.

CSS

When you need to see why an item on a webpage is not showing as its supposed to you can right click on it and select “Inspect Element”.  Doing this opens up the firebug window and it will tell you exactly what styles are being applied to it and what styles have been overwritten.  You can even change the values of anything you want to see the outcome in real-time.

Javascript

Browsers can tell you the last error code that happened, but firebug can let you watch expressions, look at the stack, insert breakpoints, and print out statements in the console.

Request / Response

Any and all requests to the server can be inspected on the Net tab.  You can see each javascript include file, each image, each ajax request.  This means that if an ajax call goes wrong, you can inspect the parameters that were sent and the response the page got back from that request.  It makes debugging a breeze.

Firebug can be downloaded here: http://getfirebug.com/

Filed Under: Tools Tagged With: css, debug, firebug, html, javascript

  • « Go to Previous Page
  • Go to page 1
  • Go to page 2

Primary Sidebar

Topics

apache apple block editor chrome cms css debug eCommerce embed firebug firefox git gmail goDaddy google hosting htaccess html html 5 IE crap image iPad iPhone javascript jquery linux localization mac os x ms sql mysql open source optimize php php 5.3 responsive rest api seo svg tinymce woocommerce wordpress wpengine xss yii youtube




Categories

  • Coding
  • Off the Shelf
  • Plugins
  • Random Thoughts
  • Server Stuff
  • Tools