Plugin Directory

Changeset 988085


Ignore:
Timestamp:
09/12/2014 08:32:29 AM (12 years ago)
Author:
lilmike
Message:

Added the ability to run php inside posts, and fixed several minor to severe bugs that may have affected php.

Location:
2mb-autocode/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 2mb-autocode/trunk/2mb-autocode.php

    r987913 r988085  
    5151        $top = 0;
    5252    }
    53     if($count3 > 0 && !is_single()) {
     53    if(($count3 > 0 && !is_single()) || get_option('2mb_autocode_tophome') == 0) {
    5454        $top = 0;
    5555    }
     
    6060        $bottom = 0;
    6161    }
    62     if($count4 > 0 && !is_single()) {
     62    if(($count4 > 0 && !is_single()) || get_option('2mb_autocode_tophome') == 0) {
    6363        $bottom = 0;
    6464    }
     
    7474    if($top == 1) {
    7575        if(get_option('2mb_autocode_toptype') == 1) {
    76             $content = do_shortcode(exec(get_option('2mb_autocode_topstring'))).$content;
     76            ob_start();
     77            eval(get_option('2mb_autocode_topstring'));
     78            $string = ob_get_contents();
     79            ob_end_clean();
     80            $content = do_shortcode($string).$content;
    7781        }
    7882        else if(get_option('2mb_autocode_toptype') == 2) {
     
    8589    if($bottom == 1) {
    8690        if(get_option('2mb_autocode_bottomtype') == 1) {
    87             $content = $content.do_shortcode(exec(get_option('2mb_autocode_bottomstring')));
     91            ob_start();
     92            eval(get_option('2mb_autocode_bottomstring'));
     93            $string = ob_get_contents();
     94            ob_end_clean();
     95            $content = $content.do_shortcode($string);
    8896        }
    8997        else if(get_option('2mb_autocode_bottomtype') == 2) {
     
    95103    }
    96104    return $content;
     105}
     106
     107add_action('the_content', 'do_php', 0);
     108function do_php($content) {
     109    $content = preg_replace_callback('/\[php\]((.|\n)+)\[\/php\]/', 'exec_php', $content);
     110    return $content;
     111}
     112
     113function exec_php($matches) {
     114    ob_start();
     115    eval($matches[1]);
     116    $output = ob_get_contents();
     117    ob_end_clean();
     118    return $output;
    97119}
    98120
  • 2mb-autocode/trunk/readme.txt

    r984821 r988085  
    11=== 2MB Autocode ===
    22Contributors: lilmike, stormdragon2976
    3 Donate link: http://2mb.solutions/
     3Donate link: http://2mb.solutions/donate
    44Tags: autocode, code placement, automatic, php, html, preformatted text, top, bottom, modify posts
    55Requires at least: 2.7.0
    66Tested up to: 4.0
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1313== Description ==
    1414
    15 This plugin, developed by [2MB Solutions](http://2mb.solutions/), allows you to place predetermined text/html/php at the top and/or bottom of each post. In addition, you can override the placing of text at the bottom and/or top of a specific post.
     15This plugin, developed by [2MB Solutions](http://2mb.solutions/), allows you to place predetermined text/html/php at the top and/or bottom of each post. In addition, you can override the placing of text at the bottom and/or top of a specific post, override the placing of text on the homepage or on a post individually, or run arbitrary php inside a post.
    1616
    1717For more on 2MB, please visit (http://2mb.solutions/).
     
    4040We're glad you asked! We're always looking for new ways to improve, whether in the realm of new plugins, or upgrading existing ones. Please go to our [website](http://2mb.solutions/), and click contact us. There you will be able to email us a message. Rest assured we read every email we receive and strive to respond to as many as possible!
    4141
     42= How do I run php inside a post? =
     43
     44Simply enclose the php you want to run inside [php and ]/php] tags.
     45
     46For example, to echo hello world in the middle of a post, do the following:
     47
     48[php] echo("hello world!");[/php]
     49
    4250== Screenshots ==
    4351
     
    4654== Changelog ==
    4755
     56= 1.1 =
     57*Added ##do_top## and  ##do_bottom## to place the bottom or top text anywhere in a post.
     58*Added ##no_top_home##, ##no_bottom_home##, ##no_top_post##, and ##no_bottom_post## to override the placing of text specifically on the home or post pages.
     59*Added [php] PHP CODE HERE [/php] to run php inside a post.
     60*Very important! Fixed an issue where php at the top or bottom of posts would not run, and could possibly crash programs or make them not work correctly.
     61*Fixed a possible bug where php code in the top or bottom of the post may have been echoing to the wrong part of the screen.
     62
    4863= 1.0 =
    4964*First release. woohoo!
     
    5166== Upgrade Notice ==
    5267
     68= 1.1 =
     69If you were using php at the top or bottom of a post, please upgrade to this version as this fixes a possibility that the php code would not run or the php may have echoed to the wrong part of the screen. In addition if you want to run php code in your posts without having to add it to every post, then you may like this release. Also, if you wish to turn off the placing of text on a per post basis for the home and/or single post pages, this update is for you.
     70
    5371= 1.0 =
    5472Because this plugin is awesome! Seriously, go try it! ;-)
Note: See TracChangeset for help on using the changeset viewer.