function hocwp_theme_switcher_wp_init() { if (!is_admin()) { $theme = hocwp_get_method_value('theme', 'get'); if (empty($theme) && hocwp_is_force_mobile()) { $theme = hocwp_theme_switcher_get_mobile_theme_name(); } if (!empty($theme)) { hocwp_set_session('hocwp_current_theme', $theme); hocwp_set_cookie('hocwp_current_theme', $theme, time() + DAY_IN_SECONDS, '/'); if (is_user_logged_in()) { $unique = get_current_user_id(); update_option('hocwp_user_' . $unique . '_theme', $theme); unset($unique); } } unset($theme); } }
function hocwp_theme_switcher_get_current_theme() { $theme = hocwp_get_method_value('theme', 'get'); if (empty($theme)) { if (is_user_logged_in()) { $theme = get_option('hocwp_user_' . get_current_user_id() . '_theme'); if (empty($theme)) { $theme = isset($_SESSION['hocwp_current_theme']) ? $_SESSION['hocwp_current_theme'] : ''; if (empty($theme)) { $theme = isset($_COOKIE['hocwp_current_theme']) ? $_COOKIE['hocwp_current_theme'] : ''; } } } else { $theme = isset($_SESSION['hocwp_current_theme']) ? $_SESSION['hocwp_current_theme'] : ''; if (empty($theme)) { $theme = isset($_COOKIE['hocwp_current_theme']) ? $_COOKIE['hocwp_current_theme'] : ''; } } } return apply_filters('hocwp_theme_switcher_current_theme', $theme); }
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_shop_save_product_meta($post_id) { if (!hocwp_can_save_post($post_id)) { return; } if (!hocwp_is_shop_site() || hocwp_wc_installed()) { return; } if (isset($_POST['sku'])) { update_post_meta($post_id, 'sku', $_POST['sku']); } $regular_price = hocwp_get_method_value('regular_price'); $sale_price = hocwp_get_method_value('sale_price'); $prices = hocwp_sanitize_product_price($regular_price, $sale_price, $post_id); update_post_meta($post_id, 'regular_price', $prices['regular_price']); update_post_meta($post_id, 'sale_price', $prices['sale_price']); update_post_meta($post_id, 'price', $prices['price']); if (isset($_POST['short_description'])) { update_post_meta($post_id, 'short_description', $_POST['short_description']); } $out_of_stock = hocwp_checkbox_post_data_value($_POST, 'out_of_stock'); update_post_meta($post_id, 'out_of_stock', $out_of_stock); if (isset($_POST['gallery'])) { update_post_meta($post_id, 'gallery', $_POST['gallery']); } }
function hocwp_translate_x_string_transaltion_update() { if (isset($_REQUEST['hocwp_action']) && 'string_translation' == $_REQUEST['hocwp_action']) { unset($_REQUEST['hocwp_action']); $search = hocwp_get_method_value('s', 'request'); $strings = hocwp_get_method_value('strings'); if (hocwp_array_has_value($strings)) { $mo = new HOCWP_MO(); $saved_strings = hocwp_get_registered_string_language(); foreach ($strings as $encrypted_string) { unset($saved_strings[$encrypted_string]); $mo->delete_from_db($encrypted_string, true); } update_option('hocwp_string_translations', $saved_strings); hocwp_delete_transient('hocwp_string_translation_registered'); } $args = array_intersect_key($_REQUEST, array_flip(array('s', 'paged', 'group'))); if (!empty($search)) { $args['s'] = $search; } if (!empty($args['s'])) { $args['s'] = urlencode($args['s']); } $translations = hocwp_get_method_value('translation'); if (hocwp_array_has_value($translations)) { foreach ($translations as $key => $value) { if (!empty($value)) { $mo = hocwp_get_post_by_column('post_title', 'hocwp_mo_' . $key, OBJECT, array('post_type' => 'hocwp_mo')); if (is_a($mo, 'WP_Post')) { $obj = new HOCWP_MO($mo->ID); $obj->export_to_db($mo->post_excerpt, $value); } } } } $url = add_query_arg($args, wp_get_referer()); wp_safe_redirect($url); exit; } }
function hocwp_generate_slider_sortable_item_ajax_callback() { $result = array(); $max_item_id = hocwp_get_method_value('max_item_id'); $max_item_id = absint($max_item_id); $media_url = hocwp_get_method_value('media_url'); $media_id = hocwp_get_method_value('media_id'); $media_id = absint($media_id); $item_html = '<li data-item="' . $max_item_id . '">'; $item_html .= '<img class="item-image" src="' . $media_url . '">'; $item_html .= '<div class="item-info">'; $item_html .= '<input type="text" placeholder="' . __('Title', 'hocwp-theme') . '" value="" class="item-title" name="slider_items[items][' . $max_item_id . '][title]">'; $item_html .= '<input type="url" placeholder="' . __('Link for this item', 'hocwp-theme') . '" value="" class="item-link" name="slider_items[items][' . $max_item_id . '][link]">'; $item_html .= '<textarea class="item-description" name="slider_items[items][' . $max_item_id . '][description]"></textarea>'; $item_html .= '</div>'; ob_start(); ?> <div class="clear"></div> <div class="advance"> <div class="dashicons dashicons-editor-expand"></div> <div class="box-content"> <div class="settings"> <div class="col-left col50 hocwp-col"> <?php $field_args = array('name' => 'slider_items[items][' . $max_item_id . '][background_color]', 'label' => __('Background Color', 'hocwp-theme'), 'value' => ''); hocwp_field_color_picker($field_args); ?> </div> <div class="col-right col50 hocwp-col"> </div> </div> </div> </div> <?php $item_html .= ob_get_clean(); $item_html .= '<input type="hidden" class="item-image-url" name="slider_items[items][' . $max_item_id . '][image_url]" value="' . $media_url . '">'; $item_html .= '<input type="hidden" class="item-image-id" name="slider_items[items][' . $max_item_id . '][image_id]" value="' . $media_id . '">'; $item_html .= '<span title="' . __('Delete this item', 'hocwp-theme') . '" class="item-icon icon-delete icon-sortable-ui"></span>'; $item_html .= '<span title="' . __('Re-order this item', 'hocwp-theme') . '" class="item-icon icon-drag icon-sortable-ui"></span>'; $item_html .= '<span title="' . __('Add child item', 'hocwp-theme') . '" class="item-icon icon-add icon-sortable-ui"></span>'; $item_html .= '</li>'; $result['html_data'] = $item_html; wp_send_json($result); }
function hocwp_setup_theme_save_post_meta_hook($post_id) { if (!hocwp_can_save_post($post_id)) { return $post_id; } $post = get_post($post_id); $post_type = $post->post_type; global $hocwp_metas; if (hocwp_array_has_value($hocwp_metas)) { foreach ($hocwp_metas as $meta) { if ('post' == $meta->get_type()) { $post_types = $meta->get_post_types(); $fields = $meta->get_fields(); foreach ($fields as $field) { $meta->save_post_meta_helper($post_id, $field); } $fields = $meta->get_custom_fields(); if (is_array($fields)) { foreach ($fields as $field) { $meta->save_post_meta_helper($post_id, $field); } } } } } $value = isset($_POST['featured']) ? 1 : 0; update_post_meta($post_id, 'featured', $value); $value = isset($_POST['active']) ? 1 : 0; update_post_meta($post_id, 'active', $value); if ('hocwp_subscriber' == $post->post_type) { update_post_meta($post_id, 'subscriber_verified', $value); } switch ($post_type) { case 'hocwp_sidebar': if (isset($_POST['sidebar_id'])) { update_post_meta($post_id, 'sidebar_id', hocwp_sanitize_id($_POST['sidebar_id'])); } if (isset($_POST['sidebar_name'])) { update_post_meta($post_id, 'sidebar_name', sanitize_text_field($_POST['sidebar_name'])); } if (isset($_POST['sidebar_description'])) { update_post_meta($post_id, 'sidebar_description', sanitize_text_field($_POST['sidebar_description'])); } if (isset($_POST['sidebar_tag'])) { update_post_meta($post_id, 'sidebar_tag', sanitize_text_field($_POST['sidebar_tag'])); } break; case 'hocwp_slider': if (isset($_POST['slider_items'])) { update_post_meta($post_id, 'slider_items', $_POST['slider_items']); } if (isset($_POST['position'])) { update_post_meta($post_id, 'position', $_POST['position']); } $fit_width = hocwp_get_method_value('fit_width'); update_post_meta($post_id, 'fit_width', $fit_width); if (isset($_POST['height'])) { update_post_meta($post_id, 'height', $_POST['height']); } break; case 'hocwp_ads': if (isset($_POST['position'])) { update_post_meta($post_id, 'position', $_POST['position']); } if (isset($_POST['expire'])) { update_post_meta($post_id, 'expire', strtotime($_POST['expire'])); } if (isset($_POST['code'])) { update_post_meta($post_id, 'code', $_POST['code']); } $image = hocwp_get_method_value('image'); update_post_meta($post_id, 'image', $image); $url = hocwp_get_method_value('url'); update_post_meta($post_id, 'url', $url); break; case 'hocwp_subscriber': if (isset($_POST['subscriber_name'])) { update_post_meta($post_id, 'subscriber_name', sanitize_text_field($_POST['subscriber_name'])); } if (isset($_POST['subscriber_phone'])) { update_post_meta($post_id, 'subscriber_phone', sanitize_text_field($_POST['subscriber_phone'])); } break; case 'coupon': if (isset($_POST['expired_date'])) { update_post_meta($post_id, 'expired_date', strtotime($_POST['expired_date'])); } break; case 'product': $args = array('posts_per_page' => -1, 'post_type' => 'hocwp_product_tab'); $query = hocwp_query($args); if ($query->have_posts()) { foreach ($query->posts as $product) { $field_name = hocwp_sanitize_id($product->post_name); if (isset($_POST[$field_name])) { update_post_meta($post_id, $field_name, $_POST[$field_name]); } } } break; case 'partner': if (isset($_POST['url'])) { update_post_meta($post_id, 'url', esc_url($_POST['url'])); } if (isset($_POST['thumbnail'])) { update_post_meta($post_id, 'thumbnail', $_POST['thumbnail']); } break; } return $post_id; }
function hocwp_lostpassword_form($args = array()) { $defaults = hocwp_account_form_default_args(); $args = wp_parse_args($args, $defaults); $data = hocwp_execute_lostpassword(); $user_login = $data['user_login']; $error = $data['error']; $message = $data['message']; $redirect_to = hocwp_get_value_by_key($args, 'redirect_to', hocwp_get_method_value('redirect_to', 'get')); $logo = hocwp_get_value_by_key($args, 'logo', hocwp_get_login_logo_url()); ?> <div class="hocwp-login-box module"> <div class="module-header text-center"> <?php if (!empty($logo)) { $a = new HOCWP_HTML('a'); $a->set_href(home_url('/')); $a->set_class('logo'); $img = new HOCWP_HTML('img'); $img->set_image_alt(''); $img->set_image_src($logo); $a->set_text($img->build()); $a->output(); } $slogan = new HOCWP_HTML('p'); $slogan->set_class('slogan'); $slogan->set_text(sprintf($args['slogan'], hocwp_get_root_domain_name(home_url('/')))); $slogan->output(); if (isset($_POST['submit']) || isset($_POST['wp-submit'])) { if (isset($_REQUEST['error']) || $error) { $message = hocwp_build_message($message, 'danger'); echo $message; } else { if (!empty($message) && !$error || isset($_POST['submit']) && !empty($message)) { $message = hocwp_build_message($message, 'success'); echo $message; } } } ?> </div> <div class="module-body"> <h4 class="form-title"><?php _e('Reset password', 'hocwp-theme'); ?> </h4> <form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url(wp_lostpassword_url()); ?> " method="post"> <p> <label><?php echo hocwp_get_value_by_key($args, 'label_username', __('Username or Email', 'hocwp-theme')); ?> <br> <input type="text" size="20" value="<?php echo esc_attr($user_login); ?> " class="input" id="user_login" name="user_login"></label> </p> <input type="hidden" name="action" value="lostpassword"> <input type="hidden" name="redirect_to" value="<?php echo $redirect_to; ?> "> <p class="submit"> <input type="submit" name="wp-submit" id="wp-submit" class="button-primary" value="Get New Password" tabindex="100"></p> </form> </div> <div class="module-footer"> <div class="text-center"> <p class="form-nav"> <a href="<?php echo esc_url(wp_login_url()); ?> "><?php echo hocwp_get_value_by_key($args, 'label_log_in', __('Login', 'hocwp-theme')); ?> </a> <span class="sep">|</span> <a href="<?php echo esc_url(wp_lostpassword_url()); ?> " title="<?php echo $args['title_lostpassword_link']; ?> "><?php echo $args['text_lostpassword_link']; ?> </a> </p> </div> </div> </div> <?php }
function hocwp_setup_theme_edit_link_admin_footer() { global $pagenow; if ('link.php' == $pagenow || 'link-add.php' == $pagenow) { $link_category = array(); $link_id = hocwp_get_method_value('link_id', 'get'); if (hocwp_id_number_valid($link_id)) { $bookmark = get_bookmark($link_id); if (hocwp_object_valid($bookmark)) { $link_category = $bookmark->link_category; } } hocwp_field_input_hidden(array('name' => 'hocwp_link_category', 'value' => json_encode($link_category))); } }
function hocwp_classifieds_admin_notice() { $post_id = hocwp_get_method_value('post', 'request'); if (hocwp_id_number_valid($post_id)) { $transient_name = hocwp_build_transient_name('hocwp_save_classifieds_post_%s_error', $post_id); $errors = get_transient($transient_name); if (false !== $errors) { foreach ($errors as $error) { hocwp_admin_notice(array('text' => $error, 'error' => true)); } delete_transient($transient_name); } } }
function hocwp_check_captcha($captcha_code = '') { if (empty($captcha_code)) { $captcha_code = hocwp_get_method_value('captcha', 'request'); } $captcha = new HOCWP_Captcha(); if ($captcha->check($captcha_code)) { return true; } return false; }
function hocwp_wc_order_item_ajax_callback() { $result = array('success' => false, 'html_data' => '<p class="alert alert-danger">' . __('There was an error occurred, please try again.', 'hocwp-theme') . '</p>'); $post_id = hocwp_get_method_value('post_id'); if (hocwp_id_number_valid($post_id)) { $post = get_post($post_id); if (is_a($post, 'WP_Post') && 'product' == $post->post_type) { $name = hocwp_get_method_value('name'); $phone = hocwp_get_method_value('phone'); $email = hocwp_get_method_value('email'); $address = hocwp_get_method_value('address'); $message = hocwp_get_method_value('message'); $attributes = hocwp_get_method_value('attributes'); $order = hocwp_wc_insert_order(array('post_id' => $post_id, 'name' => $name, 'email' => $email, 'phone' => $phone, 'address' => $address, 'message' => $message, 'attributes' => $attributes)); if (false !== $order) { $result['success'] = true; $result['html_data'] = '<p class="alert alert-success">' . __('Your order has been successfully saved, we will reply to you as soon as possible.', 'hocwp-theme') . '</p>'; } } } wp_send_json($result); }
function hocwp_add_to_newsletter_list($args = array()) { if (hocwp_newsletter_plugin_installed()) { global $newsletter; if (!isset($newsletter)) { $newsletter = new Newsletter(); } if (isset($newsletter->options['api_key']) && !empty($newsletter->options['api_key'])) { $api_key = hocwp_get_value_by_key($args, 'api_key'); if (empty($api_key)) { $api_key = $newsletter->options['api_key']; } $email = hocwp_get_value_by_key($args, 'email'); if (is_email($email)) { $base_url = NEWSLETTER_URL . '/api/add.php'; $params = array('ne' => $email, 'nk' => $api_key); $name = hocwp_get_value_by_key($args, 'name'); $surname = hocwp_get_method_value($args, 'surname'); $params['nn'] = $name; $params['ns'] = $surname; $base_url = add_query_arg($params, $base_url); $result = @file_get_contents($base_url); } } } }
function hocwp_get_force_mobile() { $mobile = hocwp_get_method_value('mobile', 'get'); return $mobile; }
function hocwp_meta_box_save_link_featured_image($link_id) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (!isset($_POST['fetured_image_nonce']) || !wp_verify_nonce($_POST['fetured_image_nonce'], 'hocwp_link_meta')) { return; } $thumbnail = hocwp_get_method_value('thumbnail'); update_option('hocwp_link_' . $link_id . '_thumbnail', $thumbnail); }
function hocwp_slider_on_save_slider_info($post_id) { if (!hocwp_can_save_post($post_id)) { return; } $slider = get_post($post_id); if ('hocwp_slider' == $slider->post_type) { $items = hocwp_get_method_value('slider_items'); $saved = hocwp_get_post_meta('slider_items', $post_id); if (!is_array($items)) { $items = array(); } if (!is_array($saved)) { $saved = array(); } $items = wp_parse_args($items, $saved); update_post_meta($post_id, 'slider_items', $items); if (isset($_POST['position'])) { update_post_meta($post_id, 'position', $_POST['position']); } unset($_POST['slider_items']); } }
function hocwp_google_login_button() { $action = hocwp_get_method_value('action', 'request'); ?> <button type="button" data-action="login-google" onclick="hocwp_google_login();" class="btn-google btn-social-login btn btn-large"> <svg class="flicon-google flip-icon" viewBox="0 0 30 28" height="448" width="256" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" version="1.1"> <path d="M 17.471,2c0,0-6.28,0-8.373,0C 5.344,2, 1.811,4.844, 1.811,8.138c0,3.366, 2.559,6.083, 6.378,6.083 c 0.266,0, 0.524-0.005, 0.776-0.024c-0.248,0.475-0.425,1.009-0.425,1.564c0,0.936, 0.503,1.694, 1.14,2.313 c-0.481,0-0.945,0.014-1.452,0.014C 3.579,18.089,0,21.050,0,24.121c0,3.024, 3.923,4.916, 8.573,4.916 c 5.301,0, 8.228-3.008, 8.228-6.032c0-2.425-0.716-3.877-2.928-5.442c-0.757-0.536-2.204-1.839-2.204-2.604 c0-0.897, 0.256-1.34, 1.607-2.395c 1.385-1.082, 2.365-2.603, 2.365-4.372c0-2.106-0.938-4.159-2.699-4.837l 2.655,0 L 17.471,2z M 14.546,22.483c 0.066,0.28, 0.103,0.569, 0.103,0.863c0,2.444-1.575,4.353-6.093,4.353 c-3.214,0-5.535-2.034-5.535-4.478c0-2.395, 2.879-4.389, 6.093-4.354c 0.75,0.008, 1.449,0.129, 2.083,0.334 C 12.942,20.415, 14.193,21.101, 14.546,22.483z M 9.401,13.368c-2.157-0.065-4.207-2.413-4.58-5.246 c-0.372-2.833, 1.074-5.001, 3.231-4.937c 2.157,0.065, 4.207,2.338, 4.58,5.171 C 13.004,11.189, 11.557,13.433, 9.401,13.368zM 26,8L 26,2L 24,2L 24,8L 18,8L 18,10L 24,10L 24,16L 26,16L 26,10L 32,10L 32,8 z"/> </svg> <span> <?php if ('register' == $action) { _e('Register with Google', 'hocwp-theme'); } else { _e('Login with Google', 'hocwp-theme'); } ?> </span> </button> <?php }