WordPress plugin updater script released

I have released the latest version of WordPress plugin updater script on Github
Wiki: https://github.com/droidzone/wordpress_plugin_updater/wiki
Code: https://github.com/droidzone/wordpress_plugin_updater

WordPress plugin updater is a useful perl script that when run on a folder containing your wordpress plugins, checks each plugin for newer versions in the WordPress repository, and updates each plugin to the latest version.

It accepts as argument a single folder or multiple folders of wordpress installations. This saves you the trouble of visiting your dashboard to update plugins, especially if you manage multiple sites, and have hundreds of plugins. Having older versions of plugins is a security hole, and hence this script helps secure your server.

You can easily run the script as a cron job at hourly-daily intervals and thus schedule updating your plugins.

Installation

Usage


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Upgrading to Genesis 2.0.0

I found that upgrading to Genesis 2.0.0 broke one of my sites. One of the sites wasnt affected, while another was. I tried removing the version of the genesis/ folder inside studiopress after the upgrade was downloaded, and then copying over the new genesis/ folder into studiopress/

i.e

rm -rf themes/studiopress/genesis
mv themes/genesis themes/studiopress/

Here, themes/genesis was the newly downloaded version.
That still broke the site. The only way out was to do the following.

Retaining 1.9.2, Clck on “Upgrade now”
When you get prompted for “Click here to complete the upgrade”, instead of proceeding, go to the shell and do the following:

cp -a themes/genesis themes/studiopress/

In effect, overwriting the old one, retaining the main copy in themes.

Edit: Something was amiss with the old studiopress vs the new one. Activating studiopress still broke my site. Finally I had to activate another studiopress theme. I’ll have to get to the root of this later.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

WordPress: This website has a redirect loop

I got the following error in Chrome after transferring my WordPress install across servers:

“This website has a redirect loop”, and seemed to redirect to a url with the signup link.

On Firefox, the error was: “The page isn’t redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies.”

I tried the following:

  1. Clearing cookies.. Duh
  2. Setting the following permissions (recommended for the install. See Codex.)
    [[email protected]] /htdocs #find . -type d -exec chmod 755 {} \;
    [[email protected]] /htdocs #find . -type f -exec chmod 644 {} \;
    [[email protected]] /htdocs #chown -R vu2009.vu2009 *
    

    where vu2009 was my webserver user (See cat /etc/passwd)

  3. Finally, logged into phpmyadmin and found that I’d forgotten to import my database!

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.
Automatically update all WordPress plugins from Bash

Automatically update all WordPress plugins from Bash

I’ve updated the script radically. WordPress had changed their site structure so that the older script would fail. With the latest updates, it should still work.

Latest version:
Writeup
Download

I was searching for an idea on how to automatically update all my WordPress plugins from Linux command line. Google introduced me to a script by Ventz Petkov. It worked very well with minor modifications. This script could automatically download all plugins from WordPress.org according to the subdirectories in the WordPress plugin directory.

However a minor drawback of the script is that it would overwrite all plugins without checking whether our plugins are already up to date. I thought this was a waste of resources, since the obvious use of such a script is to get it to run as a cron job at regular intervals. There is no need to keep downloading the same versions of plugins that you already have, countless number of times. Even Petkov has conceded as much, stating that such an addition would be quite useful.

So there you are, my first perl script. I would like to record due credits to Petkov for his method of parsing the wordpress.org website, and his framework. All that I’ve done is to add code for comparing the plugin versions that are in your plugins directory, with those on the website to see if there are available updates. If there are, only then are the files downloaded.

The latest version of the script can always be downloaded from here (New link).

The script can take command line argument. Argument #1 is the path to plugin directory. Argument #2 is the plugin to update (meaning you can manually update one plugin at a time), and is a remnant of the original script. For my purpose, I wont be using Argument #2, since I intend the script to be run automatically, updating as when updates are found.

Screenshots:

Script command line options:

--help or -h: Display this help message
--source=/path/to/plugindirectory or -s/path/to/plugindirectory
	Multiple folders can be specified at a time.
	Eg: ./updater.pl --source=/var/www/virtual/joel.co.in/vettathu.com/htdocs/wp-content/plugins,/var/www/virtual/joel.co.in/drjoel.in/htdocs/wp-content/plugins
