Help with passing variable between functions
-
Hello, I am fairly new to PHP and have been struggling with this for a long time. I would appreciate any help. I am trying to customize a plugin for my needs and pass a variable called $amount between two functions in my functions.php I would contact the owner of the plugin but he is very unresponsive. The problem is the second function isn’t getting the updated $amount that is created due to the if conditions. My understanding is that it is because it is a local variable. What is the best way to pass this variable? See the code below.
function A( $run_this, $mycred, $request ) { if ( $run_this['ref'] == 'publishing_content' ) { // Original amount (I will change this) $amount = $request['amount']; if(isset($_POST['term_id'])) { // If 74 if ($_POST['term_id'] == '74' ){ $amount = -50; } // If 75 elseif ($_POST['term_id'] == '75' ){ $amount = -75; } // Re-add the new value (Amount gets updated. Good) $run_this['amount'] = $amount; } } return $run_this; } function B( $reply, $request, $mycred ) { if ( $reply === false ) return $reply; // I NEED THE NEW AMOUNT HERE. NOT ORIGINAL $amount =; return $reply; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Help with passing variable between functions’ is closed to new replies.