admin_url( 'admin-ajax.php' )) ); } public static function init_widget() { $widget_title = ( isset(self::$configuration['widget_title']) ) ? esc_attr(self::$configuration['widget_title']) : __("Do you need help?", "agency-connect-domain"); wp_add_dashboard_widget( self::wid, //A unique slug/ID $widget_title, //Visible name for the widget array('Agency_Connect','widget') //Callback for the main widget content ); //try to move the widget to the top: self::move_widget_to_the_top(self::wid); //add_filter('admin_bar_menu', array('Agency_Connect','add_help_call_to_menu'), 51); } public static function widget() { if(isset($_POST['agency_connector_message'])) { self::send_helprequest_messsage(); }else { self::echo_helprequest_form('dashboard_widget'); } } public static function register_request_help_menu_option() { $page_title = __('Agency Connect - Get Help'); $menu_title = __('Request Help'); $menu_slug = 'agency-connect'; $function = array('Agency_Connect', 'display_helprequest_page' ); $icon_url = plugins_url('media/agencyconnect-help.png', __FILE__); $position = '2.1'; add_menu_page($page_title, $menu_title, 'manage_options', $menu_slug, $function, $icon_url, $position); //if javascript is activated, the scripts will be loaded and the register_help_request page will be replaced //if you click on the menu option a modal jquery dialog will be opened where the help request can be put add_action('admin_footer', array('Agency_Connect', 'dialogize_helprequest_page')); } public static function display_helprequest_page() { //context variable needed to use different ways for sending the mail (in dashboard and on menu page, normal php, dialog works with js) if(isset($_POST['agency_connector_message'])) { self::send_helprequest_messsage(); }else { self::echo_helprequest_form('menupage'); } } public static function dialogize_helprequest_page() { //context variable needed to use different ways for sending the mail (in dashboard and on menu page, normal php, dialog works with js) $context = 'dialog'; //add the hidden div to the page. dialog.js uses this div to make a dialog out of it //dialog.js is enqueud on every site in register_scripts function echo '
'; /*TODO: find a way nicer way to do this. when the content of the dialog changes (showing error/success messages) and you reopen the dialog, the dialog has to get the original form again, so it doesn't still show the error message from last time. so it gets the old data from this div and copies it back to the dialog div just created */ echo ''; //needs to be done so that I can access the image from javascript. I can't read out the right url in js. #echo ''; } public static function move_widget_to_the_top($widgetID) { // 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 dashboard widget from the end of the array $widget_backup = array( $widgetID => $normal_dashboard[$widgetID] ); unset( $normal_dashboard[$widgetID] ); // Merge the two arrays together so our widget is at the beginning $sorted_dashboard = array_merge( $widget_backup, $normal_dashboard ); // Save the sorted array back into the original metaboxes $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; } public static function link_to_settings_section() { return ''; } public static function send_helprequest_messsage() { if(empty($_POST['agency_connector_message']) || is_string($_POST['agency_connector_message'])) { $message = !empty($_POST['agency_connector_message']) ? sanitize_text_field($_POST['agency_connector_message']) : __("The customer didn't enter any message"); $email_to = sanitize_email(self::$configuration['email']); if (wp_mail($email_to, __("Agency Connect: A Client Needs Help", "agency-connect-domain"),$message.' From: '.site_url())) { echo ''; printf(__('Your help request has been send.', "agency-connect-domain"), $email_to); echo '
'; } else { echo '';
echo "sending to ".$email_to." the message is: ".$message." and it failed
";
printf(__('An error occured while sending the help request. Please contact your agency directly at %s', 'agency-connect-domain'), $email_to);
echo '
'.__('The message you entered is not valid.').'
'; } //needed, because elseways the ajax-request returns the message with a '0' at the end. some studip wp problem if I understood right if (defined('DOING_AJAX') && DOING_AJAX) die(); } public static function echo_helprequest_form($context) { //context is 'dashboard_widget', 'menupage' or 'dialog' depending on for what the form is rendered switch ($context) { case "dashboard_widget": $helptext = ( isset(self::$configuration['widget_helptext']) ) ? esc_attr(self::$configuration['widget_helptext']) : 'not configured'; break; default: $helptext = ( isset( self::$configuration['helprequest_helptext'])) ? esc_attr(self::$configuration['helprequest_helptext']) : 'not configured'; } //this is the form which is used by the dashboard widget and the dialog (or the mainmenu-page if js is disabled) //if a helptext is set, the form will be rendered if($helptext !== 'not configured'): ?>Powered by jan.do
here', 'agency-connect-domain' ), self::link_to_settings_section()); ?>