Famous Websites Developed in PHP

When someone asks me, Is PHP so famous ? Is it secure ? Do people use PHP to develop their websites ?

Yes. They do.

Here I am going to list out some of the famous websites, which is developed in PHP.

Yes, Facebook, a giant spider in web is developed using PHP. Although they have developed their own framework, but in heart, its PHP.

How can you forget WordPress when it comes to blogging ? WordPress covers 26% of the Web. Really ? Yes. WordPress is on to of the blogging platforms.

For more details : WordPress Usage Statistics

Who doesn’t know Tennis legend Roger Federer ? Yes his personal website is developed in Joomla. Joomla is popular CMS in PHP.

 

More links are coming soon. 🙂

Advertisements

WordPress Allow Login With Email

By Default WordPress do not let you to login using Email. Here, you can modify this behavior. Just add below code in your active theme’s functions.php file (Maybe if you are using child theme, put it into child theme’s functions.php).

add_filter('authenticate', 'customAllowEmailLogin', 20, 3);
function customAllowEmailLogin( $user, $username, $password ) {
	if ( is_email( $username ) ) {
	    $user = get_user_by_email( $username );
	    if ( $user ) $username = $user->user_login;
	}
return wp_authenticate_username_password( null, $username, $password );
}

Now you can login with your email into WordPress.
Please leave your comments if its working or not working for you.

How to change length of Excerpt in WordPress

As a WordPress developer, i needed to change the length of the excerpt.
You can add following function in your themes’s functions.php file.

if(!function_exist('new_excerpt_length') {
    function new_excerpt_length($length) { 
       return 100;
    }
}
add_filter('excerpt_length', 'new_excerpt_length');

Above function will change the excerpt length to 100. (You can change that value as per your need).

Detect an AJAX Request in PHP

Whenever you need to check if request is Ajax or non-Ajax, you can check it using following code.

if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
echo "This is an Ajax Request";
}else {
echo "Not an Ajax Request";
}

Reference : http://davidwalsh.name/detect-ajax

WordPress – Add pagination in admin listing page

When you need to add pagination in WordPress admin listing, just follow below steps:


$page_num = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
$limit = 10; // Number of rows in page
$offset = ( $page_num - 1 ) * $limit;
$total = $wpdb->get_var( "SELECT COUNT(`id`) FROM `wp_posts`" );
$num_of_pages = ceil( $total / $limit );
$lists = $wpdb->get_results("SELECT * FROM `wp_posts` ORDER BY id ASC LIMIT $offset,$limit" );


$page_links = paginate_links( array(
'base' => add_query_arg( 'pagenum', '%#%' ),
'format' => '',
'prev_text' => __( '«', 'text-domain' ),
'next_text' => __( '»', 'text-domain' ),
'total' => $num_of_pages,
'current' => $pagenum
) );


if ( $page_links ) {
echo '<div class="tablenav"><div class="tablenav-pages" style="margin: 1em 0;">' . $page_links . '</div></div>';
}

Leave comments if you find it useful or you have any query about this.