Category Archives: PHP

How To Install & Configure phpMyAdmin On Ubuntu 12.04 & Greater Versions?

phpMyAdmin is a free software that provides you a user friendly interface to work with MySQL on the web. It simply provides you a convenient visual frontend to access MySQL capabilities. This tutorial shows you the steps for installing phpMyAdmin on Ubunu Linux so before installing it make sure you must have root privileges on your virtual private server.

Continue reading How To Install & Configure phpMyAdmin On Ubuntu 12.04 & Greater Versions?

How To Easily Edit Your PHP.INI File From cPanel ?

What is PHP.INI File ? PHP.INI is a configuration file which is read when PHP starts up. For server module versions of PHP, it only happens once when the webserver is started. For the CGI and CLI versions, it happens on every invocation.

Continue reading How To Easily Edit Your PHP.INI File From cPanel ?

How To Easily Convert HTML Code To PHP Online In Just A Click ?

Its easy to convert HTML code to PHP without hiring any PHP programmer or downloading any application, you can simply do this online free of cost. There are many online free tools that converts HTML to PHP in quick way.

Continue reading How To Easily Convert HTML Code To PHP Online In Just A Click ?

Create Your Own YouTube Like Video Broadcasting Website Using PHPmotion

What is PHPmotion ?

PHPmotion is a free video sharing software also supports other media types like audio/mp3 sharing. This CMS allows you to create and run your own Video Sharing Site, Music Sharing Site, Picture Sharing Site very easily, you can now have a website just like youtube.com , dailymotion.com, veoh, hi5 and best of all. Its 100% free to download and use but have a few Terms and Conditions.

How To Install PHPmotion ?

Continue reading Create Your Own YouTube Like Video Broadcasting Website Using PHPmotion

How To Add Hacks In Your BuddyPress Site Without Loosing Them In The Next Update ?

Add actions and hacks without touching your theme’s function.php file. So that you don’t loose them anytime while running BuddyPress update.

Continue reading How To Add Hacks In Your BuddyPress Site Without Loosing Them In The Next Update ?

Function For Defining Default Post Thumbnail In WordPress

Open your theme’s function.php file and add the given function editing the thumbnail image URL (given in bold text) with your own image URL.

add_action( ‘save_post’, ‘wptuts_save_thumbnail’ );
function wptuts_save_thumbnail( $post_id ) {
$post_thumbnail = get_post_meta( $post_id, $key = ‘_thumbnail_id’, $single = true );
if ( !wp_is_post_revision( $post_id ) ) {
if ( empty( $post_thumbnail ) ) {
update_post_meta( $post_id, $meta_key = ‘_thumbnail_id’, $meta_value = ‘https://sangkrit.net/thumbnail.jpg’ );
}
}
}

How To Edit WordPress ‘Posts’ Label ?

You can edit WordPress post label to something Else. For example if you want to edit Posts (label) to Article so that anytime you or any other member visit you wp-admin (dashboard) he can see Article as a label on sidebar menu not posts (which is by default).

For doing this, open your theme’s function.php file and add the following code:

add_filter(‘gettext’, ‘change_post_to_article’);
add_filter(‘ngettext’, ‘change_post_to_article’);
function change_post_to_article($translated) {
$translated = str_ireplace(‘Post’, ‘Article’, $translated);
return $translated;
}

Different Ways Of Defining Arrays In PHP

How to define an empty array ?

$my_array_1 = array();

How to define an auto incremented array?

$my_array_2 = array(“one_1″,”two_2″,”three_3”);

How to define a multidimensional array ?

$multi_dim_array = array();
$multi_dim_array[] = array(“one_1″,”two_2”);
$multi_dim_array[] = array(“three_3″,”four_4”);
echo $multi_dim_array[0][1];
echo $multi_dim_array[1][0];

How to define an array with assigned index stings ?

$my_array_4 = array(
“name”=>”your_name”,
“age”=>20,
“gender” =>”male”
);

How to define an array having assigned index numbers?

$my_array_3 = array
1=>”one_1″,
2=>”two_2″,
3=>”three_3″
);

Restricting Image Upload Size and Upload Time Using PHP

How to Limit File Upload Size using PHP ?

For reducing high bandwidth usage network admins can limit file size  to be uploaded  on server by other users. Following script limits file size a user can upload:

<?php
if ($_FILES[“file”][“size”] < 25000)) // Max File Size: 25KB
{
echo “File size exceeds maximum.”;
}
?>

How to Limit File Upload Time Using PHP ?

Other trick for network admins for reducing high bandwidth usage is to limit file upload time. For this you may edit server’s php.ini file or you can set upload time in your site:

ini_set(‘max_input_time’, 300);

How To Add Custom User Roles In WordPress ?

Suppose you need to create a new custom post type, may be NEWS. So that you can allow you subscribers to post NEWS on your website. In the given example we will be creating a custom user role for NEWS and the users allotted this role would only be managing only NEWS section from WP-Admin (Dashboard).

