• Resolved Mauricio Gofas

    (@mauriciogofas)


    Hello!
    I need to add a field “mycred manual adjustments” after entry details in Gravity forms received messages.
    To add a table at the end of the details I am using the following code:

    add_action("gform_entry_detail","add_to_details", 10, 2);
    
    function add_to_details($form, $lead)
    
    {
    
        if ($form["id"] == 9)
    
        {
    
            echo '<table class="widefat fixed entry-detail-view" cellspacing="0">
    	<thead>
    	 <tr>
    	  <th style="background:#ebf2ff;"><h3>Adjust points for entry creator</h3></th></tr>
    	   </thead>
    	    <tbody>
    		 <tr>
    	      <td>
    
    	Code for manual balance adjustment here... 
    
    	   </td>
    	  </tr>
    	 </tbody>
    	</table>';
    
        }
    
    }

    Now I need help to integrate the addition of points in the table, the whole idea is appreciated!

    https://wordpress.org/plugins/mycred/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author myCred

    (@designbymerovingi)

    Hi.

    Actually I have added this in to 1.4.6 where you can set two hidden fields to override how many points a form gives and even what log entry template you want to use.

    When creating / editing a form, add a hidden field and set the label to:

    mycred_amount

    Under Advanced, set the default value to the amount you want to give.

    Do the same thing to override the log entry template by using the:

    mycred_entry

    as label instead. Note that these label names are case sensitive and must be exact. Extra whitespace in the label for example will not override your default settings!

    Thread Starter Mauricio Gofas

    (@mauriciogofas)

    Oh, this is really cool! But unfortunately it is not what I need…. 😐

    I need to add custom points manually in the message editor,
    my idea was to display the text field (no dropdown) “User Adjust Balance” located in /wp-admin/user-edit.php, in the visualization of the received message, located in
    /wp-admin/admin.php?page=gf_entries&view=entry&id=X&lid=XXXX

    This image illustrates what I need:
    http://www.starsclubbrasil.com.br/up/sites/163/Captura-de-Tela-2014-06-11-%C3%A0s-13.15.40.png

    Tanks for rapid reply!

    Plugin Author myCred

    (@designbymerovingi)

    Ah see, I did misunderstand you. Sorry about that.

    Ok so you want the manual adjustment form to be inserted into the bottom of that page.

    I would use the myCRED Admin Module and utilize the methods this class module offers.

    add_action( 'gform_entry_detail', 'adjust_mycred_balance_form', 10, 2 );
    function adjust_mycred_balance_form( $form, $lead ) {
    
    	// Requiremens
    	if ( $form['id'] != 9 || ! class_exists( 'myCRED_Admin' ) || ! current_user_can( 'edit_users' ) ) return;
    
    	// Load myCRED Admin Module
    	$mycred_admin = new myCRED_Admin();
    
    	// Get the user object
    	$user = get_userdata( absint( $lead['created_by'] ) );
    	if ( ! isset( $user->ID ) ) return;
    
    	// If form is submitted, process it now
    	if ( isset( $_POST['myCRED-manual-add-points'] ) )
    		$mycred_admin->adjust_points_manually( $user->ID );
    
    	// Hack for the adjust_users_balance() method
    	if ( ! defined( 'IS_PROFILE_PAGE' ) )
    		define( 'IS_PROFILE_PAGE', true );
    	elseif ( defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE === false )
    		IS_PROFILE_PAGE = false; ?>
    
    <table class="widefat fixed entry-detail-view" cellspacing="0">
    	<thead>
    		<tr>
    			<th style="background:#ebf2ff;" colspan="2"><h3>Adjust points for entry creator</h3></th>
    		</tr>
    	</thead>
    	<tbody>
    
    	<?php $mycred_admin->adjust_users_balance( $user ); ?>
    
    	</tbody>
    </table>
    <?php
    }

    Thread Starter Mauricio Gofas

    (@mauriciogofas)

    Cool, Gabriel! Thank you very much!!!!
    Do not apologize, maybe I have not expressed myself well …

    I do not intend to take more of your time, just two more questions:

    1 – I created a simple plugin with the code, but my Dreamweaver shows a syntax error at line 32 (” IS_PROFILE_PAGE = false;>?”), I delete this line and it worked perfectly! :D…
    it will be missed?

    2 – How can I do to pick just one custom point type for each form? For this function would be best just a text field, era instead of a dropdown (forgive me if the code already has this)

    The complete plugin:

    <?php
    /*
    Plugin Name: Mycred Manualy Points Addon in Gravity Entries
    Plugin URI: http://myCRED.me
    Description: Adiciona Campos personalizados no editor de solicitação de pontos.
    Version: 1.2
    Author: Gabriel Merovingi (myCRED Creator)
    Author URI: http://myCRED.me
    */
    // Mycred custom points in Gravity entries editor
    add_action( 'gform_entry_detail', 'adjust_mycred_balance_form', 10, 2 );
    function adjust_mycred_balance_form( $form, $lead ) {
    
    	// Requiremens
    	if ( $form['id'] != 9 || ! class_exists( 'myCRED_Admin' ) || ! current_user_can( 'edit_users' ) ) return;
    
    	// Load myCRED Admin Module
    	$mycred_admin = new myCRED_Admin();
    
    	// Get the user object
    	$user = get_userdata( absint( $lead['created_by'] ) );
    	if ( ! isset( $user->ID ) ) return;
    
    	// If form is submitted, process it now
    	if ( isset( $_POST['myCRED-manual-add-points'] ) )
    		$mycred_admin->adjust_points_manually( $user->ID );
    
    	// Hack for the adjust_users_balance() method
    	if ( ! defined( 'IS_PROFILE_PAGE' ) )
    		define( 'IS_PROFILE_PAGE', true );
    	elseif ( defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE === false )
    		?>
    
    <table class="widefat fixed entry-detail-view" cellspacing="0">
    	<thead>
    		<tr>
    			<th style="background:#ebf2ff;" colspan="2"><h3>Adjust points for entry creator</h3></th>
    		</tr>
    	</thead>
    	<tbody>
    
    	<?php $mycred_admin->adjust_users_balance( $user ); ?>
    
    	</tbody>
    </table>
    <?php
    }

    As a thank you, I’m sending the translation into Brazilian Portuguese of your plugin:

    https://drive.google.com/folderview?id=0B6kRZI7KJFgxTzlFaVkxTWxwazA&usp=sharing

    I will soon translate the addons and also send you.

    Plugin Author myCred

    (@designbymerovingi)

    Hey

    Ok so you will need to remove the row before as well. The row that states:

    elseif ( defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE === false )

    The class method we use here will return a dropdown menu where you select the point type you want to award. We basically use the same feature as myCRED uses when you edit a users profile.

    You can not set this to a particular point type unfortunately. Not if you want to use the adjust_users_balance() method.

    If you must limit this to a particular point type, the easiest way would be to write your own adjustment form modelled of the method and lock it in on a particular point type.

    Thread Starter Mauricio Gofas

    (@mauriciogofas)

    Hey!
    I remove `elseif ( defined( ‘IS_PROFILE_PAGE’ ) && IS_PROFILE_PAGE === false )

    This solves my problem beautifully,

    i will study some more to make this integration a addon for Gravity with options to choose custom text fields when you create a form points… but, it take a bit time 🙂

    Thanks again, Gabriel!

    Plugin Author myCred

    (@designbymerovingi)

    No problem. Im here if you need any further assistance.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Manual balance adjustment in Gravity forms entries’ is closed to new replies.