Exemplo n.º 1
0
/**
 * Set various messages
 *
 * @since 1.0
 * @todo  provide better filtering of messages
*/
function edd_wl_set_messages()
{
    // get array of messages
    $messages = edd_wl_messages();
    /**
     * wish-lists.php
     */
    // no lists if no posts
    if (!edd_wl_get_query() && edd_wl_is_page('wish-lists')) {
        edd_wl_set_message('no_lists', $messages['no_lists']);
    }
    /**
     * wish-list-create.php
     */
    // must login
    if (edd_wl_is_page('create') && !edd_wl_allow_guest_creation()) {
        edd_wl_set_message('must_login', $messages['must_login']);
    }
    /**
     * wish-list-view.php
     */
    if (edd_wl_is_page('view')) {
        $downloads = edd_wl_get_list_id() ? edd_wl_get_wish_list(edd_wl_get_list_id()) : array();
        // list updated
        if (isset($_GET['list']) && $_GET['list'] == 'updated') {
            edd_wl_set_message('list_updated', $messages['list_updated']);
        }
        // list created
        if (isset($_GET['list']) && $_GET['list'] == 'created') {
            if (is_user_logged_in()) {
                edd_wl_set_message('list_created', $messages['list_created']);
            } else {
                edd_wl_set_message('list_created', $messages['list_created_guest']);
            }
        }
        // no downloads
        if (empty($downloads)) {
            edd_wl_set_message('no_downloads', $messages['no_downloads']);
        }
    }
}
Exemplo n.º 2
0
/**
 * Open Modal
 *
 * @since 1.0
*/
function edd_wl_open_modal()
{
    check_ajax_referer('edd_wl_ajax_nonce', 'nonce');
    if (!isset($_POST['post_id'])) {
        return;
    }
    $download_id = intval($_POST['post_id']);
    // get price IDs
    $price_ids = isset($_POST['price_ids']) && is_array($_POST['price_ids']) ? $_POST['price_ids'] : '';
    // single price option (shortcode)
    $price_option_single = isset($_POST['price_option_single']) ? $_POST['price_option_single'] : '';
    $to_add = array();
    if (isset($_POST['price_ids']) && is_array($_POST['price_ids'])) {
        foreach ($_POST['price_ids'] as $price) {
            $to_add[] = array('price_id' => $price);
        }
    }
    $items = '';
    foreach ($to_add as $options) {
        if ($download_id == $options['price_id']) {
            $options = array();
        }
        $item = array('id' => $download_id, 'options' => $options);
        // add each item to array
        $items[] = $item;
    }
    // get wish lists and send price IDs + items array
    $lists = edd_wl_get_wish_lists($download_id, $price_ids, $items, $price_option_single);
    // count lists
    $list_count = edd_wl_get_query() ? count(edd_wl_get_query()) : 0;
    $return = array('post_id' => $download_id, 'list_count' => $list_count, 'lists' => html_entity_decode($lists, ENT_COMPAT, 'UTF-8'));
    echo json_encode($return);
    edd_die();
}
Exemplo n.º 3
0
/**
 * Checks to see if an item is already in the wish_list and returns a boolean. Modified from edd_item_in_cart()
 *
 * @since 1.0
 *
 * @param int   $download_id ID of the download to remove
 * @param array $options
 * @return bool Item in the list or not?
 * @todo  modify function to accept list ID, or run a search with get_posts or osmething
 */
