Export all post from database to JSON only when the database gets updated

it’s file_put_contents which saves the data then it have to be in the hook and not in the body of the plugin : function export_posts_in_json () { $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ); $query = new WP_Query( $args ); … $data = json_encode($posts); $folder=”wp-content/themes/bootstrap/library/”; $file_name = date(‘Y-m-d’) . … Read more

Delete post revisions on post publish

I think a small plugin with the hook ‘publish_posts’ is enough. But I dont know about a core function to delete revisions and I use a query with WP functions. The source is untested, written only for this post. <?php /** * Plugin Name: WPSE71248 Delete Revisions on Publish Posts * Plugin URI: http://wordpress.stackexchange.com/questions/71248/ * … Read more

Add custom image sizes to media uploader

Invalid argument supplied for foreach means that the X in foreach X as … is not an array. You can prevent this error by type casting; add (array) before the argument in the foreach statement. This will turn your variable into an array, essentially. In your code, the change would be… foreach ( (array) $attach_meta[‘sizes’] … Read more

Adding Featured Image to Post programatically

For each image/post combination, run the following. $image_name is the filename, $post_id is the post ID. if( $image_name != ” && !has_post_thumbnail( $post_id ) ){ $base = get_stylesheet_directory(); $imgfile= $base . ‘/import/’ . $image_name; // Images are stored inside an imports folder, in the theme directory $filename = basename($imgfile); $upload_file = wp_upload_bits($filename, null, file_get_contents($imgfile)); if … Read more

How can i create a function to get youtube video time

The following are the functions that I use to extract data from a YouTube response to wp_remote_get. It’s just the basic stuff, you’ll have to adjust, complement and integrate into your code. add_action( ‘save_post’, ‘brsfl_save_postdata’ ); function brsfl_save_postdata( $post_id ) { // IMPORTANT! // Check for DOING_AUTOSAVE and wp_verify_nonce() $consult = brsfl_yt_api( $_POST[‘yt_id’] ); if( … Read more

Showing user ID on user main page from screen options

You need to use the filter ‘manage_’ . $screen->id . ‘_columns’ to add a column and manage_users_custom_column to display its value. add_filter( ‘manage_users_columns’, ‘column_register_wpse_101322’ ); add_filter( ‘manage_users_custom_column’, ‘column_display_wpse_101322’, 10, 3 ); function column_register_wpse_101322( $columns ) { $columns[‘uid’] = ‘ID’; return $columns; } function column_display_wpse_101322( $empty, $column_name, $user_id ) { if ( ‘uid’ != $column_name ) … Read more

How do I create a drop down menu in a widget?

This is what I do: Static Options <select id=”<?php echo $this->get_field_id(‘posttype’); ?>” name=”<?php echo $this->get_field_name(‘posttype’); ?>” class=”widefat” style=”width:100%;”> <option <?php selected( $instance[‘posttype’], ‘Option 1’); ?> value=”Option 1″>Option 1</option> <option <?php selected( $instance[‘posttype’], ‘Option 2’); ?> value=”Option 2″>Option 2</option> <option <?php selected( $instance[‘posttype’], ‘Option 3’); ?> value=”Option 3″>Option 3</option> </select> Generate with options with PHP (example) … Read more

Filter the blog title displayed in the header

Remove that filter/function and apply your markup in the PHP template/page file. If you need help post where you output the title. CLASS Here is how I might set this up using a class: if ( ! class_exists( ‘ThemeCustomizations’ ) ) { class ThemeCustomizations { static $inBody = false; public static function set_in_body_true() { static::$inBody … Read more