--version or -v: Display script version information
--plugin=PluginName or -pPluginName: Specify one or more plugins to process instead of all plugins under source directory. To specify more than one plugin,
you can either repeat this option, like:
	Eg: ./updater.pl --plugin=nextgen-gallery --plugin=genesis-beta-tester
	  Or,
you can alternately specify a comma seperated list of plugins, like:
	Eg: ./updater.pl --plugin=nextgen-gallery,genesis-beta-tester
--wp-path= or -wp: Specify wordpress root directory instead of plugin directory
	Eg: ./updater.pl --wp-path=/var/www/virtual/joel.co.in/droidzone.in/htdocs,/var/www/virtual/joel.co.in/vettathu.com/htdocs

Examples:

/root/wordpress_plugin_updater/updater.pl -w/var/www/virtual/joel.co.in/droidzone.in/htdocs

/root/wordpress_plugin_updater/beta.pl -s/var/www/virtual/joel.co.in/droidzone.in/htdocs/wp-content/plugins

If running from cron:

/usr/bin/perl /path/to/updater.pl -s/var/www/virtual/joel.co.in/vettathu.com/htdocs/wp-content/plugins

An example crontab entry would be:

* */6 * * * /usr/bin/perl /root/bash-advanced-scripts/updater.pl -s/var/www/virtual/joel.co.in/drjoel.in/htdocs/wp-content/plugins >> /root/wordpress_update.log

Here the script is being run sixth hourly every day, and a log appended. You can have multiple entries for multiple blogs.

The following line will automatically flush log files, keeping last 6 days of backups:

0 0 */3 * * mv /root/wordpress_update.log /root/wordpress_update.log.old

You can see the list of updated plugins by:

[[email protected]] ~/temp #cat /root/wordpress_update.log | grep -in 'updating' --color
83:Processing plugin: easy-contact-forms | Local version 1.4 | Remote version 1.4.2 | Updating now..
158:Processing plugin: wordpress-importer | Local version 0.6 | Remote version 0.6.1 | Updating now..
68527:Processing plugin: fancier-author-box | Local version 1.0.5 | Remote version 1.0.6.1 | Updating now..
68910:Processing plugin: fancier-author-box | Local version 1.0.5 | Remote version 1.0.6.1 | Updating now..
90869:Processing plugin: simple-backup | Local version 2.7.1 | Remote version 2.7.2 | Updating now..
91357:Processing plugin: look-see-security-scanner | Local version 13.01 | Remote version 13.04 | Updating now..
91740:Processing plugin: look-see-security-scanner | Local version 13.01 | Remote version 13.04 | Updating now..
113638:Processing plugin: bulletproof-security | Local version .48 | Remote version .48.1 | Updating now..
113686:Processing plugin: bulletproof-security | Local version .48 | Remote version .48.1 | Updating now..
113718:Processing plugin: bulletproof-security | Local version .48 | Remote version .48.1 | Updating now..

 

The current version as of 31/03/13 is included below:

#!/usr/bin/perl -w
# Original Author: Ventz Petkov
# Last updated by Original Author on
# Date: 06-15-2011
# Last: 12-20-2012
# Version: 2.0
#
# Rewritten by: Droidzone
# Date 31-03-2013 www.droidzone.in
# Version 3.0.0.2
# Usage:
# ./update-wp-plugins.pl
#   or
# ./update-wp-plugins.pl registered-name-of-plugin
# (and this works to update an exiting plugin or download+install a new one)

$progversion="3.0.0.2";
$debugmode=0;
use Term::ANSIColor;
print color 'bold blue';
print "Wordpress Plugin Updater script v$progversion.\n";
print color 'reset';
&argparser(@$ARGV);

if(!defined($ARGV[0])) {
    dprint ("No arguments supplied for folder path");
	$path="/var/www/virtual/joel.co.in/vettathu.com/htdocs/wp-content/plugins";
	dprint ("Path was specified on the command line\n");
}
else {
	#my @values = split(',', $ARGV[0]);	
	#foreach my $val (@values) 
	$path=$ARGV[0];
	print "Working on directory: $path\n";	    
    if ( -d $path )
    {
		dprint ("Path verified\n");
    }
    else
    {
		dprint ("The path does not exist\n");
	exit;
    }
}

