Aug 16

Check whether the WordPress environment loaded or not

In most of of the time while we are writing a plugin and doing some AJAX call into this we often including wp-load.php file. It is obvious that to access the WordPress core functions we need to established the WordPress environment. But some time it also happened that WordPress environment is already established though we are including the file which lead to decrease our site performance. So now the question is Check whether the WordPress environment loaded or not Continue reading

Aug 16

How to make placeholder work in IE browser

As we all know that HTML 5 placeholder attribute is not working in IE less than 10 version. If you have input elements in your DOM with placeholder attribute and access the page in IE browser less than 10 version then you will get an error message that placeholder is not defined. To resolve this issue you have to use javascript or jQuery. I have attached a sample code file please download and check it out in different browser. Sample Code

Jul 28

BuddyPress Members Import FAQ

BuddyPress Members Import FAQ

#1 How to install BMI?
- Upload BuddyPress Members Import Directory to the /wp-content/plugins/ directory
- Activate the plugin through the ‘Plugins’ menu in WordPress.
- Go to Users tab there a BuddyPress Members Import menu will be present click on it.

#2 How to create CSV file?
- Open your favorite editor write your comma separated values there.
- Now do Save as the same file and save the file in CSV format. Continue reading

Apr 17

WordPress Security Increase

wordpress security increase
To reduce the attack to your WordPress site you can follow the below instructions

1: Increase Security from htaccess file

Add the below code to your htaccess file and replace the xxx.xx.xx.xxx with your IP. IP of your system from which you want to login to your site admin section.

<Files>
order deny,allow
deny from all
allow from xxx.xx.xx.xxx
</Files>

2: Change credentials

Change admin username and password to at-least 10 characters long with combination of all possible type character.
Like: W!w@1)*&<?lkiJH Continue reading

Apr 05

How to show External RSS Feed post on Your WordPress Site

How to show External RSS Feed post on Your WordPress Site? Dont you have time to write post and want to show post from other site’s RSS feed on your site. No worry here is a quick solution for the.

<?php
//Include feed.php file
include_once(ABSPATH.WPINC.'/feed.php');
$rss = fetch_feed('http://feeds.feedburner.com/NdtvNews-TopStories');
$maxitems = $rss->get_item_quantity(5);
$rss_items = $rss->get_items(0, $maxitems);
?>
<ul>
<?php
if ($maxitems == 0)
echo '<li>No items.</li>';
else // Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) :
?>
<li>
<a href='<?php echo $item->get_permalink(); ?>'
title="<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>">
<?php //Get title
echo $item->get_title(); ?>
</a>
<?php //Get description
echo $item->get_description(); ?>
</li>
<?php endforeach; ?>
</ul>

Nov 25

WordPress and Ajax calls

WordPress and ajax calls!!! Let me first explain you the situation. You have created one plugin and in this plugin one of your functionality need some ajax functionality mean you want to do something without refreshing the page like voting(like/dislike article), ajax sign in functionality.

After research alot and read several articles I understood that there are several ways to do a ajax call in WordPress like:
1: Use admin-ajax.php file for ajax call.
2: Include wp-load.php file in your ajax call file.
3: Include wp-config.php file with defining ‘SHORTINIT’ as TRUE.

Disadvantage of above ways:

- Site performance decreasing marginally due load the WP environment more than once.

- In first way is_admin() function will always get TRUE  even though you are in front-end.

Related links:
http://wordpress.stackexchange.com/questions/30638/determining-whether-its-a-ajax-call-from-front-end-or-from-back-end
http://codex.wordpress.org/AJAX_in_Plugins#Ajax_on_the_Viewer-Facing_Side
http://ottodestruct.com/blog/2010/dont-include-wp-load-please/

Now let say one situation you are working on a project in which you need several ajax functionality for all these you have created one common .PHP file and include wp-load.php or wp-config.php file and do your job. Now in future someone else going to work on this project and want to create some new ajax functionality as the new developer not aware about your file s/he will create a new .PHP and include wp-load.php or wp-config.php file and do his/her own job. So now What is the status of your site performance? What is the time complexity of your site? Think !!!

So, is there any other way to perform a ajax call without decreasing the site performance. Yes, there is a nice, tricky and easy way to do this.

Let us do a test:

Step1: Login as admin.
Step2: Create a page(say title My Ajax Test).
Step3: Note this page slug here slug is my-ajax-test
or
Step3: Note this page ID.
Step4: Create one file with name page-PAGEID.php or page-PAGESLUG.php and put it in your current theme root directory.
Step5: Provide this created page’s url for ajax functionality.
Step6: Write code in the above created file, in this file you have access to all WordPress functions, for ajax functionality.
Step7: DONE :)

What are you thinking, is not a good and perfect way to do ajax call in WordPress?

Now what if you want to create a plugin in which you need to implement some ajax functionality and plugin needs to be portable?

In this case create a page using code and create a page-PAGEID.php file in your current theme root directory. Place you ajaxed php code in this file using PHP file handeling functions.

