samedi 31 octobre 2015

How can i give my short code a parameter that I can use for my wpdb->insert

I am using the following plugin but I need to have a attribute called player id here. How would I go about that cause I need to be able to use my player id shorcode attribute in my insert as I cant seem to get the post value of a form when im using a short code ?.

<?php
    /*
    Plugin Name: David Buckley Go Green Redeem Points
    Plugin URI: http://ift.tt/1Kcb1BO
    Version: 1.01
    License: Plugin comes under GPL Licence.
    */
    //Include Javascript library
    wp_enqueue_script('gogreen', plugins_url( '/js/readeempoints.js' , __FILE__ ) , array( 'jquery' ));
    // including ajax script in the plugin Myajax.ajaxurl
    wp_localize_script( 'gogreen', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php')));
    function updateRedeemPoints(){
    $playerId = $_POST['playerId'];
    $points=$_POST['points'];
    global $wpdb;
    $wpdb->insert( 
        '4hSIc_pods_player_ranking', 
        array( 
            'points_to_redeem' =>$points,
            'player_id'=>'339393',
            'date_to_be_awarded' => current_time('mysql', 1),
            'approved'=>'false'

        ));


    echo 'test';
    }
    add_action('wp_ajax_updateRedeemPoints', 'updateRedeemPoints');
    add_action('wp_ajax_nopriv_updateRedeemPoints', 'updateRedeemPoints');
            function show_form(){


                echo "<div id='thanks' class='modal fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>";
                echo "<div class='modal-dialog'>";
                echo "<div class='modal-content'>";
                echo "<div class='modal-header'>";
                echo "<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>";
                echo "<h4 class='modal-title'>Redeem Points</h4>";
                echo "</div>";
                    echo "<form class='form-horizontal'  class='contact' name='redemmpointsForm' id='redemmpointsForm' >";
                    echo " <div class='form-group'>";
                    echo "<h3>You may only redeem the maxium points of : <?php echo $maxpoints;?></h3>";
                    echo "<input type='hidden' name='playerid' value='<?php echo $playerId;;?>' />";
                    echo "<input type='number'  valuemax='<?php echo $maxpoints;?>' name='points' id='points' class='form-control' placeholder='How many points do you wish to redeem.' />";
                    echo "<label class='control-label col-md-4' for='Comments'>Comments?</label>";
                    echo "<input type='text' name='comments' />";

                    echo "     </div>";
                    echo "    <div class='form-group'>";
                    echo "            <div class='col-md-6'>";
                    echo "                <input type='button' class='btn btn-success' name='submit' id='submit' Text='Submit'>";
                    echo "     <a href='#' class='btn' data-dismiss='modal'>Close</a>";
                    echo "         </div>";
                    echo "      </div>";
                    echo "</form>";
                echo "      </div>";
                        echo "      </div>";
                            echo "      </div>";
        }



    add_shortcode( 'go_greenredempoints', 'gs_redeemplugin' );

    function gs_redeemplugin($atts) {


        ob_start();

         extract( shortcode_atts( array(
            'playerId' => 'myvalue'

        ), $atts ) );




        show_form();
        return ob_get_clean();
    }
?>

Also I wish to echo back a message to the user which I can append onto another messagbox to the end user what is the best way of doing this.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire