prefix . 'callback'; $sql = "CREATE TABLE $table_name ( id int(11) NOT NULL AUTO_INCREMENT, date datetime NOT NULL DEFAULT '0000-00-00 00:00:00', name varchar(255) DEFAULT NULL, content longtext NOT NULL, UNIQUE KEY id (id) );"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); } register_activation_hook( __FILE__, 'samlab_callback_activate' ); register_uninstall_hook( __FILE__, 'samlab_callback_drop_tables'); function samlab_callback_drop_tables() { //drop a custom db table global $wpdb; $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'callback' ); delete_option('callback-settings'); } // Include the dependencies needed to instantiate the plugin. foreach ( glob( plugin_dir_path( __FILE__ ) . 'admin/*.php' ) as $file ) { load_plugin_textdomain( 'callback-settings', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); include_once $file; } add_action( 'plugins_loaded', 'samlab_сallback_settings' ); //для админки ajax для фронта ajax add_action( 'wp_ajax_getformsamlab', 'samlab_сallback_getform' ); add_action( 'wp_ajax_nopriv_getformsamlab', 'samlab_сallback_getform' ); //для админки ajax для фронта ajax add_action( 'wp_ajax_nopriv_sampostmessage', 'samlab_сallback_postmessage' ); add_action( 'wp_ajax_sampostmessage', 'samlab_сallback_postmessage' ); function samlab_сallback_add_script() { $option = get_option( 'callback-settings' ); ?> init(); add_action( 'admin_init', 'samlab_сallback_settings_init' ); //ajax запрос для удаления вешаем на хукsamlab_сallback_dellrecord add_action('wp_ajax_samlabdellrecord', 'samlab_сallback_dellrecord'); add_action('wp_ajax_samlabgettable', 'samlab_сallback_gettable'); add_action('admin_print_footer_scripts', 'samlab_сallback_addjavascript', 99); //add widget to admin $option = get_option( 'callback-settings' ); if($option['adminwidget'] == '1'){ add_action( 'wp_dashboard_setup', 'samlab_сallback_adddashboardwidgets' ); } add_action( 'admin_print_footer_scripts', 'samlab_сallback_addquicktags' ); } ////// ## Произвольный виджет в консоли в админ-панели function samlab_сallback_dashhelp() { global $wpdb; $table_name = $wpdb->prefix . 'callback'; $posts = $wpdb->get_results("SELECT * FROM ".$table_name." ORDER BY id DESC LIMIT 0,20"); echo '
'; echo ''; foreach($posts as $res){ echo ''; } echo '
'. __("Date", "callback-settings") .''. __("Name\Email", "callback-settings") .''. __("Message", "callback-settings") .'
'. $res->date . ' ' . $res->name . ' ' . $res->content . '
'; echo '
'; } function samlab_сallback_adddashboardwidgets() { wp_add_dashboard_widget( 'custom_help_widget', __("Сallback", "callback-settings"), 'samlab_сallback_dashhelp' ); // Globalize the metaboxes array, this holds all the widgets for wp-admin global $wp_meta_boxes; // Get the regular dashboard widgets array // (which has our new widget already but at the end) $normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core']; // Backup and delete our new dashbaord widget from the end of the array $example_widget_backup = array( 'example_dashboard_widget' => $normal_dashboard['example_dashboard_widget'] ); unset( $normal_dashboard['example_dashboard_widget'] ); // Merge the two arrays together so our widget is at the beginning $sorted_dashboard = array_merge( $example_widget_backup, $normal_dashboard ); // Save the sorted array back into the original metaboxes $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; } ////////////// function samlab_сallback_getform(){ global $wpdb; $option = get_option( 'callback-settings' ); $tempform .= '
'; $tempform .= '
'; $tempform .= ' '; $tempform .= ' '; if($option['emailcheck'] == "1"){ $tempform .= ' '; $tempform .= ' '; } if($option['messagecheck'] == "1"){ $tempform .= ' '; $tempform .= ' '; } $tempform .= '
'; if(isset($option['agreementstext'])){ $tempform .= '

'; $tempform .= $option['agreementstext']; $tempform .= '

