0

I have a file containing all the constants used in the plugin. For example, I have a variable in one of my file define('APPOINTMENTS_DEFAULT_ENABLE_PAYPAL', 1);

I have a checkbox in admin area where user can enable or disable the paypal feature. This is the checkbox code: <input type="checkbox" name="enable_paypal" size="40" value=""/>

Issue: Can anybody please tell me how can I write code to modify the define() so that when checkbox is clicked then make the value to 1 and otherwise value should be 0?

  • 4
    a constant is… constant. you can't modify it once it's been defined. – Milo Dec 6 '13 at 4:23
  • sir when user changes there options i need to update that in my code. and by the name "constant" i mean after user changes the option then until he changes it again the value should remain same. – Zammuuz Dec 6 '13 at 4:40
  • 1
    this question is not related to wordpress and yes, a constant by definition can not be changed, that is why it is a constant – Mark Kaplun Dec 6 '13 at 5:36
  • @nikki : constant is a particular type of data in PHP. You should not use the word "constant" to refer to anything but that particular type of data. It will cause confusion. – s_ha_dum Dec 7 '13 at 15:16
3

You can't alter a constant once it is defined. That is how PHP works. Don't fight it.

The good news is that you should not be using a constant at all. Use options.

// get your value
// the second parameter is the default
$enable_paypal = get_option('enable_paypal',true);

// set your value based on, I assume, a form of some kind
update_option('enable_paypal',false);

Reference

http://codex.wordpress.org/Function_Reference/get_option
http://codex.wordpress.org/Function_Reference/update_option

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.