dprint ("The path was set as ".$path."\n");
print "Plugin directory:$path\n";
chdir($path);

use WWW::Mechanize;
#use File::Find;
my $mech = WWW::Mechanize->new();
$mech->agent_alias( 'Mac Safari' );
my $wp_base_url = "http://wordpress.org/extend/plugins";

################################################
# Add New plugins Here:
# Format:
#   'registered-name-of-plugin',
#
my (@plugins, @plugins_notfound, @filepath, @pluginversion);

use File::Find::Rule;
use File::Spec;

my @folders = File::Find::Rule->directory->maxdepth(1)
    ->in( $path )
    ;

foreach my $i (@folders){
    ( $volume, $directories, $file ) = File::Spec->splitpath( $i );
	undef $volume, $directories;
    if ( $file ne "plugins" )
    {
        push @plugins, $file;
		push @filepath, $i;
		#print "Path: ".$i."\t Name: ".$file."\n";
    }
}

for (my $i = 0; $i < @plugins ; $i++ ) 
{
    dprint ("Processing ".$plugins[$i]."...");
    #print "Filename:".$filepath[$i]."/".$plugins[$i].".php"."\n";
    $filename=$filepath[$i]."/".$plugins[$i].".php";
	$varfound=0;
    if ( -f $filename ) 
    {
		dprint ("Meta File found at default location.\n");				
		open("txt", $filename);
		while($line = <txt>) 
		{			
			if ( $line =~ /^\s*\**\s*\bVersion:(.*)/i )
			{
				$pluginversion[$i]=$1;
				dprint ("Version found in file ".$filename);						
				$varfound=1;										
				dprint ($pluginversion[$i]."\n");
				dprint ("Array Num ".$i." Stored plugin name:".$plugins[$i]." Version found and stored ".$pluginversion[$i]);
			}
		}
		close("txt");			
    }
    else
    {
		$searchpath=$path."/".$plugins[$i];
		@files = <$searchpath/*.php>;
		dprint ("Search path is ".$searchpath."\n");
OUT: 	foreach $file (@files) 
		{
			dprint ("Checking alternate php file: ".$file."\n");
			open("txt", $file);
			while($line = <txt>) 
			{
				#  $line =~ /^[\s\*]*Version:(.*)/i
				# Discussion on regex: http://stackoverflow.com/questions/15728671/perl-regex-logic-error
				if ( $line =~ /^\s*\**\s*\bVersion:(.*)/i )
				{
					$pluginversion[$i]=$1;
					dprint ("Version found in file ".$file);						
					$varfound=1;										
					dprint ($pluginversion[$i]."\n");
					dprint ("Array Num ".$i." Stored plugin name:".$plugins[$i]." Version found and stored ".$pluginversion[$i]);
					last OUT;
				}
			}
			close("txt");	
		}
    }
	push @plugins_notfound, $plugins[$i];
}

if ( ! $varfound) 
{
	print "\nCould not parse version no from the follwing plugins:\n";
	for (my $i = 0; $i < @plugins_notfound ; $i++ ) 
	{
		print $i." ".$plugins_notfound[$i]."\n";
	}
}
else 
{
	dprint ("We found all version numbers");
}
print color 'red';
#print colored("Summary of scanning plugin directory", 'red'), "\n";
print "Summary of scanning plugin directory\n";
print "------------------------------------\n";
printf("%-4s %-45s %3s\n", "No", "Name", "Version");
print color 'reset';
#print "No:\tName\tVersion\n";
for (my $i = 0; $i < @plugins ; $i++ ) 
{
	$v = $pluginversion[$i];
	$v =~ s/[^a-zA-Z0-9\.]*//g;	
	printf("%-4s %-45s %3s\n", $i, $plugins[$i], $v );
	#print "$i\t$plugins[$i]\t$pluginversion[$i]\n";
}
print "\n";

################################################
$pluginsdone=0;

if(defined($ARGV[1])) {
    my $name = $ARGV[1];
    &update_plugin($name);
}
else {
	$i=-1;
    for my $name (@plugins) {
		$i++;
        &update_plugin($name,$i);
    }
}

print "Plugin updation completed successfully.\n";

if ( $pluginsdone > 1 )
{
	print "$pluginsdone plugin(s) were updated.\n";
}
else
{
	print "Plugins were already up-to-date. Nothing done.\n";
}

sub update_plugin {

    my $name = $_[0];
	my $index = $_[1];
    my $url = "$wp_base_url/$name";
    $mech->get( $url );
    my $page = $mech->content;
	$url="";
    my ($version,$description,$file) = "";
    if($page =~ /.*<p class="button"><a itemprop='downloadUrl' href='(.*)'>Download Version (.*)<\/a><\/p>.*/) 
	{
		$url = $1;
		$version = $2;
		if($page =~ /.*<p itemprop="description" class="shortdesc">\n(\s+)?(.*  
	)(\s+)(\t+)?<\/p>.*/) 
		{
			$description = $2;
		}
		if($url =~ /http:\/\/downloads\.wordpress\.org\/plugin\/(.*)/) 
		{
			$file = $1;
		}
    }	
	$oldversion = $pluginversion[$index];
	$version =~ s/[^a-zA-Z0-9\.]*//g;	
	$oldversion =~ s/[^a-zA-Z0-9\.]*//g;

    print "Processing plugin: ";
	print colored($name, 'green');	
	print " | Local version ";
	print colored($oldversion, 'green');		
	print " | Remote version ";

	if ( $version eq $oldversion )
	{
		print colored($version, 'green');	
		print " | ";
		print colored("Already update\n", 'green');
	}
	else
	{
		print colored($version, 'red');	
		print " | ";
		$pluginsdone++;
		print colored("Updating now..\n\n", 'blue');
		#print "Updating plugin $name now";
		`/bin/rm -f $file`; print "Downloading: \t$url\n";
		`/usr/bin/wget -q $url`; print "Unzipping: \t$file\n";
		`/usr/bin/unzip -o $file`; 
		print colored("Installed: \t$name\n\n", 'green');		
		`/bin/rm -f $file`;
	}
}

sub read_extract
{
	my $pl_version="";
    open("txt", my $file=$_[0]);
    while($line = <txt>)
    {
		for ($line)
		{
		 s/^\s+//;
		 s/\s+$//;
		}			
        if ( $line =~ /^Version:|^version:|^\* Version:/ )
        {
            $pl_version=&extract_version($line);
        }
    }
    close("txt");
	$pl_version;
}

sub extract_version
{
    my $line=$_[0];
    $string=substr($line,rindex($line, ":")+1);
    for ($string)
    {
     s/^\s+//;
     s/\s+$//;
    }
    $string;
}

sub dprint
{
	$debugtext=$_[0];
	if ($debugmode) 
	{
		print $debugtext."\n";
	}
}	

sub print_help 
{
	print "\nCommand syntax:";
	print "\n";
	print "wpupdater [path/to/plugin dir] [plugin name]\n";
	print "\nBoth arguments are optional\n\n";
}

sub argparser
{
	foreach (@ARGV) {
		$argu=$_;
		#print "Argument:$argu";
		if ($argu eq "--help")
		{
			&print_help;
			exit;
		}
	}

}

You can add these as a cron job.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Wrap a php parser file in WordPress theme

I created a form parser for a WordPress site that would parse the contents of a posted form, and display a success page. I used pure php instead of trying to use a WordPress template or theme. As a downside, the displayed page would not show any WordPress theme.

So I found a solution to import the theme for the php, and this is by including the theme’s header and footer in the php file.

The complete form parser is included below:

<?php

// If title is not displayed before loading the header, WordPress displays "Page not found" as the title

echo "<head>
<title>Your form has been submitted</title>
</head>";

// Include the Main WordPress blog header
include $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php";

// Include the specific theme header you need
include $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/studiopress/genesis/header.php";

// Your custom code STARTS here

// My code includes two functions. 
// The first part is the background activity which parses the form, checks for errors and then mails it if there arent any errors
// The second part is html code that is displayed to the user to inform them that the form has been submitted.

if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "[email protected]";
    $email_subject = "Someone has submitted feedback on your website";

    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";

// create email headers

$headers = 'From: [email protected]'."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<?php
// Second part starts.
// This part is displayed.

echo "
<h2>
Your form has been submitted
</h2>";

echo "<h4>Dear $first_name,</h4>
<p>Your feedback has been received by us and will be forwarded to the site administrator. You will receive your login details or a response soon.</p>";

echo "<br /><br /><br /><br /><br /><br /><br />
Click <a href=\"http://www.site.com\">here</a> to return to the site.";
// END of custom code

?> 

<?php
}
include $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/studiopress/genesis/footer.php";
?>[/code]
The following is the actual form:
You can use the following form to contact the administrator of this site:

