コード例 #1
1
function ck_edd_user_download_button($purchase_form, $args)
{
    global $edd_options;
    if (!is_user_logged_in()) {
        return $purchase_form;
    }
    $download_id = (string) $args['download_id'];
    $current_user_id = get_current_user_id();
    // If the user has purchased this item, itterate through their purchases to get the specific
    // purchase data and pull out the key and email associated with it. This is necessary for the
    // generation of the download link
    if (edd_has_user_purchased($current_user_id, $download_id, $variable_price_id = null)) {
        $user_purchases = edd_get_users_purchases($current_user_id, -1, false, 'complete');
        foreach ($user_purchases as $purchase) {
            $cart_items = edd_get_payment_meta_cart_details($purchase->ID);
            $item_ids = wp_list_pluck($cart_items, 'id');
            if (in_array($download_id, $item_ids)) {
                $email = edd_get_payment_user_email($purchase->ID);
                $payment_key = edd_get_payment_key($purchase->ID);
            }
        }
        $download_ids = array();
        if (edd_is_bundled_product($download_id)) {
            $download_ids = edd_get_bundled_products($download_id);
        } else {
            $download_ids[] = $download_id;
        }
        // Setup the style and colors associated with the settings
        $style = isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button';
        $color = isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue';
        $new_purchase_form = '';
        foreach ($download_ids as $item) {
            // Attempt to get the file data associated with this download
            $download_data = edd_get_download_files($item, null);
            if ($download_data) {
                foreach ($download_data as $filekey => $file) {
                    // Generate the file URL and then make a link to it
                    $file_url = edd_get_download_file_url($payment_key, $email, $filekey, $item, null);
                    $new_purchase_form .= '<a href="' . $file_url . '" class="' . $style . ' ' . $color . ' edd-submit"><span class="edd-add-to-cart-label">Download ' . $file['name'] . '</span></a>&nbsp;';
                }
            }
            // As long as we ended up with links to show, use them.
            if (!empty($new_purchase_form)) {
                $purchase_form = '<h4>' . __('You already own this product. Download it now:', 'edd') . '</h4>' . $new_purchase_form;
            }
        }
    }
    return $purchase_form;
}
コード例 #2
0
/**
 * edd_rp_get_suggestions
 *
 * Generates the suggestions for a download based off post_id
 * If the user is logged it, it will remove already purchased items from the array
 * *
 * @since       1.0
 * @param 		$post_id int the download ID being requested
 * @param   	$user_id int a user ID to filter already purchased items from the return
 * @param       $count   int The number of items to display
 * @return      array
*/
function edd_rp_get_suggestions($post_id = false, $user_id = false, $count = false)
{
    if (!$post_id) {
        return false;
    }
    global $master_array;
    if (!is_array($master_array) || empty($master_array[$post_id])) {
        $recommendations = array();
    } else {
        // If a user ID is supplied and they have purchased the item suggested, remove it
        if ($user_id) {
            foreach ($master_array[$post_id] as $id => $count) {
                if (edd_has_user_purchased($user_id, $id, NULL)) {
                    unset($master_array[$post_id][$id]);
                }
            }
        }
        // If the user has items in the cart, remove those from the suggestions
        $cart_items = edd_get_cart_contents();
        if ($cart_items) {
            $cart_post_ids = wp_list_pluck($cart_items, 'id');
            foreach ($cart_post_ids as $cart_item) {
                if (isset($master_array[$post_id][$cart_item])) {
                    unset($master_array[$post_id][$cart_item]);
                }
            }
        }
        $recommendations = $master_array[$post_id];
    }
    // If we didn't get a new length to slice to ( usually from short codes )
    if (empty($count)) {
        $count = apply_filters('edd_rp_single_recommendation_count', edd_get_option('edd_rp_suggestion_count', 3));
    }
    return apply_filters('edd_rp_single_recommendation_results', array_slice($recommendations, 0, $count, true));
}
コード例 #3
0
/**
 * Prevents logged-in customers from purchasing an item twice
 *
 */