Open your theme’s function.php file: site root >> wp-content >>themes >> function.php and add the given code block:

add_role( ‘news_user’, ‘News User’, array( ‘news’ ) );

This function generates new custom user role which can only manage
news section from Dashboard.

Although you may add some more function for new custom user role.

New custom user role can also be removed from WordPress by using the following function in your theme’s function.php file:

remove_role( ‘news_user’ );

From WordPress Function $wp_roles also you can add and remove custom user roles as show below:

global $wp_roles;
$wp_roles-&gt;add_cap( ‘news_user’, ‘manage_category’ );
$wp_roles-&gt;remove_cap( ‘news_user’, ‘view_post’ );

Embeding SWF In WordPress Posts

You can easily embed SWF file inside your WordPress post either by using a plugin or by using WP hack.

Using WordPress Plugin:

  1. Open your Dasboard
  2. Visit Plugins >> Add New and Search for Easy Flash Embed plugin.
  3. Install and Activate it.

Use the following shortcode for embedding your SWF file in your posts:

[swf src=”http://www.example.com/file.swf” width=200 height=50]

Note: In the given shortcode replace the link address to your own SWF file address and adjust the height and width as per your needs.

Using WordPress Hack:

Here is your WP Hack. Use following code for embedding Flash directly into WordPress pages and posts etc:

<object id=”flashcontent”
classid=”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″
width=”550px”
height=”400px”>
<param name=”movie” value=”movie.swf” />
<!–[if !IE]>–>
<object type=”application/x-shockwave-flash”
data=”movie.swf”
width=”550px”
height=”400px”>
<!–<![endif]–>
<p>
Text written here will only be visible if the SWF fails to load.
</p>
<!–[if !IE]>–>
</object>
<!–<![endif]–>
</object>

WordPress Hack To Remove Certain Categories From Being Displayed

This hack is useful for those who like to display certain category to chosen or registered users only. Add the following given code inside The Loop and choose the category (number) which you wish to remove from the display.

<?php
if ( have_posts() ) : query_posts($query_string .’&cat=-1,-2′); while ( have_posts() ) : the_post();
?>

Move Across WordPress Draft, Pending And Publish Post Statuses

Don’t use register_post_status before init. Register Post Status is a function used to create and modify post status based on given parameters. register_post_status() function is located in wp-includes/post.php It accepts following two parameters:

  • $post_status means a string for the post status name
  • $args means an array of arguments

<?php register_post_status( $post_status, $args ); ?>

Example:
(Following example registers “Unread” post status:

function my_custom_post_status(){
register_post_status( ‘unread’, array(
‘label’ => _x( ‘Unread’, ‘post’ ),
‘public’ => true,
‘exclude_from_search’ => false,
‘show_in_admin_all_list’ => true,
‘show_in_admin_status_list’ => true,
‘label_count’ => _n_noop( ‘Unread <span class=”count”>(%s)</span>’, ‘Unread <span class=”count”>(%s)</span>’ ),
) );
}
add_action( ‘init’, ‘my_custom_post_status’ );

Where:

  • label is a descriptive name for the post status marked for translation.
  • public – Set true to show posts of this status in the front end. Defaults to false.
  • exclude_from_search – Set true to exclude posts with this post status in search results. Defaults to false.
  • show_in_admin_all_list – Defines whether to include posts in the edit listing for their post type.
  • show_in_admin_status_list – Shows in the list of statuses with post counts. Example: Published (12)
  • label_count – The text to display on admin screen or you won’t see status count.

Hide Post Images Without Removing Thumbnail Image In Category Archive

Given code hides post images but keeps thumbnail image in Category archive and homepage. Add following code block in your theme’s function.php:

function wpi_image_content_filter($content){

if (is_home() || is_front_page() || is_category()){
$content = preg_replace(“/<img[^>]+>/i”, “”, $content);
}

return $content;
}
add_filter(‘the_content’,’wpi_image_content_filter’,11);

Create Your Own Proxy Website Using WordPress

Governments all over the world are trying to censor Internet. They are seeking ways to limit free speech by blocking content on the web. Here using RePress you will learn to get those websites online again for you and the world without any hassle. Your website will become a proxy for the blocked website, rerouting any traffic from a user, through your website to the blocked site.

Although there are already many proxy websites providing access to blocked content but you may have your own proxy website if you don’t want to submit your details to other website.

For example: When you login to a blocked website from a proxy; your details are submitted there so if you respect your privacy then you may own your own proxy.

Follow these steps:

  1. Visit your WordPress Dashboard.
  2. Move to Plugins >> Add New
  3. Search RePress >> Click Install >> Click Activate.
  4. Now visit Settings >> RePress
  5. Add the Domain names you would like to access.
  6. Your Proxy Server is ready now.