public static function get_user_meta_by_id($user_id, $option, $single = true)
 {
     global $current_user;
     if (!$user_id) {
         $user_id = $current_user->ID;
     }
     if (!$user_id) {
         $value = SunshineSession::instance()->{$option};
     } else {
         if ($option == 'email') {
             $value = $current_user->user_email;
         } else {
             $value = get_user_meta($user_id, 'sunshine_' . $option, $single);
         }
     }
     return $value;
 }
function sunshine_init()
{
    global $sunshine;
    add_rewrite_endpoint($sunshine->options['endpoint_gallery'], EP_PERMALINK | EP_PAGES);
    add_rewrite_endpoint($sunshine->options['endpoint_image'], EP_PERMALINK | EP_PAGES);
    add_rewrite_endpoint($sunshine->options['endpoint_order'], EP_PERMALINK | EP_PAGES);
    SunshineUser::instance();
    SunshineCountries::instance();
    $functions = SUNSHINE_PATH . 'themes/' . $sunshine->options['theme'] . '/functions.php';
    if (file_exists($functions)) {
        include_once $functions;
    }
    if (is_admin()) {
        include_once 'admin/sunshine-admin.php';
    } else {
        SunshineSession::instance();
        SunshinePaymentMethods::instance();
        SunshineEmail::instance();
        SunshineFrontend::instance();
    }
}
function sunshine_cart_return()
{
    if (SunshineSession::instance()->last_gallery) {
        ?>
	<div id="sunshine-cart-return">
		<a href="<?php 
        echo get_permalink(SunshineSession::instance()->last_gallery);
        ?>
"><?php 
        echo sprintf(__('Return to gallery "%s"', 'sunshine'), get_the_title(SunshineSession::instance()->last_gallery));
        ?>
</a>
	</div>
<?php 
    }
}
function sunshine_gallery_email_redirect()
{
    global $sunshine;
    if (isset($_POST['sunshine_gallery_email'])) {
        $email = sanitize_email($_POST['sunshine_gallery_email']);
        $gallery_id = intval($_POST['sunshine_gallery_id']);
        if (is_email($_POST['sunshine_gallery_email'])) {
            $gallery_emails = SunshineSession::instance()->gallery_emails;
            $gallery_emails[] = $gallery_id;
            SunshineSession::instance()->gallery_emails = $gallery_emails;
            $existing_emails = get_post_meta($gallery_id, 'sunshine_gallery_email');
            if (!in_array($email, $existing_emails)) {
                add_post_meta($gallery_id, 'sunshine_gallery_email', $email);
                do_action('sunshine_gallery_email', $email, $gallery_id);
            }
        } else {
            $sunshine->add_error(__('Not a valid email address', 'sunshine'));
        }
        wp_safe_redirect(get_permalink($gallery_id));
        exit;
    }
}
 function can_view_order()
 {
     global $wp_query, $current_user;
     if (isset(self::$current_order->ID)) {
         $order_customer_id = get_post_meta(self::$current_order->ID, '_sunshine_customer_id', true);
         if (current_user_can('sunshine_manage_options')) {
             // Admin, always let through
         } elseif ($order_customer_id && $current_user->ID != $order_customer_id) {
             wp_die(__('Sorry, you are not allowed to access this order information', 'sunshine'), __('Access denied', 'sunshine'), array('back_link' => true));
             exit;
         } elseif (!$order_customer_id && SunshineSession::instance()->order_id != self::$current_order->ID) {
             wp_die(__('Sorry, you are not allowed to access this order information', 'sunshine'), __('Access denied', 'sunshine'), array('back_link' => true));
         }
     }
 }
 public function redirect($location, $status = NULL)
 {
     SunshineSession::instance()->errors = $this->errors;
     SunshineSession::instance()->messages = $this->messages;
     return $location;
 }
 public function remove_item_in_cart($hash)
 {
     foreach ($this->content as $key => $cart_item) {
         if ($hash == $cart_item['hash']) {
             if (is_user_logged_in()) {
                 SunshineUser::delete_user_meta('cart', $cart_item);
             } else {
                 unset($this->content[$key]);
                 SunshineSession::instance()->cart = $cart;
             }
             break;
         }
     }
 }