Plugin Directory

Changeset 1422879


Ignore:
Timestamp:
05/24/2016 06:34:57 AM (10 years ago)
Author:
Brendanw7
Message:

You can now use your own custom php functions in your shortcodes.

Location:
wp-shortcode-creator/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • wp-shortcode-creator/trunk/bw-shortcode-creator.php

    r1420591 r1422879  
    6161            $bwshortcodecreator_timestamp = time();
    6262            $bwshortcodecreator_shortcode_attributes = '';
     63            $bwshortcodecreator_shortcode_enable_php = '';
     64            $bwshortcodecreator_shortcode_php = '';
    6365            $bwshortcodecreator_shortcode_nicename = esc_sql($_POST['bwshortcodecreator_shortcode_nicename']);
    6466           
     
    7274                    'shortcode_content' => $bwshortcodecreator_shortcode_content,
    7375                    'shortcode_nicename' => $bwshortcodecreator_shortcode_nicename,
    74                     'shortcode_attributes' => $bwshortcodecreator_shortcode_attributes
     76                    'shortcode_attributes' => $bwshortcodecreator_shortcode_attributes,
     77                    'shortcode_enable_php' => $bwshortcodecreator_shortcode_enable_php,
     78                    'shortcode_php' => $bwshortcodecreator_shortcode_php
    7579                )
    7680            );
     
    8993            $bwshortcodecreator_shortcode_nicename = esc_sql($_POST['bwshortcodecreator_shortcode_nicename']);
    9094            $bwshortcodecreator_id = esc_sql($_POST['bwshortcodecreator_edit_shortcode_id']);
    91            
     95            if(isset($_POST['bwshortcodecreator_shortcode_enable_php'])) {
     96                $bwshortcodecreator_shortcode_enable_php = 1;
     97                $bwshortcodecreator_shortcode_php = esc_sql($_POST['bwshortcodecreator_shortcode_php']);
     98            } else {
     99                $bwshortcodecreator_shortcode_enable_php = 0;
     100                $bwshortcodecreator_shortcode_php = esc_sql($_POST['bwshortcodecreator_shortcode_php']);
     101            }
     102
    92103            $table_name = $wpdb->prefix.'bwshortcodecreator';
    93104           
     
    99110                    'shortcode_content' => $bwshortcodecreator_shortcode_content,
    100111                    'shortcode_nicename' => $bwshortcodecreator_shortcode_nicename,
    101                     'shortcode_attributes' => $bwshortcodecreator_shortcode_attributes
     112                    'shortcode_attributes' => $bwshortcodecreator_shortcode_attributes,
     113                    'shortcode_enable_php' => $bwshortcodecreator_shortcode_enable_php,
     114                    'shortcode_php' => $bwshortcodecreator_shortcode_php
    102115                ),
    103116                array( 'id' => $bwshortcodecreator_id )
     
    117130            $wpdb->delete(
    118131                $table_name,
    119                 array( 'id' => $bwshortcodecreator_id )
     132                array('id' => $bwshortcodecreator_id)
    120133            );
    121134        }
  • wp-shortcode-creator/trunk/inc/add_shortcodes.php

    r1420591 r1422879  
    99            $bwshortcodecreator_shortcode_content= $row->shortcode_content;
    1010            $bwshortcodecreator_shortcode_attributes = $row->shortcode_attributes;
     11            $bwshortcodecreator_shortcode_enable_php = $row->shortcode_enable_php;
     12            $bwshortcodecreator_shortcode_php = $row->shortcode_php;
    1113            $id = $row->id;
    1214            $bwshortcodecreator_function_name = 'bwshortcodecreator_'.$id;
    1315            eval("add_shortcode( '".$bwshortcodecreator_shortcode_title."', '".$bwshortcodecreator_function_name."' );");
    14             eval(" function ".$bwshortcodecreator_function_name."() {   
    15                return '".bwshortcodecreator_mynl2br($bwshortcodecreator_shortcode_content)."';
    16               }"
    17            );
     16            if($bwshortcodecreator_shortcode_enable_php == 1) {
     17                eval(" function ".$bwshortcodecreator_function_name."() {
     18                    \$custom_php = ".$bwshortcodecreator_shortcode_php.";
     19                    return bwshortcodecreator_mynl2br(\$custom_php);
     20                    }"
     21                );
     22            } else {
     23                eval(" function ".$bwshortcodecreator_function_name."() {   
     24                    return '".bwshortcodecreator_mynl2br($bwshortcodecreator_shortcode_content)."';
     25                    }"
     26                );
     27            }
    1828         }
    1929    }
  • wp-shortcode-creator/trunk/inc/bwshortcodecreator-dbcreate.php

    r1420591 r1422879  
    11<?php
    2 
    3 
    4 
    52function bwshortcodecreator_dbcreate() {
    6 
    73    global $wpdb;
    8 
     4    $table_name = $wpdb->prefix . "bwshortcodecreator";
     5    $charset_collate = $wpdb->get_charset_collate();
    96   
    10 
    11     $table_name = $wpdb->prefix . "bwshortcodecreator";
    12 
     7    $sql = "CREATE TABLE $table_name (
     8      id mediumint(9) NOT NULL AUTO_INCREMENT,
     9      timestamp varchar(30) NOT NULL,
     10      shortcode_title varchar(100) NOT NULL,
     11      shortcode_nicename varchar(100) NOT NULL,
     12      shortcode_attributes varchar(500) NOT NULL,
     13      shortcode_enable_php int(1) NOT NULL,
     14      shortcode_php varchar(5000) NOT NULL,
     15      shortcode_content varchar(5000) NOT NULL,
     16      UNIQUE KEY id (id)
     17    ) $charset_collate;";
    1318   
    14 
    15     $charset_collate = $wpdb->get_charset_collate();
    16 
    17    
    18 
    19     $sql = "CREATE TABLE $table_name (
    20 
    21       id mediumint(9) NOT NULL AUTO_INCREMENT,
    22 
    23       timestamp varchar(30) NOT NULL,
    24 
    25       shortcode_title varchar(100) NOT NULL,
    26 
    27       shortcode_nicename varchar(100) NOT NULL,
    28 
    29       shortcode_attributes varchar(500) NOT NULL,
    30 
    31       shortcode_content varchar(10000) NOT NULL,
    32 
    33       UNIQUE KEY id (id)
    34 
    35     ) $charset_collate;";
    36 
    37    
    38 
    3919    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    40 
    4120    dbDelta( $sql );
    42 
    43    
    44 
    45     $bwshortcodecreator_title = 'exampleshortcode';
    46 
    47     $bwshortcodecreator_content = 'This is an example shortcode';
    48 
    49     $bwshortcodecreator_timestamp = time();
    50 
    51     $bwshortcodecreator_nicename = 'Example Shortcode';
    52 
    53     $bwshortcodecreator_attributes = '';
    54 
    55    
    56 
    57     $wpdb->insert(
    58 
    59         $table_name,
    60 
    61         array(
    62 
    63             'timestamp' => $bwshortcodecreator_timestamp,
    64 
    65             'shortcode_title' => $bwshortcodecreator_title,
    66 
    67             'shortcode_content' => $bwshortcodecreator_content,
    68 
    69             'shortcode_nicename' => $bwshortcodecreator_nicename,
    70 
    71             'shortcode_attributes' => $bwshortcodecreator_attributes
    72 
    73         )
    74 
    75     );
    76 
    7721}
    78 
    7922?>
  • wp-shortcode-creator/trunk/inc/options-page-wrapper.php

    r1420591 r1422879  
    44?>
    55<div class="wrap">
    6     <h1 class="bwsc_title"><?php esc_attr_e( 'Video Dropdown Settings', 'wp_admin_style' ); ?></h1>
     6    <h1 class="bwsc_title"><?php esc_attr_e( 'Shortcode Creator Settings', 'wp_admin_style' ); ?></h1>
    77    <div id="bwsc_menu">
    88        <?php
     
    2222                                $shortcode_attributes = $row->shortcode_attributes;
    2323                                $shortcode_nicename = $row->shortcode_nicename;
     24                                $shortcode_enable_php = $row->shortcode_enable_php;
     25                                $shortcode_php = $row->shortcode_php;
    2426                                $shortcode_timestamp = $row->timestamp;
    2527                                $shortcode_id = $row->id;
     
    4648                                    <label for="bwshortcodecreator_shortcode_content">Shortcode Content</label>
    4749                                    <div id="poststuff">
    48                                     <?php the_editor(bwshortcodecreator_mynl2br($shortcode_content),'bwshortcodecreator_shortcode_content'); ?>
     50                                        <?php the_editor(bwshortcodecreator_mynl2br($shortcode_content),'bwshortcodecreator_shortcode_content'); ?>
    4951                                    </div>
    5052                                   
     
    6062                                    <br />
    6163                                    <br />-->
     64                                   
     65                                    <?php
     66                                    if($shortcode_enable_php == 1) {
     67                                        ?>
     68                                        <input type="checkbox" name="bwshortcodecreator_shortcode_enable_php" id="bwshortcodecreator_shortcode_enable_php" checked /> <label>Enable custom PHP</label>
     69                                        <?php
     70                                    } else {
     71                                        ?>
     72                                        <input type="checkbox" name="bwshortcodecreator_shortcode_enable_php" id="bwshortcodecreator_shortcode_enable_php" /> <label>Enable custom PHP</label>
     73                                        <?php
     74                                    }
     75                                    ?>
     76                                   
     77                                    <p>Please note, checking this box will disable the text box above. It will still be saved, but not used until you uncheck the box, upon which the same will happen to the boc below</p>
     78                                   
     79                                    <br />
     80
     81                                    <label for="bwshortcodecreator_shortcode_php">Shortcode PHP (Advanced)</label>
     82                                   
     83                                    <br />
     84                                   
     85                                    <?php
     86                                    if($shortcode_enable_php == 1) {
     87                                        ?>
     88                                        <input type="text" name="bwshortcodecreator_shortcode_php" id="bwshortcodecreator_shortcode_php" class="regular-text" value="<?php echo $shortcode_php; ?>">
     89                                        <?php
     90                                    } else {
     91                                        ?>
     92                                        <input type="text" name="bwshortcodecreator_shortcode_php" id="bwshortcodecreator_shortcode_php" class="regular-text" value="<?php echo $shortcode_php; ?>" disabled="disabled">
     93                                        <?php
     94                                    }
     95                                    ?>
     96                                    <h3>How to use PHP in Shortcode Creator</h3>
     97                                    <p>Inside your function you must <strong>return</strong> your visible output, if any.</p>
     98                                    <ol>
     99                                        <li>Navigate to 'Appearance->Editor'</li>
     100                                        <li>On the top right, choose your current theme in the dropdown box and hit select</li>
     101                                        <li>On the right side, find your theme's 'functions.php' file</li>
     102                                        <li>In that file, create a function with any name you want, and write your PHP code within that function. If you need to include variables/parameters, set them before you define your function</li>
     103                                        <li>Now, you just have to call the function in the input above</li>
     104                                    </ol>
     105                                    <p>An example of correct use of the line above: <strong><i>my_fucntion();</i></strong> or <strong><i>my_fucntion($param1, $param2);</i></strong></p>
     106                                    <p><strong>WARNING:</strong> Do not type anything besides your function in the above input. You could break something otherwise.</p>
     107                                    <br />
     108                                    <br />
    62109                                   
    63110                                    <input class="button-primary" type="submit" name="bwshortcodecreator_edit_shortcode_submit" value="Save" />
  • wp-shortcode-creator/trunk/js/bwshortcodecreator_js.js

    r1420591 r1422879  
    1212        jQuery(this).next('.bwsc_content').slideDown('fast');
    1313    });
     14   
     15    jQuery('#bwshortcodecreator_shortcode_enable_php').change(function() {
     16        if(this.checked) {
     17             jQuery('#bwshortcodecreator_shortcode_php').removeAttr("disabled");
     18             jQuery('#bwshortcodecreator_shortcode_content').attr("disabled", "disabled");
     19        } else {
     20             jQuery('#bwshortcodecreator_shortcode_php').attr("disabled", "disabled");
     21             jQuery('#bwshortcodecreator_shortcode_content').removeAttr("disabled");
     22        }
     23    });
    1424});
  • wp-shortcode-creator/trunk/readme.txt

    r1420591 r1422879  
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1010
     11This plugin allows users to create and customize shortcodes to their liking
     12
    1113== Description ==
    1214
     
    1517With Shortcode Creator you are able to create shortcodes to be used anywhere in the wordpress system.
    1618You can simply use the wordpress rich text editor to customize your shortcodes output without needing to know a single line of code.
     19Or if you know how to write php code you can even use your own cutom functions in php!
    1720
    1821== Installation ==
Note: See TracChangeset for help on using the changeset viewer.