• storyday

    (@storyday)


    the codes bellow is making a static index.html when post or edit a post of wordpress by getting the buffer of index.php.
    why does it not work normally ?

    if I activated this plugin,when I post,the homepage of my blog will show in my admin panel?
    could you please help me to find what’s wrong the the out put buffer, or there is some code in WP to prevent using ob_start()?

    function writeIndex($post_ID){
    
    $ori_dir = getcwd();// save the origin dir
    
    //change the dir to index.php of wp
    // and get the index.php's output
    chdir(ABSPATH); 
    
    ob_start();
    
    include ABSPATH.'index.php';
    
    $output = ob_get_clean();
    //close the buffer of index.php
    //get the content and then write it into a static HTML file
    chdir( $ori_dir);
    
       //write the file
    
      $filename = ABSPATH.'index.html';
    
      if ( is_writable($filename ) ) {
    
    	  if ( $handle = @fopen($filename, 'w')) {
    
    		  @flock($handle ,LOCK_EX );
    
    		  // write into HTML file
    
    		  @fwrite($handle, $contents);
    
    		  @flock($handle, LOCK_UN);
    
    		  fclose($handle); 
    
    		  }
    	  }
    
    }
    add_action('publish_post', 'writeIndex');
    add_action('delete_post', 'writeIndex');

    but these codes without WP seems work very well
    header
    <?php

    ob_start();

    echo “Hello World”;

    $contents = ob_get_clean();

    $filename = ‘index.html’;

    if (is_writable($filename)) {

    if ( $handle = fopen($filename, ‘w’)) {

    @flock($handle ,LOCK_EX );

    fwrite($handle, $contents);

    @flock($handle, LOCK_UN);

    fclose($handle);

    }
    }
    ?>
    footer

  • The topic ‘why this plugin does not work,ob_start() problem’ is closed to new replies.