<form action="../phpscripts/send_form_email1.php" method="post" name="contactform">Note: If you're requesting login rights, please add information on how you're related to the family.&nbsp;
<table width="450px">
<tbody>
<tr>
<td valign="top"><label for="first_name">First Name *</label></td>
<td valign="top"><input type="text" maxlength="50" name="first_name" size="30" /></td>
</tr>
<tr>
<td valign="top"><label for="last_name">Last Name *</label></td>
<td valign="top"><input type="text" maxlength="50" name="last_name" size="30" /></td>
</tr>
<tr>
<td valign="top"><label for="email">Email Address *</label></td>
<td valign="top"><input type="text" maxlength="80" name="email" size="30" /></td>
</tr>
<tr>
<td valign="top"><label for="telephone">Telephone Number</label></td>
<td valign="top"><input type="text" maxlength="30" name="telephone" size="30" /></td>
</tr>
<tr>
<td valign="top"><label for="comments">Comments *</label></td>
<td valign="top"><textarea cols="30" maxlength="1000" name="comments" rows="6"></textarea></td>
</tr>
<tr>
<td></td>
<td style="text-align: left;" colspan="2"><input type="submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form>[/code]
Version 0.2

I made it generic and detect the proper active theme:
&lt;?php

// If title is not displayed before loading the header, WordPress displays "Page not found" as the title

