get_option( 'admin_email' ),
'name' => 'Name:',
'message' => 'Message:',
'submit' => 'Send message',
'width' => '100%',
'btn_color' => '#000',
'btn_text_color' => '#fff',
'from' => get_option( 'blogname' ),
'subject' => 'Ajax Message',
'success' => 'Thank you, message sent',
'error' => 'Error: Message not sent',
'textarea' => '',
'captcha_on' => '1',
'captcha_value' => '333'
);
update_option( $option_name, $data );
$notices = get_option( 'keksus_ae_plugin_admin_notices', array() );
$notices = array(
'content' => __( 'Thank you for installing this plugin! Plugin settings are available on the page', 'ae' ) .
' Settings - Ajax Message'
);
update_option( 'keksus_ae_plugin_admin_notices', $notices );
}
function keksus_ae_deactivate() {
global $option_name;
delete_option( $option_name );
delete_option( 'keksus_ae_plugin_admin_notices' );
}
function keksus_ae_plugin_admin_notices() {
if ( $notices = get_option( 'keksus_ae_plugin_admin_notices' ) ) {
foreach ( $notices as $notice) {
echo "
";
}
delete_option( 'keksus_ae_plugin_admin_notices' );
}
}
add_action( 'admin_notices', 'keksus_ae_plugin_admin_notices' );
function keksus_ae_scripts_frontend() {
wp_enqueue_style( 'frontend-css', plugins_url( 'css/frontend.css',__FILE__ ) );
wp_enqueue_style( 'admin-icons', plugins_url( 'css/ionicons.min.css',__FILE__ ) );
wp_enqueue_script( 'frontend-ajax', plugins_url( 'js/frontend.js',__FILE__ ), array(jquery) );
wp_localize_script( 'frontend-ajax', 'ajax',
array(
'url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'helloworld' )
)
);
}
add_action( 'wp_enqueue_scripts', 'keksus_ae_scripts_frontend' );
function keksus_ae_scripts_admin() {
$current_screen = get_current_screen();
if ( $current_screen->id === "settings_page_ae_options_group" ) {
wp_enqueue_style( 'admin-css', plugins_url( 'css/admin.css',__FILE__ ) );
wp_enqueue_style( 'admin-icons', plugins_url( 'css/ionicons.min.css',__FILE__ ) );
wp_enqueue_script( 'admin-js', plugins_url( 'js/admin.js',__FILE__ ), array(jquery) );
wp_localize_script( 'admin-js', 'ajax',
array(
'url' => admin_url( 'admin-ajax.php' )
//'nonce' => wp_create_nonce( 'helloadmin' )
)
);
}
}
add_action( 'admin_enqueue_scripts', 'keksus_ae_scripts_admin' );
// show plugin footer text
function keksus_ae_this_screen() {
$current_screen = get_current_screen();
if ( $current_screen->id === "settings_page_ae_options_group" ) {
add_filter( 'update_footer', 'right_admin_footer_text_output', 11);
function right_admin_footer_text_output( $text ) {
$text = current_time( 'Y-m-d' );
return $text;
}
add_filter( 'admin_footer_text', 'left_admin_footer_text_output' );
function left_admin_footer_text_output( $text ) {
$text = __( 'Thank you for installing this plugin! Created by', 'ae' ).' Keksus';
return $text;
}
}
}
add_action( 'current_screen', 'keksus_ae_this_screen' );
// add custom styles to header
function keksus_ae_style_to_header() {
global $option_name,$options;
?>
'. __( 'Name required', 'ae' ) . '';
echo '
';
}
elseif ( '' == $message ) {
echo ''. __( 'Message required', 'ae' ) . '';
echo '
';
}
elseif ( isset( $captcha_value ) ) {
if ( $captcha == $captcha_value ) {
keksus_ae_mail( $from,$subject,$name,$message );
}
else {
echo '
'. __( 'Wrong captcha code', 'ae' ) . '';
echo '
';
}
}
else {
keksus_ae_mail( $from,$subject,$name,$message );
}
//echo wp_json_encode( $_POST);
wp_die();
}
}
add_action( 'wp_ajax_ae_action', 'keksus_ae_action_callback' );
add_action( 'wp_ajax_nopriv_ae_action', 'keksus_ae_action_callback' );
// function used in callback
function keksus_ae_mail( $from,$subject,$name,$message ) {
global $option_name,$options;
$to_email = $options['email'];
$body = "
From: $from
";
$body .= "
Subject: $subject
";
$body .= '===============================';
$body .= "
Name: $name
";
//$body .= "
Email: $from_email
";
$body .= "
Message:
$message
";
$headers = 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: $name
" . "\r\n";
if ( wp_mail( $to_email, $subject, $body, $headers ) ) {
echo ''. __( $options['success'], 'ae' ) .'';
echo '
';
wp_die();
}
else {
echo '
'. __( $options['error'], 'ae' ) .'';
echo '
';
wp_die();
}
}
// captcha value
function keksus_ae_captcha() {
global $option_name,$options;
if ( $options['captcha_on'] == '1' ) {
return $options['captcha_value'];
}
}
add_action( 'captcha', 'keksus_ae_captcha' );
// register plugin settings
function keksus_ae_plugin_settings() {
global $option_name,$options;
register_setting( 'ae_options_group', $option_name, 'keksus_ae_sanitize_callback' );
}
add_action( 'admin_init', 'keksus_ae_plugin_settings' );
// settings page for admin dashboard
function keksus_ae_admin_page_settings() {
add_options_page( 'Ajax Message settings', 'Ajax Message', 'manage_options', 'ae_options_group', 'keksus_ae_options_output' );
}
add_action( 'admin_menu', 'keksus_ae_admin_page_settings' );
function keksus_ae_options_output() {
global $option_name,$options;
$checked = ( is_array( $options ) && $options['captcha_on'] == '1' ) ? 'checked="checked"' : '';
?>