function edd_wl_item_in_wish_list($download_id = 0, $options = array(), $list_id = 0)
{
    if (isset($list_id)) {
        $posts = array($list_id);
    } else {
        $posts = edd_wl_get_query();
    }
    if ($posts) {
        $found_ids = array();
        foreach ($posts as $id) {
            $cart_items = get_post_meta($id, 'edd_wish_list', true);
            $found = false;
            if ($cart_items) {
                foreach ($cart_items as $item) {
                    if ($item['id'] == $download_id) {
                        if (isset($options['price_id']) && isset($item['options']['price_id'])) {
                            if ($options['price_id'] == $item['options']['price_id']) {
                                $found = true;
                                break;
                            }
                        } else {
                            $found = true;
                            break;
                        }
                    }
                }
            }
            // add each found id to array
            if ($found) {
                $found_ids[] = $id;
            }
        }
        return $found_ids;
    }
}
Exemplo n.º 4
0
/**
 * Get lists for post ID
 *
 * @since 1.0
*/
function edd_wl_get_wish_lists($download_id, $price_ids, $items, $price_option_single)
{
    ob_start();
    $messages = edd_wl_messages();
    global $edd_options;
    $text = !empty($edd_options['edd_wl_add_to_wish_list']) ? $edd_options['edd_wl_add_to_wish_list'] : sprintf(__('Add to %s', 'edd-wish-lists'), edd_wl_get_label_singular(true));
    ?>

<div class="modal-header">

	<h2 id="edd-wl-modal-label">
		<?php 
    echo esc_attr($text);
    ?>
	</h2>

   <?php 
    $download = $download_id ? get_the_title($download_id) : '';
    // price variations
    // EG: Download Name - Option 1, Option 2, Option 3
    if (edd_has_variable_prices($download_id)) {
        $price_options = array();
        foreach ($items as $item) {
            $price_options[] = edd_get_price_name($item['id'], $item['options']);
        }
    }
    $options = !empty($price_options) ? ' - ' . implode(', ', $price_options) : '';
    // show user what they have selected
    echo '<p>' . sprintf('%1$s%2$s', $download, $options) . '</p>';
    ?>

	<a class="edd-wl-close" href="#" data-dismiss="modal">
		<i class="glyphicon glyphicon-remove"></i>
		<span class="hide-text"><?php 
    _e('Close', 'edd-wish-lists');
    ?>
</span>
	</a>
	
</div>

<div class="modal-body">
	<?php 
    // show lists this item is already included in
    echo edd_wl_lists_included($download_id, $items[0]['options']);
    ?>

	<?php 
    if (!edd_wl_allow_guest_creation()) {
        ?>
		<?php 
        echo '<p>' . $messages['must_login'] . '</p>';
        ?>
	<?php 
    } else {
        ?>
		
		<?php 
        $list_query = edd_wl_get_query();
        $private = edd_wl_get_query('private');
        $public = edd_wl_get_query('public');
        $variable_pricing = edd_has_variable_prices($download_id);
        $data_variable = $variable_pricing ? ' data-variable-price=yes' : 'data-variable-price=no';
        $type = edd_single_price_option_mode($download_id) ? 'data-price-mode=multi' : 'data-price-mode=single';
        ?>

		<form method="post" action="" class="form-modal">
		      
			<?php 
        if ($list_query) {
            ?>
		            <p id="current_lists">
		            <input type="radio" checked="" id="existing-list" value="existing-list" name="list-options">
		            <label for="existing-list"><?php 
            echo $messages['modal_option_add_to_existing'];
            ?>
</label>

		              <select id="user-lists" name="user-lists">
		            	
		            	<?php 
            /**
             * Public lists
             */
            if ($public) {
                ?>

		            	  <optgroup label="Public">
		            	 
		            	  <?php 
                foreach ($public as $id) {
                    ?>
		            	    <option value="<?php 
                    echo $id;
                    ?>
"><?php 
                    echo get_the_title($id) . ' ' . edd_wl_get_item_count($id);
                    ?>
</option>  
		            	 <?php 
                }
                ?>
		            	  
		            	   </optgroup>

		            	<?php 
            }
            ?>

		               <?php 
            /**
             * Private lists
             */
            if ($private) {
                ?>

		                <optgroup label="Private">
		               
		                <?php 
                foreach ($private as $id) {
                    ?>
		                  <option value="<?php 
                    echo $id;
                    ?>
"><?php 
                    echo get_the_title($id) . ' ' . edd_wl_get_item_count($id);
                    ?>
</option> 
		                <?php 
                }
                ?>
		                
		                 </optgroup>
		              <?php 
            }
            ?>

		              </select>

		            </p>

		    <?php 
        }
        ?>

		             <p>
						<input type="radio" id="new-list" value="new-list" name="list-options">
						<label for="new-list"><?php 
        echo $messages['modal_option_add_new'];
        ?>
</label>

						<input type="text" id="list-name" name="list-name" placeholder="<?php 
        echo $messages['modal_option_title'];
        ?>
">

						<select id="list-status" name="list-status">
							<option value="private"><?php 
        echo $messages['list_option_private'];
        ?>
</option>
							<option value="publish"><?php 
        echo $messages['list_option_public'];
        ?>
</option>
						</select>
		            </p>

		              </div>

		         <?php 
        // add a hidden input field for each price ID which our next ajax function will grab
        foreach ($price_ids as $id) {
            ?>
		         		<input name="edd-wish-lists-post-id" type="hidden" value="<?php 
            echo $id;
            ?>
">
		         	<?php 
        }
        ?>
     

		        
		         <?php 
        if ($price_option_single) {
            ?>
		         <input name="edd-wl-single-price-option" type="hidden" value="yes">
		     	<?php 
        }
        ?>

		         <div class="modal-footer"> 			
        				<?php 
        $args = array('download_id' => $download_id, 'text' => $messages['modal_option_save'], 'icon' => '', 'action' => 'edd_add_to_wish_list', 'class' => 'edd-wl-save edd-wl-action', 'style' => 'button');
        edd_wl_wish_list_link($args);
        ?>

        				<a class="edd-wl-button edd-wl-success edd-wl-action" href="#" data-dismiss="modal" style="display:none;">
        					<?php 
        echo $messages['modal_option_close'];
        ?>
        				</a>
	
      				</div>

		            </form>
	<?php 
    }
    ?>
 	
  </div>
	<?php 
    $html = ob_get_clean();
    return apply_filters('edd_wl_get_wish_lists', $html);
}
Exemplo n.º 5
0
<?php

/**
 * Wish List template
*/
$private = edd_wl_get_query('private');
// get the private lists
$public = edd_wl_get_query('public');
// get the public lists
?>

<?php 
echo edd_wl_create_list_link();
// create list
?>

<?php 
/**
 * Private lists
*/
if ($private) {
    ?>
	<h3><?php 
    echo sprintf(__('Private %s', 'edd-wish-lists'), edd_wl_get_label_plural());
    ?>
</h3>
	<ul class="edd-wish-list">
	<?php 
    foreach ($private as $id) {
        ?>
		<li>