Support » Fixing WordPress » add_action never called

  • I have registration form that sends the user details to my mail and it works fine.
    My problem started when i tried using mailchimp api.

    Here’s the form validation code from functions.php

    function ajax_action_stuff() {
      $data     = $_POST['data'];
      $userinfo    = $data['userinfo'];
      $orderid = $data['orderid'];
    
      global $wpdb;
      global $theme_option;
      if($theme_option['paypal_active'] == 1){
        $status = 'progressing';
      }else if($theme_option['paypal_active'] == 0){
        $status = 'free';
      }
    
      $wpdb->query('CREATE TABLE IF NOT EXISTS <code>imevent_payments</code> (
                <code>id</code> BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
                <code>buyer_email</code> TEXT NOT NULL,
                <code>price</code> TEXT NOT NULL,
                <code>currency</code> TEXT NOT NULL,
                <code>status</code> TEXT NOT NULL,
                <code>payment_type</code> TEXT NOT NULL,
                <code>order_id</code> TEXT NOT NULL,
                <code>transaction_id</code> TEXT NOT NULL,
                <code>sumary</code> TEXT NOT NULL,
                <code>buyer_info</code> TEXT NOT NULL,
                <code>created</code> INT( 4 ) UNSIGNED NOT NULL
        ) ENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;');
    
      if(trim($userinfo) == ''){
        echo 'false';
        return false;
      }
      $price_plan_information = array(
        'buyer_email' => '',
        'price'       =>'',
        'currency'    => '',
        'status'      => esc_attr($status),
        'payment_type' => '',
        'order_id'    => esc_attr($orderid),
        'transaction_id'  => '',
        'sumary'      => '',
        'buyer_info'  => esc_attr($userinfo),
        'created'     => time()
        );
    
      $insert_format = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');
      $wpdb->insert('imevent_payments', $price_plan_information, $insert_format);
    
      if($status == 'free' && trim($theme_option['register_email_free']) != '') {
    
          $body_email = "<html><body><h2>" . __('הרשמה חדשה:', TEXT_DOMAIN) . "</h2>";
          $body_email .= "<strong>מזהה</strong>: " . $orderid . "<br/>" .
              "<strong>פרטים</strong>: <br/>" . $userinfo . "</html></body>";
    
          $multiple_to_recipients = array($theme_option['register_email_free']);
          $subject = __('New Register', TEXT_DOMAIN);
          $body = $body_email;
          $headers = __('From website', TEXT_DOMAIN) . "\r\n";
          $headers = "MIME-Version: 1.0\r\n";
          $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    
          wp_mail($multiple_to_recipients, $subject, $body, $headers);
    
      }
    
      echo 'true';
    
      die(); // stop executing script
    
    }
    
    add_action( 'wp_ajax_ajax_action', 'ajax_action_stuff' ); // ajax for logged in users
    add_action( 'wp_ajax_nopriv_ajax_action', 'ajax_action_stuff' );

    Now I have another function

    function syncMailchimp()
    {
        require_once 'MCAPI.class.php';
        $data = $_POST['data'];
        $userinfo = $data['userinfo'];
        $array = array();
        $lines = explode("\n", $userinfo);
    
        foreach ($lines as $line) {
            list($key, $value) = explode(": ", $line);
            $array[$key] = $value;
        }
        var_dump($array);
        $nameKey = "שם ושם משפחה";
        $emaiKey = "כתובת דואר אלקטרוני״";
        $phoneKey = "טלפון";
        $email = $array[$emaiKey];
        $name = '$array[$nameKey]';
        $number = '$array[$nameKey]';
    
        $apiKey = '75c3e307567205bbe8286ea94ba64efc-us12';
        $listId = '445ed1f025';
        $api = new MCAPI($apiKey);
        $retval = $api->lists();
    
    // By default this sends a confirmation email - you will not see new members
    // until the link contained in it is clicked!
    
        $merge_vars = array('FNAME' => $name, 'NUMBER' => $number);
        if ($api->listSubscribe($listId, $email, $merge_vars) === true) {
            echo 'success';
        }
    
    }
    add_action( 'wp_ajax_nopriv_ajax_action', 'syncMailchimp' );

    My problem is that the syncmailchimp function is never called.
    any ideas why? I need to get the POST data from the from in order to send it to mailchimp.
    Thanks in advance.

  • The topic ‘add_action never called’ is closed to new replies.