echo "&lt;head&gt;
&lt;title&gt;Your feedback has been submitted&lt;/title&gt;
&lt;/head&gt;";

// Include the Main WordPress blog header
include $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php";

//bloginfo(‘template_url’);
$homeurl=home_url();
$ddir= get_bloginfo( 'template_directory');
$current_theme_relative_path=substr_replace($ddir, "", 0, strlen($homeurl));
//echo "&lt;br/&gt;The relative path to the currently active theme is ".$newss;

// Include the specific theme header you need
//echo "Full path to header is ".$_SERVER['DOCUMENT_ROOT'].$newss."/header.php";
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/header.php";

// Your custom code STARTS here

// My code includes two functions. 
// The first part is the background activity which parses the form, checks for errors and then mails it if there arent any errors
// The second part is html code that is displayed to the user to inform them that the form has been submitted.

if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "[email protected]";
    $email_subject = "Someone has submitted feedback on your website";

    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.&lt;br /&gt;&lt;br /&gt;";
        echo $error."&lt;br /&gt;&lt;br /&gt;";
        echo "Please go back and fix these errors.&lt;br /&gt;&lt;br /&gt;";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.&lt;br /&gt;';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.&lt;br /&gt;';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.&lt;br /&gt;';
  }
  if(strlen($comments) &lt; 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.&lt;br /&gt;';
  }
  if(strlen($error_message) &gt; 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";

// create email headers

$headers = 'From: [email protected]'."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?&gt;

&lt;?php
// Second part starts.
// This part is displayed.

echo "
&lt;h2&gt;
Your feedback/request has been submitted
&lt;/h2&gt;";

echo "&lt;h4&gt;Dear $first_name,&lt;/h4&gt;
&lt;p&gt;Your feedback has been received by us and will be forwarded to the site administrator. 
&lt;br/&gt;
You will receive your login details or a response soon.&lt;/p&gt;";

echo "&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
Click &lt;a href=\"http://www.vettathu.com\"&gt;here&lt;/a&gt; to return to the site.";
// END of custom code

//Useful wordpress functions
/*
echo "The current theme name is".get_current_theme()."&lt;br/&gt;";

echo "&lt;br/&gt;";
echo "The dir is ".$ddir."&lt;br/&gt;";

echo "The home url is".$homeurl."&lt;br/&gt;";
*/
//$newdirst=str_replace($homeurl,".",$temp_ddir);

/*
echo "Length of whole is ".strlen($ddir);
echo "Length of substring is ".strlen($homeurl);

*/

?&gt; 

&lt;?php
}
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/footer.php";

