Support » Plugin: Post Snippets » [Plugin: Post Snippets] PHP code snippet doesn't work on get_post_snippet in the theme

  • Resolved 9steps

    (@9steps)


    PHP code snippet doesn’t work on get_post_snippet function in a theme.
    Any help?


    Snipet

    Title: test
    Shortcode Options: PHP Code
    Snippet: echo “test snippet”;

    <?php echo get_post_snippet(‘test’); ?>

    get_post_snippet function doesn’t put out the text
    ‘test snippet’ but the whole php code text ‘echo “test snippet”;’

    http://wordpress.org/extend/plugins/post-snippets/

Viewing 1 replies (of 1 total)
  • I made a little hack for the problem.

    added this code in post-snippets.php(line 690 between the function “get_snippet”):

    public function get_snippet( $snippet_name, $snippet_vars = '' )
    	{
    		$snippets = get_option( self::PLUGIN_OPTION_KEY );
    
    		for ($i = 0; $i < count($snippets); $i++) {
    			if ($snippets[$i]['title'] == $snippet_name) {
    				parse_str( htmlspecialchars_decode($snippet_vars), $snippet_output );
    				$snippet = $snippets[$i]['snippet'];
    				$var_arr = explode(",",$snippets[$i]['vars']);
    
    				if ( !empty($var_arr[0]) ) {
    					for ($j = 0; $j < count($var_arr); $j++) {
    						$snippet = str_replace("{".$var_arr[$j]."}", $snippet_output[$var_arr[$j]], $snippet);
    					}
    				}
    
    /* ---- added this code  */
    				if ($snippets[$i][php] == TRUE) {
    					$snippet = stripslashes($snippet);
    					ob_start();
    					eval ($snippet);
    					$snippet = ob_get_clean();
    					$snippet = addslashes( $snippet );
    				}
    /* ---- added this code  */
    
    			}
    		}
    		return $snippet;
    	}

    and now, get_post_snippet function with php code option in a theme works OK.

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Post Snippets] PHP code snippet doesn't work on get_post_snippet in the theme’ is closed to new replies.