• 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

php

WordPress “The plugin generated xxxx characters of unexpected output during activation”

September 11, 2012 by Webhead

Problem

I was developing a plugin for wordpress and receive a messsage:

The plugin generated 496 characters of unexpected output during activation

Solution

I placed the following code at the end of my plugin file,

update_option(‘plugin_error’,  ob_get_contents());

then looked in the wordpress options table using the query

“SELECT *
FROM `wp_options`
WHERE option_name = ‘plugin_error'”

Then I could see what the unexpected output was.

Or I could’ve installed the WH Debug plugin and just added this to the end of the plugin file:

wh_debug( ‘plugin_error’, ob_get_contents());

And then viewed it in the WordPress admin pages under Tools->WH Debug.

 

source: http://hungrycoder.xenexbd.com/wordpress-2/how-i-have-solved-the-the-plugin-generated-xxxx-characters-of-unexpected-output-during-activation-problem.html

keywords: wordpress characters of unexpected output during activation

 

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

Insert HTML into PHP DOM object

August 30, 2012 by Webhead

Problem

I recently had an html string that needed to be added to a DOM object.   At first I had something like this:

$dom = new DOMDocument;
$field_div = $dom->createElement(“div”, $field);
$dom->appendChild($field_div);

Where $field was an html string.  This produced a div with the html printed out as text.

Solution

Stack overflow is just the best website ever created for developers.  The solution is to use DOM->createDocumentFragment.  So the new code looked like:

$field_html = $dom->createDocumentFragment(); // create fragment
$field_html->appendXML($field);
$field_div = $dom->createElement(“div”);
$field_div->appendChild($field_html);

source: http://stackoverflow.com/questions/2255158/how-do-i-insert-html-into-a-php-dom-object
keywords: php domnode create node from html string

Filed Under: Coding Tagged With: php

Contact Form 7 Multi-Step Forms

August 8, 2012 by Webhead

UPDATE:  This plugin still works as expected for most people, but if it doesn’t work for you, I have found a great alternative that I personally use for larger projects: Formidable Pro.  Formidable allows multi-page forms, ajax submissions, and more.  It does so much more than Contact Form 7 and Contact Form 7 Multi Step Forms.  There is a free and a paid version.  The paid version is very cheap for what you get.  In my opinion it is much better than the more expensive Gravity Forms.

My first official wordpress plugin is one that modifies the Contact Form 7 plugin.  And yes, you’ll need the Contact Form 7 plugin activated in WordPress.   I needed a contact form that spanned across multiple pages and in the end would send an email with all the info collected.  Here are the steps to use it once it’s installed.

  1.  Create a contact form 7 form as you normally would.
  2.  Add a hidden tag named “step” with the value being the current step dash (“-“) total steps. If you have a 5-step form and you are creating the first step, the hidden field would look like: [hidden step “1-5”]
    the last step, would look like: [hidden step “5-5”]
  3.  In the “Additional Settings” textarea at the bottom of the form editing page, add in the location of the next form.
  4. If the next form is located on My2ndPage on example.com you would add the following to the “Additional Settings” textarea:  on_sent_ok: “location.replace(‘http://example.com/My2ndPage/’);”
  5.  Repeat steps 1 – 3. On the form that will actually send a email, do not do step 3 unless you want the form to redirect the user to another page.

A working sample can be seen at:
http://webheadcoder.com/contact-form-7-multi-step-form/

Get the Contact Form 7 MultiStep Forms in the WordPress Repository.

 

 

Filed Under: Coding Tagged With: php, wordpress

Extending Contact Form 7

August 8, 2012 by Webhead

Contact Form 7 is a wordpress plugin that allows users to easily put forms into wordpress pages.  These forms are very basic, but very extensible.  I recently had a task to change Contact Form 7 to be a 2-step form.  In doing this I found a lot of hooks and help.  In the end created my first official wordpress plugin.

Posts explaining how to send a form to another form:  http://wordpress.org/support/topic/plugin-contact-form-7-use-cf7-with-action-another-wp-page

Guide to customization: http://hecode.com/easy-contact-form-7-guide-and-customization/

Add a hidden field: http://wordpress.org/extend/plugins/contact-form-7-modules/

 

Filed Under: Coding Tagged With: php, wordpress

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

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

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 3
  • Go to page 4
  • Go to page 5
  • Go to page 6
  • Go to page 7
  • Go to page 8
  • Go to Next Page »

Primary Sidebar

Topics

apache apple bootstrap buddypress chrome cloudways cms css debug drupal eCommerce firebug firefox git gmail goDaddy google hosting htaccess html html 5 IE crap image iPad iPhone javascript jquery kinsta linux localization mac os x ms sql mysql open source optimize php php 7.2 svg tinymce woocommerce wordpress wpengine xss yii youtube




Categories

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