?&gt;

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Manually reset WordPress master password

It may have happened to many of us who maintain multiple wordpress installations with very secure passwords. One day, we just forget our passwords and then realize that the email setup for the user is invalid, and we cant reset the password through email.

If it happens, there is a technique to reset the password through mysql.

Login to the Phpmyadmin control panel.

Identify the username of the account we’re about to reset from the wp_users table.

Then execute the following sql code in Phpmyadmin:

UPDATE `wp_users`
SET `user_pass` = MD5('newpassword')
WHERE `user_login` ='username_to_reset_for'
LIMIT 1;

You may need to modify the quoted strings for your database.

Voila, now you can login with the new password.

Another GUI based method for PhpMyadmin and other ways to reset password are described in the WordPress Codex.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.
Working with WordPress multisite sub-domain install on localserver in WAMP

Working with WordPress multisite sub-domain install on localserver in WAMP

While I was trying to set this up, I came across multiple articles, but none worked correctly for me.

Details of Localserver: Windows 7 64 bit system

WAMP installed to c:\wamp

 

You need to make two major changes to get a subdomain localhost install of WordPress running correctly. These are changes to your hosts file and the Apache httpd.conf file

Location:

HOSTS FILE:

C:\Windows\System32\drivers\etc

Alternate generic location: %systemroot%\system32\drivers\etc\

Linux: /etc/hosts

HTTPD.CONF FILE:

httpd.conf: C:\wamp\bin\apache\apache2.4.2\conf

On Ubuntu the main Apache configuration file is actually apache2.confApache2.confcontains the default configuration for Apache on Ubuntu. Apache2.conf includeshttpd.conf for “user configurations”. Here’s the lines from apache2.conf that includehttpd.conf:

# Include all the user configurations:
Include /etc/apache2/httpd.conf[/code]
So use httpd.conf to add extra Apache configuration, and modify apache2.conf if you need to change the existing Apache configuration.

Ubuntu’s Httpd.conf Location

For the versions of Ubuntu we’ve checked so far, you can consistently find httpd.conf in the directory /etc/apache2.   I needed to get www.droidzone.in, supernova.droidzone.in working in localhost. So the example will be this. The hosts file needs the following changes:
127.0.0.1 www.droidzone.in

127.0.0.1 supernova.droidzone.in

Note that http://droidzone.in in real time points to www.droidzone.in by means of an A record. So what applies to www.droidzone.in applies to droidzone.in. The address has to be a.b.c and not just b.c. So adding www before droidzone.in is a must.

So now that the addresses are pointed to localhost represented by 127.0.0.1, we need to setup httpd.conf. Click on th WAMP icon in the tray>Apache>httpd.conf (See figure)

 

 

 

 

 

 

 

 

 

 

The file opens in Notepad in a window.

Next, at the end of this file, add the following:

&lt;VirtualHost *:80&gt;
 ServerName www.droidzone.in
 DocumentRoot "C:\wamp\www"
 DirectoryIndex index.php index.html index.html index.htm index.shtml
&lt;/VirtualHost&gt;

&lt;VirtualHost *:80&gt;
 ServerName supernova.droidzone.in
 DocumentRoot "C:\wamp\www"
 DirectoryIndex index.php index.html index.html index.htm index.shtml
&lt;/VirtualHost&gt;

Note that C:\wamp\www is the directory where I have put my WordPress installation. That is, the directories wp-admin and wp-content, along with the file wp-config.php are contained within this directory.

Once these files have been modified, you should restart Apache.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Missing text in WordPress

I’d been noticing big chucks of posts missing from WordPress for a long, long time. I’d understood that these were often due to code tags issues (open tags/invalid tags) due to the code editor, and short of spending a lot of time manually correcting tags in a text editor, could see no solution to the issue.

Today I chanced to read this support thread, which stated that the solution was within WordPress itself, and was simply to enable an option in Settings:

 

Settings>Writing>WordPress should correct invalidly nested XHTML automatically


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.