public function export_to_db($string, $translation = '')
 {
     $encrypted_string = md5($string);
     $query = hocwp_get_post_by_meta('encrypted_string', $encrypted_string);
     $post_id = $this->post_id;
     $post_title = $this->build_post_title($string);
     $postarr = array('post_content' => $translation, 'post_type' => 'hocwp_mo', 'post_title' => $post_title, 'post_status' => 'private', 'post_excerpt' => $string);
     if (!$query->have_posts()) {
         if (hocwp_id_number_valid($post_id)) {
             $postarr['ID'] = $post_id;
         } else {
             $mo = $this->get_object($string);
             if (is_a($mo, 'WP_Post')) {
                 $postarr['ID'] = $mo->ID;
             }
         }
     } else {
         if (hocwp_id_number_valid($this->post_id)) {
             $postarr['ID'] = $this->post_id;
         } else {
             $object = array_shift($query->posts);
             $postarr['ID'] = $object->ID;
         }
     }
     $post_id = hocwp_insert_post($postarr);
     if (hocwp_id_number_valid($post_id)) {
         update_post_meta($post_id, 'encrypted_string', $encrypted_string);
         update_post_meta($post_id, 'string', $string);
     }
     return $post_id;
 }
 function hocwp_widget_subscribe_ajax_callback()
 {
     $use_captcha = (bool) hocwp_get_method_value('use_captcha');
     $captcha_code = hocwp_get_method_value('captcha');
     $email = hocwp_get_method_value('email');
     $name = hocwp_get_method_value('name');
     $phone = hocwp_get_method_value('phone');
     $register = (bool) hocwp_get_method_value('register');
     $result = array('success' => false, 'message' => hocwp_build_message(hocwp_text_error_default(), 'danger'));
     $captcha_valid = true;
     if ($use_captcha) {
         $captcha = new HOCWP_Captcha();
         $captcha_valid = $captcha->check($captcha_code);
     }
     $re_verify = false;
     $query = hocwp_get_post_by_meta('subscriber_email', $email, array('post_type' => 'hocwp_subscriber'));
     if ($query->have_posts()) {
         $subscriber = array_shift($query->posts);
         $verified = hocwp_get_post_meta('subscriber_verified', $subscriber->ID);
         if (1 != $verified) {
             $re_verify = true;
         }
     }
     if ($captcha_valid) {
         if (is_email($email)) {
             $active_key = hocwp_generate_reset_key();
             $verify_link = hocwp_generate_verify_link($active_key);
             if ($re_verify) {
                 hocwp_send_mail_verify_email_subscription(hocwp_text_email_subject_verify_subscription(), $email, $verify_link);
                 $result['success'] = true;
                 $result['message'] = hocwp_build_message(hocwp_text_success_register_and_verify_email(), 'success');
             } else {
                 if ($query->have_posts() || $register && email_exists($email)) {
                     $result['message'] = hocwp_build_message(hocwp_text_error_email_exists(), 'danger');
                 } else {
                     $post_title = '';
                     if (!empty($name)) {
                         $post_title .= $name;
                     }
                     if (empty($post_title)) {
                         $post_title = $email;
                     } else {
                         $post_title .= ' - ' . $email;
                     }
                     $post_data = array('post_type' => 'hocwp_subscriber', 'post_title' => $post_title, 'post_status' => 'publish');
                     $post_id = hocwp_insert_post($post_data);
                     if (hocwp_id_number_valid($post_id)) {
                         update_post_meta($post_id, 'subscriber_name', $name);
                         update_post_meta($post_id, 'subscriber_email', $email);
                         update_post_meta($post_id, 'subscriber_phone', $phone);
                         update_post_meta($post_id, 'subscriber_verified', 0);
                         update_post_meta($post_id, 'subscriber_active_key', $active_key);
                         if ($register) {
                             $password = wp_generate_password();
                             $user_data = array('username' => $email, 'email' => $email, 'password' => $password);
                             $user_id = hocwp_add_user($user_data);
                             if (hocwp_id_number_valid($user_id)) {
                                 wp_send_new_user_notifications($user_id);
                                 update_post_meta($post_id, 'subscriber_user', $user_id);
                                 update_user_meta($user_id, 'subscriber_id', $post_id);
                             }
                         }
                         hocwp_send_mail_verify_email_subscription(hocwp_text_email_subject_verify_subscription(), $email, $verify_link);
                         $result['success'] = true;
                         $result['message'] = hocwp_build_message(hocwp_text_success_register_and_verify_email(), 'success');
                     }
                 }
             }
         } else {
             $result['message'] = hocwp_build_message(hocwp_text_error_email_not_valid(), 'danger');
         }
     } else {
         $result['message'] = hocwp_build_message(hocwp_text_error_captcha_not_valid(), 'danger');
     }
     wp_send_json($result);
 }
function hocwp_setup_theme_add_default_sidebars()
{
    $added = (bool) get_option('hocwp_default_sidebars_added');
    if ($added) {
        $query = hocwp_query(array('post_type' => 'hocwp_sidebar', 'posts_per_page' => -1));
        if (!$query->have_posts()) {
            $added = false;
        }
    }
    if (!$added) {
        $sidebars = hocwp_theme_get_default_sidebars();
        foreach ($sidebars as $name => $data) {
            $sidebar = hocwp_get_post_by_meta('sidebar_id', $name);
            if (!$sidebar->have_posts()) {
                $post_data = array('post_title' => $data['name'], 'post_type' => 'hocwp_sidebar', 'post_status' => 'publish');
                $post_id = hocwp_insert_post($post_data);
                if (hocwp_id_number_valid($post_id)) {
                    update_post_meta($post_id, 'sidebar_default', 1);
                    update_post_meta($post_id, 'sidebar_id', $name);
                    update_post_meta($post_id, 'sidebar_name', $data['name']);
                    update_post_meta($post_id, 'sidebar_description', $data['description']);
                    update_post_meta($post_id, 'sidebar_tag', $data['tag']);
                    update_post_meta($post_id, 'active', 1);
                }
            }
        }
        update_option('hocwp_default_sidebars_added', 1);
    }
}