Pages

Thursday, July 30, 2015

Connection Timed-out

When your server reaches maximum usage and uses up all the server resources, this error usually pops up. The problem could be hidden in one of the themes and plugins that you are using.

Solution

It is advisable to start switching to default theme and see if the problem persists. If the problem continues, try to deactivate all plugins and activate one plugin after another to detect which plugin is resulting in this resource utilization. If you detect the plugin that is causing this problem, there are chances that this plugin uses more memory resources from your hosting server.

The ideal way to fix this issue is to first consider if the plugin in question is worth using all the resources – meaning, is it coded properly enough to justify the usage of the server resources. If yes, then you can ask your hosting provider to increase the memory limit or the memory execution time. If you already have the access to php.ini, then you can increase the memory execution time on your own using this code:

max_execution_time = 60;

Alternatively, you can also edit the .htaccess file and add this line:

php_value max_execution_time 60


If you edit .htaccess, make sure you update your permalinks by going to Settings in WordPress dashboard.

Wednesday, July 29, 2015

How to fix "Call to Undefined Function" in WordPress?

If you happen to get an error message with the words “Call to Undefined Function”, then you are in for a serious business to dig out a little further the culprit function.

Solutions for "Call to Undefined Function"

You need to understand that this error usually appears in four different circumstances. You need to determine which one of them will likely be the situation in your case.

  1. 1. Installing a new theme or plugin: When installing a new plugin or a new theme, you need to check if it is compatible with current version of WordPress. Most likely the Call to Undefined Function error shows up because the theme or plugin there might be some functions that use some related functions of an old WordPress version and hence cannot be defined. The error message usually points out the line number and the file name. This is the starting point to fix. You need to understand why such code was used in that line and see the possibility of modifying it or rather removing it altogether.  

  
  1. 2.       Auto-Upgrading Theme or Plugin: It may so happen that such errors can occur during auto-upgrading a theme or plugin. In such cases, first delete the theme or plugin and try to reinstall the updated version manually.


  1. 3.       Installing Multisite plugin on a single site: Some multisite plugins do not work on single sites because they are specifically designed to work on multi-site. Likewise, some single site plugins do not work on multisites. This is because the functions in one installation may not be defined for another type of installation. If this is the case, then make sure you install the right plugin for the right type of installation.


  1. 4.       Function does not exist: If you delete a function or a file within a theme or a plugin folder, then there is a high likelihood that you will get a ‘call to undefined function’. To debug this, you need to follow the error message carefully to see which function or file it is calling and throwing this error. Although it needs a deeper investigation, sometimes fresh re-installation of that particular theme or plugin also works fine. 

The Famous Fatal Error - PHP Memory Allocation

Memory Allocation in PHP apparently is the most common error that WordPress users would have come across. PHP by its very nature consumes memory on the server. Your hosting provider would either allocate the memory or may even allow you to increase the allocation. Most hosting providers might allocate only 8MB for PHP. Normally, single installation of WordPress can make PHP consume atleast 16MB of memory. Also, there are possibilities that you are using some other PHP application or CMS on your server which is also taking away the allocated PHP memory. In all such cases where memory is not sufficient, WordPress throws an error which is usually in this format:

 "Allowed memory size of NNN bytes exhausted". 

Solution for PHP Memory Allocation

Firstly, check if you have the rights to change memory allocation. If you do not have, proceed straight to your hosting service provider to increase the PHP memory limits. If you have the rights to change memory allocation, then open wp-config.php file in a text editor and add this line:
define( 'WP_MEMORY_LIMIT', '64M' ); 
You can change 64M to the desired value. You need to add this line just above this line:
 /* That's all, stop editing! Happy blogging. */ 

By writing this piece of code, you are instructing WordPress to increase PHP Memory allocation exclusively for WordPress only. This will resolve most of the errors caused due to lower PHP memory allocation.

Tuesday, June 25, 2013

Invalid Date Error in Google Webmaster for Sitemap generated by WordPress SEO by Yoast


If you have recently tested your sitemap that is generated by Yoast plugin for WordPress SEO, then you might have encountered an error in Google Webmaster tools while adding or testing the sitemap.

The error type would usually be mentioned as "invalid date". To fix this, one of the plugin file in Yoast SEO plugin need to be edited. Thanks to a contributor (roaming_elephant) in WordPress support forum, part of the code needs replacement. Here are the step-by-step procedures to fix this problem:

