do function when checkbox is checked on plugin settings page









up vote
0
down vote

favorite












i created a small plugin for internal usage, with a settings page.
as follows:



<div class="wrap">

<h1><?php echo esc_html(get_admin_page_title()); ?></h1>

<form method="post" name="desite_options" action="options.php">
<?php
//Grab all options
$options = get_option($this->plugin_name);

// Desite
$credit = $options['credit'];
$logo_link = $options['logo_link'];
$logo_alt = $options['logo_alt'];
$dashboard_welcome = $options['dashboard_welcome'];
$acf_settings = $options['acf_settings'];
$acf_map = $options['acf_map'];
$acf_map_key = $options['acf_map_key'];
$ocean_rtl = $options['ocean_rtl'];

?>

<?php
settings_fields($this->plugin_name);
do_settings_sections($this->plugin_name);
?>
<h3>Admin Customization</h3>

<fieldset>
<legend class="screen-reader-text">
<span>Add desite's credit</span>
</legend>
<label for="<?php echo $this->plugin_name; ?>-credit">
<input type="checkbox" id="<?php echo $this->plugin_name; ?>-credit" name="<?php echo $this->plugin_name; ?>[credit]" value="1" <?php checked($credit, 1); ?> />
<span><?php esc_attr_e('Add desite credit', $this->plugin_name); ?></span>
</label>
</fieldset>

<?php submit_button('Save all changes', 'primary','submit', TRUE); ?>

</form>




i have managed to save the selections and sanitize the fields.
i'm having difficulties to run a function when a checkbox is checked.
for example:
i have the following function:



 function remove_footer_admin() 
echo 'Site built for Bhuka Tours by <a href="https://desite.co.il/">DEsite</a>';
add_filter('admin_footer_text', 'remove_footer_admin');


what do i need to do in order to execute this function when $credit is checked, and in which file its best?
thanks.










share|improve this question





















  • In your plugin code, you need to make the value of your checkbox conditional. Currently you have hardcoded it to '1'. Regarding your function, you need to do following. In your functions.php file, check if the plugin is active. If it is active retrieve the value of checkbox. If the value is 1, then use the add_filter line. Something like, if( $checkbox == '1' ) add_filter('admin_footer_text', 'remove_footer_admin');
    – zipkundan
    Nov 11 at 20:33














up vote
0
down vote

favorite












i created a small plugin for internal usage, with a settings page.
as follows:



<div class="wrap">

<h1><?php echo esc_html(get_admin_page_title()); ?></h1>

<form method="post" name="desite_options" action="options.php">
<?php
//Grab all options
$options = get_option($this->plugin_name);

// Desite
$credit = $options['credit'];
$logo_link = $options['logo_link'];
$logo_alt = $options['logo_alt'];
$dashboard_welcome = $options['dashboard_welcome'];
$acf_settings = $options['acf_settings'];
$acf_map = $options['acf_map'];
$acf_map_key = $options['acf_map_key'];
$ocean_rtl = $options['ocean_rtl'];

?>

<?php
settings_fields($this->plugin_name);
do_settings_sections($this->plugin_name);
?>
<h3>Admin Customization</h3>

<fieldset>
<legend class="screen-reader-text">
<span>Add desite's credit</span>
</legend>
<label for="<?php echo $this->plugin_name; ?>-credit">
<input type="checkbox" id="<?php echo $this->plugin_name; ?>-credit" name="<?php echo $this->plugin_name; ?>[credit]" value="1" <?php checked($credit, 1); ?> />
<span><?php esc_attr_e('Add desite credit', $this->plugin_name); ?></span>
</label>
</fieldset>

<?php submit_button('Save all changes', 'primary','submit', TRUE); ?>

</form>




i have managed to save the selections and sanitize the fields.
i'm having difficulties to run a function when a checkbox is checked.
for example:
i have the following function:



 function remove_footer_admin() 
echo 'Site built for Bhuka Tours by <a href="https://desite.co.il/">DEsite</a>';
add_filter('admin_footer_text', 'remove_footer_admin');


what do i need to do in order to execute this function when $credit is checked, and in which file its best?
thanks.










share|improve this question





















  • In your plugin code, you need to make the value of your checkbox conditional. Currently you have hardcoded it to '1'. Regarding your function, you need to do following. In your functions.php file, check if the plugin is active. If it is active retrieve the value of checkbox. If the value is 1, then use the add_filter line. Something like, if( $checkbox == '1' ) add_filter('admin_footer_text', 'remove_footer_admin');
    – zipkundan
    Nov 11 at 20:33












up vote
0
down vote

favorite









up vote
0
down vote

favorite











i created a small plugin for internal usage, with a settings page.
as follows:



<div class="wrap">

<h1><?php echo esc_html(get_admin_page_title()); ?></h1>

<form method="post" name="desite_options" action="options.php">
<?php
//Grab all options
$options = get_option($this->plugin_name);

