Example #1
0
 function debugBox($post)
 {
     $actionBox = MAB_ActionBox::get($post->ID);
     if (is_null($actionBox)) {
         $data['meta'] = array();
     } else {
         $data['meta'] = $actionBox->getMeta();
     }
     $filename = 'metaboxes/debug.php';
     echo MAB_Utils::getView($filename, $data);
 }
Example #2
0
function mab_process_wysija_optin_submit($result, $data)
{
    if (!class_exists('WYSIJA_object')) {
        MAB_Ajax::addMessage(__('MailPoet is not set up properly: WYSIJA_object does not exist.', 'mab'));
        return false;
    }
    if (empty($data['email']) || !is_email($data['email'])) {
        MAB_Ajax::addMessage(__('Invalid email address.', 'mab'));
        return false;
    }
    if (empty($data['lists'])) {
        MAB_Ajax::addMessage(__('Email list is not set.', 'mab'));
        return false;
    }
    $list['list_ids'] = explode(',', $data['lists']);
    $user = array();
    $user['email'] = $data['email'];
    if (!empty($data['fname'])) {
        $user['firstname'] = $data['fname'];
    }
    if (!empty($data['lname'])) {
        $user['lastname'] = $data['lname'];
    }
    $subscriber = array('user' => $user, 'user_list' => $list);
    if (!empty($data['mabid'])) {
        $actionBox = MAB_ActionBox::get($data['mabid']);
        if (!$actionBox) {
            MAB_Ajax::addMessage('Action box does not exist.');
            return false;
        }
    }
    $result = WYSIJA::get('user', 'helper')->addSubscriber($subscriber);
    if (false === $result) {
        MAB_Ajax::addMessage(__('Email signup failed.', 'mab'));
        return false;
    }
    $meta = $actionBox->getMeta();
    if (!empty($meta['optin']['wysija']['success-message'])) {
        MAB_Ajax::addMessage(wp_kses_post($meta['optin']['wysija']['success-message']));
    }
    if (!empty($meta['optin']['redirect'])) {
        return array('redirect' => esc_url($meta['optin']['redirect']));
    }
    return true;
}
Example #3
0
 /**
  * Use to dynamically load action boxes via ajax
  * @return array['result'] the action box HTML
  *         array['msgs'] Any messages
  *         array['css'] array of css objects
  *         array['js'] array of js objects
  */
 public function getActionBox()
 {
     $resultArray = array('html' => '', 'error' => false, 'css' => array(), 'js' => array());
     $this->log('AJAX request payload: ' . print_r($_GET, true), 'debug');
     if (empty($_GET['id'])) {
         self::addMessage(__('ID is invalid.', 'mab'));
         $resultArray['error'] = true;
         $resultArray['msgs'] = $this->getMessages();
         self::response($resultArray);
     }
     $result = array();
     $id = $_GET['id'];
     $actionBox = MAB_ActionBox::get($id);
     // action box does not exist
     if (is_null($actionBox)) {
         $resultArray['error'] = true;
         self::addMessage('Action box does not exist with ID ' . $id);
         $resultArray['msgs'] = $this->getMessages();
         self::response($resultArray);
     }
     $html = $actionBox->getActionBox();
     // action box is empty? respond but do not set error
     if (empty($html)) {
         self::response($resultArray);
     }
     $resultArray['html'] = $html;
     /**
      * The following is possible because we are doing ajax.
      * No other script/styles is enqueued
      */
     global $wp_styles, $wp_scripts;
     $actionBox->loadAssets();
     // this will fill $wp_styles and $wp_scripts
     $wp_styles->all_deps($wp_styles->queue);
     $wp_scripts->all_deps($wp_scripts->queue);
     $styles = array();
     $scripts = array();
     $jsToIgnore = array('jquery', 'jquery-migrate', 'jquery-core');
     $cssToIgnore = array();
     $wp_styles->do_concat = true;
     foreach ($wp_styles->to_do as $style) {
         if (in_array($style, $cssToIgnore)) {
             continue;
         }
         $cssObj = $wp_styles->registered[$style];
         $wp_styles->print_html = '';
         $wp_styles->do_item($style);
         $cssObj->html = trim($wp_styles->print_html);
         $styles[] = $cssObj;
     }
     $wp_scripts->do_concat = true;
     foreach ($wp_scripts->to_do as $script) {
         if (in_array($script, $jsToIgnore)) {
             continue;
         }
         $jsObj = $wp_scripts->registered[$script];
         $wp_scripts->print_html = '';
         $wp_scripts->do_item($script);
         $jsObj->html = trim($wp_scripts->print_html);
         $scripts[] = $jsObj;
     }
     $resultArray['css'] = $styles;
     $resultArray['js'] = $scripts;
     self::response($resultArray);
 }