Step 1: open the plugin folder and open this php file: wordpress-seo/inc/class-sitemaps.php

Step 2: Go to line 249 and 250 where you will find the below code:
if ( $query->have_posts() )
 $date = $query->posts[0]->post_modified_gmt;
Replace the above code with the below given code:
if ( $query->have_posts() ) {
  $date = $query->posts[0]->post_modified_gmt;
  $date = date( 'c', strtotime( $date ));
}
That is all you need to do. You can now go to google webmaster tools and retest your sitemap that is generated by yoast. It should return no errors. If you have any questions, feel free to comment here.

Monday, December 31, 2012

Show more comments per page in wordpress backend

I have a very old site which I hardly bother to update. I opened the dashboard after about several months only to see that there are 653 comments. 90% of them were spam messages. Now I had to delete them or mark them as spam.

Wordpress prior to 2.8 versions used to show only 20 comments per page. But this limit is no more a limit from versions after 2.8.

If you want to increase the number of comments to be listed per page, then  follow these simple instructions:


  1. Open Comments in your wp-admin dashboard
  2. Click on the Screen Options on the right-top corner 
  3. It will open a slide-down menu.
  4. Change the number from 20 to any number that you want.
That's it. You get as many comments as you want in one page and avoid pagination process. Now you can delete, spam it or approve it in bulk very easily.

Saturday, December 29, 2012

Add Media Links in Activity Stream

Buddypress Media is a great plugin authored by rtCamp. They enable site users to upload media in albums. Media includes music, videos and photos.

However, the plugin lacks one important part - Adding media from the front end. Much like how another plugin Activity Plus does. Activity Plus lacks what BP Media provides - and that is - organizing into albums and having them stored for future use right on the members pages.

I thought of marrying both. i.e bringing BP media on the front-page where Activity Updates are posted.

//add media links

function add_media_links(){

    global $bp, $current_user;;

if (is_user_logged_in()) {

echo '<div style="float:right; font-weight:bold;">';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/media/" style="color:black; padding-right:10px">Upload</a>';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/albums/" style="color:black; padding-right:10px">My Albums</a>';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/photos/" style="color:black; padding-right:10px">My Photos</a>';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/videos/" style="color:black; padding-right:10px">My Videos</a>';

echo '<a href="'.$bp->root_domain . '/members/' . $current_user->user_login  .'/music/" style="color:black; padding-right:10px">My Music</a>';

echo '</div>';

}

else {

echo '<div style="float:right; font-weight:bold;">';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">Upload</a>';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">My Albums</a>';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">My Photos</a>';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">My Videos</a>';

echo '<a href="'.$bp->root_domain . '/login/" style="color:black; padding-right:10px">My Music</a>';

echo '</div>';}

return;

}

add_filter('bp_before_directory_activity_content',add_media_links');

?>
You may want to add this to your functions.php file.

This code, specially the last line of the code adds a filter such that whenever bp_before_directory_activity_content function is triggered, my own custom function add_media_links will trigger automatically where in, if the user is logged in, it provides direct links to the media upload as it takes $current_user->username to take them to their own page for media uploads. And if its just a visitor, these links will redirect to the login page.



You can see this in my site which is live in action at: DublinWala.Com

Thursday, November 29, 2012

Logout and Redirect to a New URL

Since Wordpress 2.7, a new template tag has been introduced using which one could redirect a logged-in user to another URL. Why would one need such a function? Well, people want logged out users to still hang-around their site to check something that might interest them.

This is how you can use this template tag:

Step 1: Add this code in your functions.php


add_filter('allowed_redirect_hosts','logout_redirect');
function logout_redirect($link)
{
    $link[] = 'example.com';
    return $link;
}
Step 2: Add this code anywhere on your site, for example in a sidebar.php or header.php or footer.php:

<a href="<?php echo wp_logout_url( 'http://example.com' ); ?>" title="Logout">Logout</a>
That's it! You are done. Wait, I just forgot to caution you that the Step 2 has PHP in it. So it won't work if you are simply adding it to a HTML text widget in sidebar or if you are adding it to a page or post. You should necessarily add this to a php file, ideally sidebar.php would do.

In case you insist that you want to use it in a sidebar widget, then better install a plugin which allows PHP in sidebar widgets.