// Desite
$credit = $options['credit'];
$logo_link = $options['logo_link'];
$logo_alt = $options['logo_alt'];
$dashboard_welcome = $options['dashboard_welcome'];
$acf_settings = $options['acf_settings'];
$acf_map = $options['acf_map'];
$acf_map_key = $options['acf_map_key'];
$ocean_rtl = $options['ocean_rtl'];

?>

<?php
settings_fields($this->plugin_name);
do_settings_sections($this->plugin_name);
?>
<h3>Admin Customization</h3>

<fieldset>
<legend class="screen-reader-text">
<span>Add desite's credit</span>
</legend>
<label for="<?php echo $this->plugin_name; ?>-credit">
<input type="checkbox" id="<?php echo $this->plugin_name; ?>-credit" name="<?php echo $this->plugin_name; ?>[credit]" value="1" <?php checked($credit, 1); ?> />
<span><?php esc_attr_e('Add desite credit', $this->plugin_name); ?></span>
</label>
</fieldset>

<?php submit_button('Save all changes', 'primary','submit', TRUE); ?>

</form>




i have managed to save the selections and sanitize the fields.
i'm having difficulties to run a function when a checkbox is checked.
for example:
i have the following function:



 function remove_footer_admin() 
echo 'Site built for Bhuka Tours by <a href="https://desite.co.il/">DEsite</a>';
add_filter('admin_footer_text', 'remove_footer_admin');


what do i need to do in order to execute this function when $credit is checked, and in which file its best?
thanks.










share|improve this question













i created a small plugin for internal usage, with a settings page.
as follows:



<div class="wrap">

<h1><?php echo esc_html(get_admin_page_title()); ?></h1>

<form method="post" name="desite_options" action="options.php">
<?php
//Grab all options
$options = get_option($this->plugin_name);

// Desite
$credit = $options['credit'];
$logo_link = $options['logo_link'];
$logo_alt = $options['logo_alt'];
$dashboard_welcome = $options['dashboard_welcome'];
$acf_settings = $options['acf_settings'];
$acf_map = $options['acf_map'];
$acf_map_key = $options['acf_map_key'];
$ocean_rtl = $options['ocean_rtl'];

?>

<?php
settings_fields($this->plugin_name);
do_settings_sections($this->plugin_name);
?>
<h3>Admin Customization</h3>

<fieldset>
<legend class="screen-reader-text">
<span>Add desite's credit</span>
</legend>
<label for="<?php echo $this->plugin_name; ?>-credit">
<input type="checkbox" id="<?php echo $this->plugin_name; ?>-credit" name="<?php echo $this->plugin_name; ?>[credit]" value="1" <?php checked($credit, 1); ?> />
<span><?php esc_attr_e('Add desite credit', $this->plugin_name); ?></span>
</label>
</fieldset>

<?php submit_button('Save all changes', 'primary','submit', TRUE); ?>

</form>




i have managed to save the selections and sanitize the fields.
i'm having difficulties to run a function when a checkbox is checked.
for example:
i have the following function:



 function remove_footer_admin() 
echo 'Site built for Bhuka Tours by <a href="https://desite.co.il/">DEsite</a>';
add_filter('admin_footer_text', 'remove_footer_admin');


what do i need to do in order to execute this function when $credit is checked, and in which file its best?
thanks.







php wordpress wordpress-plugin-creation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 12:36









dor meljon

235




235











  • In your plugin code, you need to make the value of your checkbox conditional. Currently you have hardcoded it to '1'. Regarding your function, you need to do following. In your functions.php file, check if the plugin is active. If it is active retrieve the value of checkbox. If the value is 1, then use the add_filter line. Something like, if( $checkbox == '1' ) add_filter('admin_footer_text', 'remove_footer_admin');
    – zipkundan
    Nov 11 at 20:33
















  • In your plugin code, you need to make the value of your checkbox conditional. Currently you have hardcoded it to '1'. Regarding your function, you need to do following. In your functions.php file, check if the plugin is active. If it is active retrieve the value of checkbox. If the value is 1, then use the add_filter line. Something like, if( $checkbox == '1' ) add_filter('admin_footer_text', 'remove_footer_admin');
    – zipkundan
    Nov 11 at 20:33















In your plugin code, you need to make the value of your checkbox conditional. Currently you have hardcoded it to '1'. Regarding your function, you need to do following. In your functions.php file, check if the plugin is active. If it is active retrieve the value of checkbox. If the value is 1, then use the add_filter line. Something like, if( $checkbox == '1' ) add_filter('admin_footer_text', 'remove_footer_admin');
– zipkundan
Nov 11 at 20:33




In your plugin code, you need to make the value of your checkbox conditional. Currently you have hardcoded it to '1'. Regarding your function, you need to do following. In your functions.php file, check if the plugin is active. If it is active retrieve the value of checkbox. If the value is 1, then use the add_filter line. Something like, if( $checkbox == '1' ) add_filter('admin_footer_text', 'remove_footer_admin');
– zipkundan
Nov 11 at 20:33

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239021%2fdo-function-when-checkbox-is-checked-on-plugin-settings-page%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239021%2fdo-function-when-checkbox-is-checked-on-plugin-settings-page%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線