Archive for the ‘ Wordpress ’ Category

Fix “PHP Fatal error: Call to undefined function get_header()” error in WordPress

Taken from http://www.ardamis.com/2011/06/02/fix-for-php-fatal-error-get_header-in-wordpress/

While making changes to my WordPress theme, I noticed that the error_log file in my theme folder contained dozens of PHP Fatal error lines:

[01-Jun-2011 14:25:15] PHP Fatal error:  Call to undefined function  get_header() in /home/accountname/public_html/ardamis.com/wp-content/themes/ars/index.php on line 7
[01-Jun-2011 20:58:23] PHP Fatal error:  Call to undefined function  get_header() in /home/accountname/public_html/ardamis.com/wp-content/themes/ars/index.php on line 7

The first seven lines of my theme’s index.php file:

<?php ini_set('display_errors', 0); ?>
<?php
	/*
	* @package WordPress
	* @subpackage Theme
	*/
	get_header();
?>

I realized that the error was being generated each time that my theme’s index.php file was called directly, and that the error was caused by the theme’s inability to locate the WordPress get_header function (which is completely normal). Thankfully, the descriptive error wasn’t being output to the browser, but was only being logged to the error_log file, due to the inclusion of the ini_set(‘display_errors’, 0); line. I had learned this the hard way a few months ago when I found that calling the theme’s index.php file directly would generate an error message, output to the browser, that would reveal my hosting account username as part of the absolute path to the file throwing the error.

I decided the best way to handle this would be to check to see if the file could find the get_header function, and if it could not, simply redirect the visitor to the site’s home page. The code I used to do this:

<?php ini_set('display_errors', 0); ?>
<?php
/**
* @package WordPress
* @subpackage Ars_Theme
*/
if (function_exists('get_header')) {
	get_header();
}else{
    /* Redirect browser */
    header("Location: http://www.ewea.org/SITENAME/");
    /* Make sure that code below does not get executed when we redirect. */
    exit;
}; ?>

Executing WordPress shortcodes

By default, WordPress shortcodes can only be used in pages, posts and widgets.
If you want to include a shortcode for a cool plugin, or a special functionality you need, in your WordPress Template for example, you can use the following code to make it happen.

<?php echo do_shortcode('[shortcode goes here]'); ?>

WordPress subnavigation accordian

See official documentation here:
http://codex.wordpress.org/Function_Reference/wp_list_pages

 

This here is the most interesting part (towards the bottom):

They can be styled with CSS selectors:

.pagenav { … } /* the outermost list item; contains whole list */
.page-item-2 { … } /* item for Page ID 2 */
.page_item { … } /* any Page item */
.current_page_item { … } /* the current Page */
.current_page_parent { … } /* parent of the current Page */
.current_page_ancestor { … } /* any ancestor of the current Page */

In order to achieve an accordion menu effect for instance, the following CSS can be used:

.pagenav  ul ul,
.pagenav .current_page_item ul ul,
.pagenav .current_page_ancestor ul ul,
.pagenav .current_page_ancestor .current_page_item ul ul,
.pagenav .current_page_ancestor .current_page_ancestor ul ul {
display: none;
}
.pagenav .current_page_item ul,
.pagenav .current_page_ancestor ul,
.pagenav .current_page_ancestor .current_page_item ul,
.pagenav .current_page_ancestor .current_page_ancestor ul,
.pagenav .current_page_ancestor .current_page_ancestor .current_page_item ul,
.pagenav .current_page_ancestor .current_page_ancestor .current_page_ancestor ul { 
display: block;
}

Restoring a single database from a complete MySQL database dump

Found here.

I had a collection of database dumps from a server that had been created using MySQL’s –all-databases option. This contained the databases for several Drupal websites, but I wanted to restore the Drupal database for just one of the sites. After a bit of Googling I came across two simple solutions:

The first option is to pass the whole SQL dump to MySQL command line, but restrict it’s operation using the “–one-database” option.

mysql -u root -p --one-database oneDB < fulldump.sql

In the above code substitute oneDB with the database name you want to restore, and fulldump.sql with the name of your full DB backup. If you would rather just extract the database dump of the single database from the –all-databases dump file, you can do this with sed using this command:

sed -n '/^-- Current Database: `oneDB`/,/^-- Current Database: `/p' fulldump.sql > oneDB.sql

Where dbname is replaced with the database name of the database to extract, and alldatabases.sql is the name of your dump file. The result will be saved into the file oneDB.sql.

Changing a WordPress password with PhpMyAdmin

Stolen from http://codex.wordpress.org/Resetting_Your_Password

This article is for those who have phpMyAdmin access to their database. Note: use phpMyAdmin at your own risk. If you doubt your ability to use it, seek further advice. WordPress is not responsible for loss of data.

Begin by logging into phpMyAdmin and click databases.

Image #2

  • A list of databases will appear. Click your WordPress database.

Image #3

  • All the tables in your database will appear. If not, click Structure.
  • Look for wp_users.
  • Click on the icon for browse.
  • Locate your Username under user_login
  • Click edit

Image #4

  • Your user_id will be shown, click on Edit
  • Next to the user_pass is a long list of numbers and letters.
  • Select and delete these and type in your new password.
  • Type in the password you want to use. Just type it in normally, but remember, it is case-sensitive.
  • In this example, the new password will be ‘rabbitseatcarrots’
  • Once you have done that, click the dropdown menu indicated, and select MD5 from the menu.

Image #5

  • Check that your password is actually correct, and that MD5 is in the box.
  • Click the ‘Go’ button to the bottom right.
  • Test the new password on the login screen. If it doesn’t work, check that you’ve followed these instructions exactly.

Contact Form 7 options

When using Contact Form 7 in WordPress, you may need to add a hidden identifier, like the submitters IP address.

This is easily done by adding [_remote_ip] into the email template.

 

More tags here: http://contactform7.com/special-mail-tags/

Jump to top of iframe

When you want to have the page jump to the top of an iframe upon clicking “Next” or “Submit”, etc, you can easily use this code:

<iframe width="620" scrolling="no" height="2500" frameborder="0" style="background-color: transparent; overflow: hidden;" allowtransparency="true" src="http://www.website.com" onload="window.parent.parent.scrollTo(0,0);"></iframe>

WordPress new user

Hello USERNAME,

To access the back-end for editing and updating:

  • Admin: http://events.ewea.org/annual2012/wp-admin/
  • Username: USERNAME
  • Password: UN12345

What do do next?

Online documentation

There is a world of excellent documention for wordpress.

 

Kind regards,

Jason Bickley

WordPress Plugins for EWEA

Here is a list of plugins I am using for EWEA WordPress websites..

  • Contact Form 7
  • FD Feedburner Plugin
  • Google Analytics for WordPress
  • Google XML Sitemaps
  • PHP Execution
  • Random Text
  • Redirection
  • User Role Editor
  • W3 Total Cache
  • WordPress SEO
  • WP-FileManager
  • WP Realtime Sitemap
  • WPtouch
  • Yoast Breadcrumbs

Google Syntax Highligher

I found a new plugin today for WordPress; “Google Syntax Highlighter”.
It formats your source code pastings on the fly.

Here’s a test below:

<?php

$fp = fopen("$datafile","a"); // Open datafile

if(!$fp) {
 echo "Error: Cannot open file.";
 exit;
}

fwrite($fp, $fname."|$|".$lname."|$|".$org."|$|".$country."|$|".$date."|$|".$ipadd."|$|".$usagent."\r\n");
fclose($fp);

header("Location: http://" . $_SERVER['SERVER_NAME'] . "/offshore/db/thanks.php"); /* Redirect browser */
exit;
?>