'; } $tempform .= '
'; echo $tempform; wp_die(); } function samlab_сallback_dellrecord() { global $wpdb; $table_name = $wpdb->prefix . 'callback'; $delrecord = sanitize_text_field( $_POST['id'] ); $id = esc_attr($delrecord); $wpdb->delete( $table_name, array( 'id' => $id ) ); echo __("Record delited","callback-settings"); wp_die(); } function samlab_сallback_gettable(){ header("Content-Type: application/json"); //@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); global $wpdb; $table_name = $wpdb->prefix . 'callback'; $posts = $wpdb->get_results("SELECT * FROM " . $table_name . " ORDER BY id DESC"); if($posts){ foreach($posts as $res){ $nestedData = array(); $nestedData[] = $res->date; $nestedData[] = $res->name; $nestedData[] = $res->content; $nestedData[] = ''; $data[] = $nestedData; } $json_data = array( "data" => $data ); echo(json_encode($json_data)); }else{ $nestedData = array(); $nestedData[] = ''; $nestedData[] = ''; $nestedData[] = __( 'No records yet', 'callback-settings' ); $nestedData[] = ''; $data_false[] = $nestedData; $json_data_false = array( "data" => $data_false ); echo(json_encode($json_data_false)); } wp_die(); } function samlab_сallback_postmessage(){ global $wpdb; $option = get_option( 'callback-settings' ); $post_name = sanitize_text_field( $_POST['name'] ); $post_email = sanitize_text_field( $_POST['email'] ); $post_message = sanitize_text_field( $_POST['message'] ); if( $post_name){ $name = $post_name; }else{$name = '';} if( $post_email){ $email = $post_email; }else{$email = '';} if( $post_message){ $message = $post_message; }else{$message = '';} //записываем в базу $date = date('Y-m-d H:i:s'); $table_name = $wpdb->prefix . 'callback'; $data_wp = array( 'date' => $date, 'name' => $name.'
'.$email, 'content' => $message ); $wpdb->insert($table_name, $data_wp); if($option['sendemails'] == "1" ) { $to = $option['emailtosend']; $subject = __( 'Callback from the site', 'callback-settings' ); $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=utf-8\r\n"; $template = '

'.$subject.' - '. $name .' '.$email.'

'.$message.'

'; //$message .= $name; //$message .= $email; $messages .= $template; $done = mail ($to, $subject, $messages, $headers); } //$poempmess .= 'Получили имя:'.$name.' email:'.$email.' сообщение: '.$message; //echo $poempmess; wp_die(); } function samlab_сallback_addjavascript() { if(get_user_locale() == 'ru_RU'){ $translate = plugins_url(dirname( plugin_basename( __FILE__ ) ) .'/admin/assets/js/Russian.json'); }else{ $translate = plugins_url(dirname( plugin_basename( __FILE__ ) ) .'/admin/assets/js/English.json'); } ?> '. __( 'Call me back', 'callback-settings' ) .''; return $temp_scw ; } //FINISH samlab_callback //START samlab_callback button add_shortcode( 'samlab_callback_button', 'samlab_callback_widget_button' ); function samlab_callback_widget_button( $atts ) { if($option['usebootstrap'] == "1" ) { //if use bootstrap wp_register_style('bootstrap_style', plugin_dir_url(__FILE__) . '/public/bootstrap.min.css'); wp_enqueue_style('bootstrap_style'); //if not use bootstrap }elseif($option['usebootstrap'] == "0" ){ wp_register_style('samlab_callback_style', plugin_dir_url(__FILE__) . '/public/samlab_style.css'); wp_enqueue_style('samlab_callback_style'); // } wp_register_script('jquery_popup', plugin_dir_url(__FILE__) . '/public/jquery-confirm.min.js', array('jquery'), true); wp_enqueue_script('jquery_popup'); wp_register_style('jquery_popup_style', plugin_dir_url(__FILE__) . '/public/jquery-confirm.min.css'); wp_enqueue_style('jquery_popup_style'); $temp_scwbutton .= ''; return $temp_scwbutton ; } //FINISH samlab_callback function samlab_callback_scripts() { wp_register_script('samlab_callback_script', dirname( plugin_basename( __FILE__ ) ) . '/public/samlab_callback.js', array('jquery'),'1.1', true); wp_enqueue_script('samlab_callback_script'); } //add_action( 'the_content', 'samlab_callback_scripts', 999 );