WordPress.org

Ready to get started?Download WordPress

Forums

Post Snippets
[resolved] PHP code snippet doesn't work on get_post_snippet in the theme (2 posts)

  1. 9steps
    Member
    Posted 2 years ago #

    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/

  2. 9steps
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic