private function checkout() { $sticky_info = $this->upgrades_api->get_info($this->listing->get_id()); if ($sticky_info->pending || !$sticky_info->upgradeable || !wpbdp_payments_possible()) { return; } $payment = new WPBDP_Payment(array('listing_id' => $this->listing->get_id())); $payment->add_item('upgrade', $sticky_info->upgrade->cost, _x('Listing upgrade to featured', 'submit', 'WPBDM')); $payment->save(); update_post_meta($this->listing->get_id(), '_wpbdp[sticky]', 'pending'); // FIXME: maybe this should be set automatically when saving the payment? require_once WPBDP_PATH . 'core/view-checkout.php'; $checkout = new WPBDP_Checkout_Page($payment); return $checkout->dispatch(); }
/** * Checks if a given user can perform some action to a listing. * @param string $action the action to be checked. available actions are 'view', 'edit', 'delete' and 'upgrade-to-sticky' * @param (object|int) $listing_id the listing ID. if null, the current post ID will be used * @param int $user_id the user ID. if null, the current user will be used * @return boolean * @since 2.1 */ function wpbdp_user_can($action, $listing_id = null, $user_id = null) { $listing_id = $listing_id ? is_object($listing_id) ? $listing_id->ID : intval($listing_id) : get_the_ID(); $user_id = $user_id ? $user_id : wp_get_current_user()->ID; $post = get_post($listing_id); if ($post->post_type != WPBDP_POST_TYPE) { return false; } if (isset($_GET['preview'])) { return false; } switch ($action) { case 'view': return true; break; case 'edit': case 'delete': return user_can($user_id, 'administrator') || $post->post_author && $post->post_author == $user_id; break; case 'upgrade-to-sticky': if (!wpbdp_get_option('featured-on') || !wpbdp_get_option('payments-on')) { return false; } if (!wpbdp_payments_possible()) { return false; } $sticky_info = wpbdp_listing_upgrades_api()->get_info($listing_id); return $sticky_info->upgradeable && (user_can($user_id, 'administrator') || $post->post_author == $user_id); break; } return false; }