function pw_edd_prevent_duplicate_purchase($valid_data, $posted)
{
    $cart_contents = edd_get_cart_contents();
    foreach ($cart_contents as $item) {
        if (edd_has_user_purchased(get_current_user_id(), $item['id'])) {
            edd_set_error('duplicate_item', 'You have already purchased this item so may not purchase it again');
        }
    }
}
/**
 * Restrict commission to purchased products in Easy Digital Downloads
 *
 * Make sure to enable "Ignore Zero Referrals?" from Affiliates -> Settings -> Misc
 * If you would like 0.00 referrals to be ignored.
*/
function affwp_edd_restrict_commission_to_purchased_products($referral_amount, $affiliate_id, $amount, $reference, $product_id)
{
    // get referring affiliate ID
    $affiliate_id = affiliate_wp()->tracking->get_affiliate_id();
    // get user ID of referring affiliate
    $user_id = affwp_get_affiliate_user_id($affiliate_id);
    if (!(function_exists('edd_has_user_purchased') && edd_has_user_purchased($user_id, array($product_id)))) {
        $referral_amount = 0.0;
    }
    return $referral_amount;
}
コード例 #5
0
    function render_comments_table_row($comment)
    {
        $comment_date = get_comment_date('Y/m/d \\a\\t g:i a', $comment->comment_ID);
        $comment_author_img = EDD_FES()->vendors->get_avatar('comment_author_image', $comment->comment_author_email, 32);
        $purchased = edd_has_user_purchased($comment->user_id, $comment->comment_post_ID);
        ?>
	<tr>
		<td class="col-author" style="width:25%;">
			<div class="fes-author-img"><?php 
        echo $comment_author_img;
        ?>
</div>
			<span id="fes-comment-author"><?php 
        echo $comment->comment_author;
        ?>
</span>
			<br /><br />
			<?php 
        if ($purchased) {
            echo '<div class="fes-light-green">' . __('Has Purchased', 'edd_fes') . '</div>';
        } else {
            echo '<div class="fes-light-red">' . __('Has Not Purchased', 'edd_fes') . '</div>';
        }
        ?>
			<span id="fes-comment-date"><?php 
        echo $comment_date;
        ?>
&nbsp;&nbsp;&nbsp;</span><br />
			<span id="fes-product-name">
				<b><?php 
        echo EDD_FES()->vendors->get_product_constant_name($plural = false, $uppercase = true) . ': ';
        ?>
</b>
				<a href="<?php 
        echo esc_url(get_permalink($comment->comment_post_ID));
        ?>
"><?php 
        echo get_the_title($comment->comment_post_ID);
        ?>
</a>&nbsp;&nbsp;&nbsp;
			</span><br />
			<span id="fes-view-comment">
				<a href="<?php 
        echo esc_url(get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID);
        ?>
"><?php 
        _e('View Comment', 'edd_fes');
        ?>
</a>
			</span>
		</td>
		<td class="col-content" style="width:70%;">
			<div class="fes-comments-content"><?php 
        echo $comment->comment_content;
        ?>
</div>
			<hr/>
			<div id="<?php 
        echo $comment->comment_post_ID;
        ?>
" class="fes-vendor-comment-respond-form">
				<span><?php 
        _e('Respond:', 'edd_fes');
        ?>
</span><br/>
				<table>
					<tr>
						<form id="fes_comments-form" action="" method="post">
							<input type="hidden" name="cid" value="<?php 
        echo $comment->comment_ID;
        ?>
">
							<input type="hidden" name="pid" value="<?php 
        echo $comment->comment_post_ID;
        ?>
">
							<input type="hidden" name="aid" value="<?php 
        echo get_current_user_id();
        ?>
">
							<?php 
        wp_nonce_field('fes_comment_nonce', 'fes_nonce');
        ?>
							<textarea class="fes-cmt-body" name="newcomment_body" cols="50" rows="8"></textarea>
							<button class="fes-cmt-submit-form button" type="submit"><?php 
        _e('Post Response', 'edd_fes');
        ?>
</button>
						</form>
						<form id="fes_ignore-form" action="" method="post">
							<input type="hidden" name="cid" value="<?php 
        echo $comment->comment_ID;
        ?>
">
							<?php 
        wp_nonce_field('fes_ignore_nonce', 'fes_nonce');
        ?>
							<button class="fes-ignore button" type="submit"><?php 
        _e('Mark as Read', 'edd_fes');
        ?>
</button>
						</form>
					</tr>
				</table>
			</div>
		</td>
	</tr>
	<?php 
    }