I have created one sample plugin which will help you to understand this more clearly.

How to use the above plugin:
- Install the plugin.

- Goto widget section.

- Drag the ‘WordPress Better Ajax’ widget to any sidebar.

- Goto front end and click on ‘Click Me’.

Advantages:

- This procedure will not decrease your site performance.

- In a single file you can do all your ajax calls.

- If you directly access this page then it will give you a message indicating that you are in  wrong place.

Please comment what you are think about this.

Nov 09

How to make compatible nextgen gallery with AWS plugin

From few peoples I heard that nextgen gallery plugin is not working with AWS plugin as it should and asking me How to make compatible nextgen gallery with AWS plugin? So I have work around it and come out with some solution explaining below:

- Create gallery and add images as per the rule of NGG.
- Show your created gallery as per the rule of NGG.
- Now find out the ID of the div in which all your gallery images are present.
- Put this ID in “AWS Options” admin form’s first field named “No ajax container IDs”.

- Now add the below code in AWS plugins ajaxify.js file just before the "$body.removeClass('loading');"(at line 179)
scriptNode = document.createElement('script');
contentNode.appendChild(scriptNode);
scriptNode.setAttribute('src', rootUrl + 'wp-content/plugins/nextgen-gallery/js/jquery.cycle.all.min.js');

scriptNode = document.createElement(‘script’);
contentNode.appendChild(scriptNode);
scriptNode.setAttribute(‘src’, rootUrl + ‘wp-content/plugins/nextgen-gallery/js/ngg.slideshow.min.js’);

scriptNode = document.createElement(‘script’);
contentNode.appendChild(scriptNode);
scriptNode.setAttribute(‘src’, rootUrl + ‘wp-content/plugins/nextgen-gallery/shutter/shutter-reloaded.js’);

that’s it :)
- Example site link: http://www.youngtechleads.com/development/ngg-aws/

Oct 02

How to modify Active Directory passwords through PHP

The secret is keep in Active Directory on a user object within the unicodePwd attribute. This attribute is written under some restricted conditions, however it can’t be accessible, but the value of this attribute can be modify or alter.
In order to alter this attribute, you must have a 128-bit Secure Socket Layer (SSL) connection to the server. For this connection to be possible, the server must possess a server certificate for a 128-bit RSA connection, the client must trust the certificate authority (CA) that generated the server certificate, and both client and server must be capable of 128-bit encryption.

Passwords must meet complexity requirements determines whether password complexity is enforced. If this setting is enabled, user passwords meet the following requirements:

  • The password is at least six characters long.
  • The password contains characters from at least three of the following five categories:
    • English uppercase characters (A – Z)
    • English lowercase characters (a – z)
    • Base 10 digits (0 – 9)
    • Non-alphanumeric (For example: !, $, #, or %)
    • Unicode characters
  • The password does not contain three or more characters from the user’s account name.

PHP code as follows:
function create_ldap_connection() {
$ip = "Ad server IP";
$ldaps_url = "ldaps://$ip";
$port = 636;

$ldap_conn = ldap_connect( $ldaps_url, $port ) or die("Sorry! Could not connect to LDAP server ($ip)");

ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);

$username = "AdminUserName";
$password = "AdminPassword";
$binddn = "CN=Administrator,CN=Users,DC=TestDomain,DC=local";

$result = ldap_bind( $ldap_conn, $binddn, $password ) or die("
Error: Couldn't bind to server using provided credentials!");

if($result) {
return $ldap_conn;
} else {
die("
Error: Couldn't bind to server with supplied credentials!");
}
}

function get_user_dn( $ldap_conn, $user_name ) {
/* Write the below details as per your AD setting */
$basedn = "DC=AD Test,DC=Local";
/* Search the user details in AD server */
$searchResults = ldap_search( $ldap_conn, $basedn, $user_name );
if ( !is_resource( $searchResults ) )
die('Error in search results.');

/* Get the first entry from the searched result */
$entry = ldap_first_entry( $ldap_conn, $searchResults );
return ldap_get_dn( $ldap_conn, $entry );
}

function pwd_encryption( $newPassword ) {
$newPassword = "\"" . $newPassword . "\"";
$len = strlen( $newPassword );
$newPassw = "";
for ( $i = 0; $i < $len; $i++ ){
$newPassw .= "{$newPassword{$i}}\000";
}
$userdata["unicodePwd"] = $newPassw;
return $userdata;
}

$user_name = "(sAMAccountName=UserName of user whose password want to change)";//Dont remove parentheses brackets
$user_password = "New Password";

$ldap_conn = create_ldap_connection();
$userDn = get_user_dn($ldap_conn, $user_name);
$userdata = pwd_encryption($user_password);

$result = ldap_mod_replace($ldap_conn, $userDn , $userdata);
/* Check whether the password updated successfully or not. */
if ( $result )
die("Password changed successfully!");
else
die("Error: Please try again later!");