<?xml version=”1.0″ encoding=”UTF-8″?>

<configuration>

<system.webServer>

<rewrite>

<rules>

<rule name=”Redirect to newdomain.com”>
<match url=”(.*)” />
<conditions>
<add input=”{SERVER_PORT}” pattern=”443″ negate=”true” />
</conditions>
<action type=”Redirect” url=”http://www.newdomain.com/{R:1}” />
</rule>
</rules>

</rewrite>

</system.webServer>

</configuration>

Credit for this tip goes to http://www.alexbarnettdesign.com/coding/removal-of-username-at-wordpress-register-page/.

WordPress needs a unique user name. But many people forget their user name and likes to login with their email id, which is easy to remember.

What we can do is create a function to generate a random user name and call that function as value for user name field. Then we can assign “hidden” type for the input field of user name.

Here is the function to generate random user name.


function generate_random_username($length = 6) {

    $char = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x","y", "z");

    $rand = array_rand($char, $length - 5);

    $str = "";
    foreach ($rand as $k => $v) {

        $str .= $char[$v];

    }

    $str .= substr(time(), -5);

    return $str;

}

Add the above code to function.php in your theme folder.

Edit type and value field of user_login in wp-register.php in the root folder.

Make type as hidden and value as echo generate_random_username(14)

14 is the length of user name.

When I tried to activate NextGenGallery on a client site, I was getting the error: 500 Internal server error.

Found a number of solutions in different sites for the issue. None of them worked for me except the following:

Add AddType x-mapp-php5 .php to .htaccess file to make the php files run with php5, since Apache by default may be running an earlier version of php.

Error: Error parsing XML; message from parser is: Invalid value for body of continue-shopping-url in checkout-shopping-cart/checkout-flow-support/merchant-checkout-flow-support: URL contains illegal characters

Fix: Check the field wp-admin —> Store –> Settings –> Admin –> Transaction Details URL

It should be a valid link.

I am sharing 2 simple plugins I did, so it will be helpful for new plugin writers.

My client wanted to add an award section. That is, he wanted to assign an award for some post and display it in the front end under the title of the post. Each award has an image also.

So first he needs to create the awards. For that I wrote this plugin.

Now I have to display these awards when editing a post/ adding a new post.

For that I used the following plugin: Adding custom box

This plugin will save the award id as post meta. Later in the theme page we can call the post meta and display the award.

The following code will be useful if you want to allow users to post only in some categories.


function restrict_categories($categories) {
// If we are in the new/edit post page and not an admin, then restrict the categories
$onPostPage = (strpos($_SERVER['PHP_SELF'], 'post.php') || strpos($_SERVER['PHP_SELF'], 'post-new.php'));
if (is_admin() && $onPostPage && !current_user_can('level_10')) {
$size = count($categories);
for ($i = 0; $i < $size; $i++) {			 			if ($categories[$i]->slug != 'user-created-articles' && $categories[$i]->slug != 'user-created-content' && $categories[$i]->slug != 'user-created-disagreements'&& $categories[$i]->slug != 'user-created-reviews')
unset($categories[$i]);
}
}
return $categories;
}
add_filter('get_terms', 'restrict_categories');

In the above code it checks the category slug. Admin can post in any categories, but other users can post only in the categories, where slug is either “user-created-articles” or “user-created-articles” or “user-created-disagreements” or “user-created-reviews”

By adding the following code to functions.php in your theme file you can permit contributors to upload images.

if ( current_user_can('contributor') && !current_user_can('upload_files') )
	add_action('admin_init', 'allow_contributor_uploads');

function allow_contributor_uploads() {
	$contributor = get_role('contributor');
	$contributor->add_cap('upload_files');
}

For a client, in whm – cpanel after uploading all files to the root I got a confusing redirection which goes to /cgi-sys/defaultwebpage.cgi when I go to the domain name.

The page showed the message “Cpanel is successfully installed” etc…

Here is the solution to resolve the issue of redirection.

Edit httpd.conf . In the server there is Apache Configuration –> Include Editor –> post virtual host include

There write

<VirtualHost XXX.XX.XXX.XXX:80>
ServerName www.yourdomain.com
DocumentRoot /home/yourdom/public_html
ServerAdmin webmaster@yourdomain.com
UserDir disable
</VirtualHost>

XXX.XX.XXX.XXX – should be replaced by your ip address.

yourdom – has to be replaced by your domain name.

Then restart Apache.

It should remove the redirection.

Example :


<form action="" method="post" name="form1" id="form1">
<input type="checkbox" name="install1" id="install1" onclick="calculate()" value="225" />

<input type="checkbox" name="install2" id="install2" onclick="calculate()" value="375" />

<input type="checkbox" name="package3" id="package3" onclick="calculate()" value="50" />

<input type="text" id="total" name="total"  size="6" />

</form>

Following is the javascript needed to calculate the total.

<script type="text/javascript">
function calculate() {
var elems = document.forms['form1'].elements;
var total = 0;
for(var i=0;i<elems.length;i++) {
if (elems[i].checked) {total += +(elems[i].value);}
}
elems['total'].value = total;
}
</script>

While searching for paypal integration, I got this beautiful class from internet.

http://www.micahcarrick.com/php-paypal-ipn-integration-class.html

Thanks Micah Carrick, it is perfect for my work.

I am not explaining much about this integration because if you download it from the above link, it is well documented in the file.

So I don’t want to repeat it here.

© 2012 Some PHP | Wordpress Tips Suffusion WordPress theme by Sayontan Sinha