コード例 #6
0
/**
 * Show Has Purchased Item Message
 *
 * Prints a notice when user has already purchased the item.
 *
 * @since 1.0
 * @deprecated 1.8
 * @global $user_ID
 */
function edd_show_has_purchased_item_message()
{
    $backtrace = debug_backtrace();
    _edd_deprecated_function(__FUNCTION__, '1.8', 'no alternatives', $backtrace);
    global $user_ID, $post;
    if (!isset($post->ID)) {
        return;
    }
    if (edd_has_user_purchased($user_ID, $post->ID)) {
        $alert = '<p class="edd_has_purchased">' . __('You have already purchased this item, but you may purchase it again.', 'edd') . '</p>';
        echo apply_filters('edd_show_has_purchased_item_message', $alert);
    }
}
コード例 #7
0
ファイル: template-tags.php プロジェクト: evinw/project_3dBP
    /**
     * Comments
     *
     * @since Marketify 1.0
     *
     * @return void
     */
    function marketify_comment($comment, $args, $depth)
    {
        global $post;
        $GLOBALS['comment'] = $comment;
        ?>
	<li id="comment-<?php 
        comment_ID();
        ?>
" <?php 
        comment_class(empty($args['has_children']) ? '' : 'parent');
        ?>
>
		<article id="div-comment-<?php 
        comment_ID();
        ?>
" class="comment-body">

			<footer class="comment-meta">
				<div class="comment-author vcard">
					<?php 
        if (0 != $args['avatar_size']) {
            echo get_avatar($comment, $args['avatar_size']);
        }
        ?>

					<?php 
        if ($depth == 1) {
            ?>
						<?php 
            printf('<cite class="fn">%s</cite>', get_comment_author_link());
            ?>

						<?php 
            if (get_option('comment_registration') && edd_has_user_purchased($comment->user_id, $post->ID)) {
                ?>
							<a class="button purchased"><?php 
                _e('Purchased', 'marketify');
                ?>
</a>
						<?php 
            }
            ?>
					<?php 
        }
        ?>
				</div><!-- .comment-author -->
			</footer><!-- .comment-meta -->

			<div class="comment-content">
				<div class="comment-metadata">
					<?php 
        printf('<cite class="fn">%s</cite>', get_comment_author_link());
        ?>

					<?php 
        if (get_comment_meta($comment->comment_ID, 'edd_rating', true)) {
            ?>
						<?php 
            do_action('marketify_edd_rating', $comment);
            ?>
					<?php 
        }
        ?>

					<a href="<?php 
        echo esc_url(get_comment_link($comment->comment_ID));
        ?>
">
						<time datetime="<?php 
        comment_time('c');
        ?>
">
							<?php 
        printf(_x('%1$s at %2$s', '1: date, 2: time', 'marketify'), get_comment_date(), get_comment_time());
        ?>
						</time>
					</a>

					<?php 
        comment_reply_link(array_merge($args, array('add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'], 'before' => '<span class="reply-link"> &mdash; ', 'after' => '</span>')));
        ?>

					<?php 
        edit_comment_link(__('Edit', 'marketify'), ' &mdash; <span class="edit-link">', '</span>');
        ?>
				</div><!-- .comment-metadata -->

				<?php 
        if ('0' == $comment->comment_approved) {
            ?>
				<p class="comment-awaiting-moderation"><?php 
            _e('Your comment is awaiting moderation.', 'marketify');
            ?>
</p>
				<?php 
        }
        ?>

				<?php 
        comment_text();
        ?>
			</div><!-- .comment-content -->

		</article><!-- .comment-body -->

	<?php 
    }
