Proper use of Output Buffer

No, you don’t need output buffering in this case. As a rule of thumb: Don’t use output buffering unless you really have to. Just imagine what happens if someone else uses output buffering too from a plugin and it crosses with yours: // plugin ob_start(); // later, you in your theme ob_start(); // you call … Read more

Hide main div if wp_nav_menu is empty

Assign the menu to a string: $menu = wp_nav_menu( array ( ‘echo’ => FALSE, ‘fallback_cb’ => ‘__return_false’ ) ); if ( ! empty ( $menu ) ) { echo ‘<div class=”navmain2″>’ . $menu . ‘</div>’; }

Perform an action when post is updated/published

The save_post action fires When a post is updated and/or published — including when a new post is inserted. <?php add_action( ‘save_post’, ‘wpse41912_save_post’ ); function wpse41912_save_post() { // do stuff } If you want your functions to fire only when a post is being edited, you can hook into edit_post. If you want it to … Read more

How to use the do_action () with parameter

The correct way is to pass first argument as a unique string which acts as an identifier for the action & any additional arguments after that do_action(‘unique_action_tag’, $parameter1, $parameter2,,,, & so on); To attach functions to this action you’ll do // 10 is the priority, higher means executed first // 2 is number of arguments … Read more

static variable loop not working in WordPress

Try something like this: function realistic_get_first_embed_video($post_id) { $post = get_post($post_id); $content = do_shortcode(apply_filters(‘the_content’, $post->post_content)); $embeds = get_media_embedded_in_content($content); if (!empty($embeds)) { //check what is the first embed containg video tag, youtube or vimeo $counter = 0; foreach ($embeds as $embed) { // Check condition if count is 0 then // it is the first iteration if( … Read more

What is an alternative method to the WordPress private _doing_it_wrong() function

What is an alternative method to the WordPress private _doing_it_wrong() function? There’s no way that WordPress is ever going to get rid of the _doing_it_wrong() function, so it’s perfectly safe to use it. But if for some reason you don’t want to use it because it’s marked private, then you could create a plugin that … Read more

Remote upload file to server B

Try adding die(‘message’); and use that to debug where it fails. Also try and use ftp://external-server.com as opposed to just external-server.com. Also make sure you use your FTP password. And try it on active mode as opposed to passive mode. When I was trying to upload by FTP that’s what I had to do. Also … Read more