Make id column as AUTO INCREMENT on plugin activation

Add the autoincrement keyword after `id` int NOT NULL: public static function activate() { global $wpdb; $sql = “CREATE TABLE `{$wpdb->base_prefix}employee` ( `id` int NOT NULL autoincrement, `name` varchar(255) NOT NULL, `dob` date NOT NULL, `gender` int NOT NULL, `email` varchar(255) NOT NULL, `joining_date` date NOT NULL, `address` varchar(255) NOT NULL, `salary_package` int NOT NULL, … Read more

Is there a built in function to see if a URLis oEmbed Compatible?

wp-includes/class-oembed.php has a public variable $providers. So you can build a small function to get all of them: function list_oembed_providers( $print = TRUE ) { require_once( ABSPATH . WPINC . ‘/class-oembed.php’ ); $oembed = _wp_oembed_get_object(); $print and print ‘<pre>’ . htmlspecialchars( var_export( $oembed->providers, TRUE ) ) . ‘</pre>’; return $oembed->providers; } If you call this … Read more

Limit get_pages to only show 5 items

I have had similar problems with the number attribute in get_pages() I got around it by using get_children: $pages = get_children(array( ‘numberposts’ =>1, ‘post_parent’ => $heading_page->post_id )); and using post_parent instead of child_of.

WordPress override bloginfo variable

For the example you mentioned, you can add a filter to the stylesheet_directory hook add_filter(‘stylesheet_directory’,’change_stylesheet_dir’) ; function change_stylesheet_dir($stylesheet_dir, $stylesheet, $theme_root) { # do stuff – change the stylesheet directory $new_stylesheet_directory = ‘http://mysites.com/hello/’; return new_stylesheet_directory ; } For any of the other parameters for bloginfo, you can look at the code for for bloginfo, which is … Read more

Custom excerpt function re-factoring

I’d simply set a flag as second input argument for the function: function new_wp_trim_excerpt( $text, $case=”plain” ) { switch ( $case ) { default : case ‘plain’ : // do stuff – your function so far break; case ‘image’ : break; } } Notes: Avoid names like class=”moarplz”. It’s hard to read for others and … Read more