コード例 #8
0
/**
 * Show Has Purchased Item Message
 *
 * Prints a notice when user has already purchased the item.
 *
 * @access      private
 * @since       1.0
 * @return      void
*/
function edd_show_has_purchased_item_message($download_id)
{
    global $user_ID;
    if (edd_has_user_purchased($user_ID, $download_id)) {
        echo '<p class="edd_has_purchased">' . __('You have already purchased this item, but you may purchase it again.', 'edd') . '</p>';
    }
}
コード例 #9
0
/**
 * Check to see if a user has access to a post/page
 *
 * @since       2.0
 * @param       int $user_id The ID of the user to check
 * @param       array $restricted_to The array of downloads for a post/page
 * @param       int $post_id The ID of the object we are viewing
 * @return      array $return An array containing the status and optional message
 */
function edd_cr_user_can_access($user_id = false, $restricted_to, $post_id = false)
{
    $has_access = false;
    $restricted_count = count($restricted_to);
    $products = array();
    // If no user is given, use the current user
    if (!$user_id) {
        $user_id = get_current_user_id();
    }
    // bbPress specific checks. Moderators can see everything
    if (class_exists('bbPress') && current_user_can('moderate')) {
        $has_access = true;
    }
    // Admins have full access
    if (current_user_can('manage_options')) {
        $has_access = true;
    }
    // The post author can always access
    if ($post_id && current_user_can('edit_post', $post_id)) {
        $has_access = true;
    }
    if ($restricted_to && !$has_access) {
        foreach ($restricted_to as $item => $data) {
            if (empty($data['download'])) {
                $has_access = true;
            }
            // The author of a download always has access
            if ((int) get_post_field('post_author', $data['download']) === (int) $user_id && is_user_logged_in()) {
                $has_access = true;
                break;
            }
            // If restricted to any customer and user has purchased something
            if ('any' === $data['download'] && edd_has_purchases($user_id) && is_user_logged_in()) {
                $has_access = true;
                break;
            } elseif ('any' === $data['download']) {
                $products[0] = __('any product', 'edd-cr');
                $has_access = false;
                break;
            }
            // Check for variable prices
            if (!$has_access) {
                if (edd_has_variable_prices($data['download'])) {
                    if (strtolower($data['price_id']) !== 'all' && !empty($data['price_id'])) {
                        $products[] = '<a href="' . get_permalink($data['download']) . '">' . get_the_title($data['download']) . ' - ' . edd_get_price_option_name($data['download'], $data['price_id']) . '</a>';
                        if (edd_has_user_purchased($user_id, $data['download'], $data['price_id'])) {
                            $has_access = true;
                        }
                    } else {
                        $products[] = '<a href="' . get_permalink($data['download']) . '">' . get_the_title($data['download']) . '</a>';
                        if (edd_has_user_purchased($user_id, $data['download'])) {
                            $has_access = true;
                        }
                    }
                } else {
                    $products[] = '<a href="' . get_permalink($data['download']) . '">' . get_the_title($data['download']) . '</a>';
                    if (is_user_logged_in() && edd_has_user_purchased($user_id, $data['download'])) {
                        $has_access = true;
                    }
                }
            }
        }
        if ($has_access == false) {
            if ($restricted_count > 1) {
                $message = __('This content is restricted to buyers of:', 'edd-cr');
                if (!empty($products)) {
                    $message .= '<ul>';
                    foreach ($products as $id => $product) {
                        $message .= '<li>' . $product . '</li>';
                    }
                    $message .= '</ul>';
                }
            } else {
                $message = sprintf(__('This content is restricted to buyers of %s.', 'edd-cr'), $products[0]);
            }
        }
        if (isset($message)) {
            $return['message'] = $message;
        } else {
            $return['message'] = __('This content is restricted to buyers.', 'edd-cr');
        }
    } else {
        // Just in case we're checking something unrestricted...
        $has_access = true;
    }
    // Allow plugins to modify the restriction requirements
    $has_access = apply_filters('edd_cr_user_can_access', $has_access, $user_id, $restricted_to);
    $return['status'] = $has_access;
    return $return;
}
コード例 #10
0
ファイル: edd-reviews.php プロジェクト: SelaInc/eassignment
 /**
  * Conditional whether the currently logged in user has purchased the product
  * before
  *
  * @since 1.2
  * @access public
  * @global array $post Used to access the current post
  * @return void
  */
 public function is_user_buyer()
 {
     global $post;
     if (edd_has_user_purchased(get_current_user_id(), $post->post_ID)) {
         return true;
     } else {
         return false;
     }
     // end if
 }