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

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.

PHP Array Functions

PHP Array functions need no installation. These functions are the part of PHP core.

array_change_key_case — It changes all keys in an array
array_chunk — It split an array into chunks
array_combine — It creates an array by using one array for keys and other for its values
array_count_values — It counts all the values of an array
array_diff_assoc — It computes the difference of arrays with additional index check
array_diff_key — It computes the difference of arrays using keys for comparison
array_diff_uassoc — It computes the difference of arrays with additional index check which is performed by a user supplied callback function
array_diff_ukey — It computes the difference of arrays using a callback function on the keys for comparison
array_diff — It computes the difference of arrays
array_fill_keys — It fill an array with values, specifying keys
array_fill — It fill an array with values
array_filter — It filters elements of an array using a callback function
array_flip — It exchanges all keys with their associated values in an array
array_intersect_assoc — It computes the intersection of arrays with additional index check
array_intersect_key — It computes the intersection of arrays using keys for comparison
array_intersect_uassoc — It computes the intersection of arrays with additional index check, compares indexes by a callback function
array_intersect_ukey — It computes the intersection of arrays using a callback function on the keys for comparison
array_intersect — It computes the intersection of arrays
array_key_exists — It checks if the given key or index exists in the array
array_keys — It return all the keys or a subset of the keys of an array
array_map — It applies the callback to the elements of the given arrays
array_merge_recursive — It merge two or more arrays recursively
array_merge — It merge one or more arrays
array_multisort — It sort multiple or multi-dimensional arrays
array_pad — It pad array to the specified length with a value
array_pop — It pop the element off the end of array
array_product — It calculate the product of values in an array
array_push — It push one or more elements onto the end of array
array_rand — It pick one or more random entries out of an array
array_reduce — It iteratively reduce the array to a single value using a callback function
array_replace_recursive — It replaces elements from passed arrays into the first array recursively
array_replace — It replaces elements from passed arrays into the first array
array_reverse — It return an array with elements in reverse order
array_search — It searches the array for a given value and returns the corresponding key if successful
array_shift — It shift an element off the beginning of array
array_slice — It extract a slice of the array
array_splice — It remove a portion of the array and replace it with something else
array_sum — It calculate the sum of values in an array
array_udiff_assoc —It computes the difference of arrays with additional index check, compares data by a callback function
array_udiff_uassoc — It computes the difference of arrays with additional index check, compares data and indexes by a callback function
array_udiff — It computes the difference of arrays by using a callback function for data comparison
array_uintersect_assoc — It computes the intersection of arrays with additional index check, compares data by a callback function
array_uintersect_uassoc — It computes the intersection of arrays with additional index check, compares data and indexes by a callback functions
array_uintersect — It computes the intersection of arrays, compares data by a callback function
array_unique —It removes duplicate values from an array
array_unshift — It prepend one or more elements to the beginning of an array
array_values —It return all the values of an array
array_walk_recursive — It apply a user function recursively to every member of an array
array_walk — It apply a user function to every member of an array
array — It create an array
arsort — It sort an array in reverse order and maintain index association
asort — It sort an array and maintain index association
compact — It create array containing variables and their values
count — It count all elements in an array, or something in an object
current — It return the current element in an array
each — It return the current key and value pair from an array and advance the array cursor
end —It set the internal pointer of an array to its last element
extract — It import variables into the current symbol table from an array
in_array — It checks if a value exists in an array
key — It fetch a key from an array
krsort — It sort an array by key in reverse order
ksort — It sort an array by key
list — It assign variables as if they were an array
natcasesort — It sort an array using a case insensitive “natural order” algorithm
natsort — It sort an array using a “natural order” algorithm
next — It advance the internal array pointer of an array
pos — It is the alias of current
prev — It rewind the internal array pointer
range — It create an array containing a range of elements
reset — It set the internal pointer of an array to its first element
rsort — It sort an array in reverse order
shuffle — It shuffle an array
sizeof — It alias of count
sort — It sort an array
uasort — It sort an array with a user-defined comparison function and maintain index association
uksort — It sort an array by keys using a user-defined comparison function
usort — It sort an array by values using a user-defined comparison function