How To Disable WordPress Comments Completely
The following snippet will let you disable WordPress comments completely.
1 |
<?php return false; ?> |
Snippet Source/Credit: aotearoawebdesign.co.nz
How To Add PayPal Button To Your WordPress Website
Using the following snippet will let you add PayPal button to your WordPress website. Remember to add the snippet to your theme’s functions.php file and you are done.
1 2 3 4 5 6 7 8 9 10 11 12 |
// paypal donate button function cwc_donate_shortcode( $atts ) { extract(shortcode_atts(array( 'text' => 'Make a donation', 'account' => 'REPLACE ME', 'for' => '', ), $atts)); global $post; if (!$for) $for = str_replace(" ","+",$post->post_title); return '<a class="donateLink" href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business='.$account.'&item_name=Donation+for+'.$for.'">'.$text.'</a>'; } add_shortcode('donate', 'cwc_donate_shortcode'); |
Snippet Source/Credit: Snipplr
How To Deactivate All WordPress Plugins
Using the following line of snippets, you will be able to deactivate all WordPress plugins.
1 |
UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins'; |
How To Delete WordPress Post Revision From Database
The following snippet will let you delete WordPress post revision from the database.
1 2 3 4 5 |
DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision' |
Snippet Source/Credit: lesterchan.net
How To Display Recent Posts From All Sites
The following snippet will display recent posts from all sites.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
function recent_mu_posts( $howMany = 10 ) { global $wpdb; global $table_prefix; // get an array of the table names that our posts will be in // we do this by first getting all of our blog ids and then forming the name of the // table and putting it into an array $rows = $wpdb->get_results( "SELECT blog_id from $wpdb->blogs WHERE public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0';" ); if ( $rows ) : $blogPostTableNames = array(); foreach ( $rows as $row ) : $blogPostTableNames[$row->blog_id] = $wpdb->get_blog_prefix( $row->blog_id ) . 'posts'; endforeach; # print_r($blogPostTableNames); # debugging code // now we need to do a query to get all the posts from all our blogs // with limits applied if ( count( $blogPostTableNames ) > 0 ) : $query = ''; $i = 0; foreach ( $blogPostTableNames as $blogId => $tableName ) : if ( $i > 0 ) : $query.= ' UNION '; endif; $query.= " (SELECT ID, post_date, $blogId as `blog_id` FROM $tableName WHERE post_status = 'publish' AND post_type = 'post')"; $i++; endforeach; $query.= " ORDER BY post_date DESC LIMIT 0,$howMany;"; # echo $query; # debugging code $rows = $wpdb->get_results( $query ); // now we need to get each of our posts into an array and return them if ( $rows ) : $posts = array(); foreach ( $rows as $row ) : $posts[] = get_blog_post( $row->blog_id, $row->ID ); endforeach; # echo "<pre>"; print_r($posts); echo "</pre>"; exit; # debugging code return $posts; else: return "Error: No Posts found"; endif; else: return "Error: Could not find blogs in the database"; endif; else: return "Error: Could not find blogs"; endif; } |
Snippet Source/Credit: Snipplr