Tag Archives: PHP

How To Replace Default WordPress Text Widgets To Use Javascript, Flash Etc ?

By default WordPress doesn’t lets you use JavaScript in its default text widgets. There are some WordPress themes that automatically allows JS in text widgets after activation. Earlier we discussed about a plugin that allows you to use JavaScript inside your WordPress blog posts and pages, we have also posted a tutorial on a plugin that lets you use PHP in text widgets and another tutorial on plugin that lets you use PHP inside blog posts, pages and other content types etc.

Continue reading How To Replace Default WordPress Text Widgets To Use Javascript, Flash Etc ?

Create Snippet Library Of Text, HTML Or PHP To Use In WordPress Posts Via Shortcodes

Post Snippets is a popular WordPress plugin that allows you to easily create a library of Text, HTML or PHP code touse inside your blog posts, pages and other custom post types etc. All created snippets can be used directly from WordPress Visual Editor using its button. You can as many snippets you want and even you can export and import them to you in other WordPress sites you own.

Continue reading Create Snippet Library Of Text, HTML Or PHP To Use In WordPress Posts Via Shortcodes

How To Insert And Execute PHP Code Using A Text Widget In WordPress ?

All WordPress bloggers know about Text Widget. It is present on every WordPress site and we use it for showing arbitrary Text and HTML code on your blog’s sidebar or any other widget area you have in your theme. Earlier we discussed about a plugin that allows you to use WordPress Visual Editor and TinyMCE buttons in Text Widget. This article is about another widget plugin that allows you to use PHP code (including HTML too) in a text widget added by this plugin.

Continue reading How To Insert And Execute PHP Code Using A Text Widget In WordPress ?

Add Debug Bar Showing Query, Cache, And Other Helpful Information On Debugging In WordPress

WordPress developers launched WordPress.Com’s debug bar for Self Hosted WordPress Blogs . It adds a debug menu to WP admin bar that shows query, cache, and other helpful debugging information. Good for developers.

Continue reading Add Debug Bar Showing Query, Cache, And Other Helpful Information On Debugging In WordPress

Display Your Host’s PHP, MySQL & Memcached Information On WordPress Dashboard

Display your host’s PHP, MySQL & Memcached (if installed) information on your WordPress site dashboard.

Continue reading Display Your Host’s PHP, MySQL & Memcached Information On WordPress Dashboard

It Is Possible To Auto Post Your WordPress Blog On Google Plus

I know Google Plus only provides a read only API hence creating auto posting apps for Google Plus is yet not possible but PHP solves this problem. Dmitry Sandalov’s standalone PHP script makes auto publishing to Google+ possible.

Continue reading It Is Possible To Auto Post Your WordPress Blog On Google Plus

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 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);

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);

PHP Was Never Written In Perl

Morons keep assuming that PHP was written in Perl. Wikipedia is spreading this false notion. Wikipedians take words of Rasmus Lerdorf less reliable. It is visible on Wikipedia page history that many tried to correct this mistake but its bureaucratic approach had undone all that.

Even the creator of PHP Rasmus Lerdorf  himself says that PHP was never witten in Perl and real world doesn’t require any other source not even Wikipedia to confirm the truth. Simply learn PHP and it is not Perl. Actually Wikipedia was using the Wiki written in Pearl before Magnus Manske actually recreated Wikipedia in PHP. That very stuff is named by Wiki Media Foundation  as MediaWiki.

Know what PHP is: PHP is one of the most popular and widely used server side scripting language which used for creating dynamic webcontent and applications that interact with the user offering customized information. PHP originally stood for Personal Home Pages but somewhere the acronym get changed to Hypertext Pre-processor.

PHP has given new dimensions to the lives of Jimmy Wales, Mark Zuckerberg and many others. Where Jimmy Wales started from Bomis.Com providing free to premium access of users to X-rated content. Later-on he gained huge amount of credibility after founding Wikipedia. And Mark Zuckerberg, who had almost no friends created Facebook which is now the largest social networking system.

Wikipedia and Facebook are different frameworks but they both run on PHP. WordPress is also PHP programmed most popular blogging platform. So better don’t take any wrong idea about this dominant web-technology. PHP was never written in Perl and in this regard Wikipedia is less reliable than Rasmus Lerdorf.

Listing MySQL Databases

For showing all database:

SHOW DATABASES;

In case you need to filter database by name:

SHOW DATABASES LIKE ‘pattern’;

For complex filtering of database use WHERE Clause:

SHOW DATABASES WHERE conditions;

With WHERE clause one can use regular expressions like ‘<‘ and ‘>’ operators, string functions etc. for filtering records returned by SHOW DATABASES.