Created
September 18, 2016 18:33
-
-
Save BHWD/9f4f05559981012f5b9353b472ee09bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'admin_menu', 'dat_add_admin_menu' ); | |
add_action( 'admin_init', 'dat_settings_init' ); | |
function dat_add_admin_menu( ) { | |
add_submenu_page( 'edit.php?post_type=dat_cpt', 'Automatic Divi Testimonials', 'Settings', 'manage_options', 'automatic_divi_testimonials', 'dat_options_page' ); | |
} | |
function dat_settings_init( ) { | |
register_setting( 'pluginPage', 'dat_settings' ); | |
add_settings_section( | |
'dat_pluginPage_section', | |
__( 'Testimonial Email Notification Settings', 'automatic-divi-testimonials' ), | |
'dat_settings_section_callback', | |
'pluginPage' | |
); | |
add_settings_field( | |
'dat_checkbox_field_0', | |
__( 'Disable Email Notifications', 'automatic-divi-testimonials' ), | |
'dat_checkbox_field_0_render', | |
'pluginPage', | |
'dat_pluginPage_section' | |
); | |
add_settings_field( | |
'dat_text_field_1', | |
__( 'Enter Custom Email To Receieve Notifications (defaults to admin email)', 'automatic-divi-testimonials' ), | |
'dat_text_field_1_render', | |
'pluginPage', | |
'dat_pluginPage_section' | |
); | |
} | |
function dat_checkbox_field_0_render( ) { | |
$options = get_option( 'dat_settings' ); | |
$a= $options; | |
if (array_key_exists("dat_checkbox_field_0",$a)) | |
{ | |
echo "Key exists!"; | |
} | |
?> | |
<input type='checkbox' name='dat_settings[dat_checkbox_field_0]' <?php checked( $options['dat_checkbox_field_0'], 1 ); ?> value='1'> | |
<?php | |
} | |
function dat_text_field_1_render( ) { | |
$options = get_option( 'dat_settings' ); | |
?> | |
<input type='email' name='dat_settings[dat_text_field_1]' value='<?php echo $options['dat_text_field_1']; ?>'> | |
<?php | |
} | |
function dat_settings_section_callback( ) { | |
echo __( 'Below you are able to change the default settings for email notifications', 'automatic-divi-testimonials' ); | |
} | |
function dat_options_page( ) { | |
// Get settings options | |
$options = get_option( 'dat_settings' ); | |
// Message Variables | |
$admin_email = get_option( 'admin_email' ); | |
$custom_email = $options['dat_text_field_1']; | |
//echo 'Admin Email: '.$admin_email.'<br>'; | |
//echo 'Custom Email: '.$custom_email.'<br>'; | |
if (!empty($custom_email)) { | |
$sendToEmail = $custom_email; | |
//echo 'IF Statement Custom Email: '.$sendToEmail; | |
} else { | |
$sendToEmail = $admin_email; | |
//echo 'IF Statement Admin Email: '.$sendToEmail; | |
} | |
?> | |
<form action='options.php' method='post'> | |
<h2>Automatic Divi Testimonials</h2> | |
<?php | |
settings_fields( 'pluginPage' ); | |
do_settings_sections( 'pluginPage' ); | |
submit_button(); | |
?> | |
</form> | |
<?php | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment