本文整理汇总了PHP中wp_car_manager函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_car_manager函数的具体用法?PHP wp_car_manager怎么用?PHP wp_car_manager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_car_manager函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* AJAX callback method
*
* @return void
*/
public function run()
{
// check nonce
$this->check_nonce();
// @todo set filters
$filters = array();
// get filters from get vars
foreach ($_GET as $get_key => $get_var) {
if (0 === strpos($get_key, 'filter_')) {
$filters[str_ireplace('filter_', '', $get_key)] = absint($get_var);
}
}
// get vehicles
$vehicle_manager = new Vehicle\Manager();
$vehicles = $vehicle_manager->get_vehicles($filters);
// check & loop
if (count($vehicles) > 0) {
foreach ($vehicles as $vehicle) {
// title
$title = get_the_title($vehicle->get_id());
// get image
$image = get_the_post_thumbnail($vehicle->get_id(), apply_filters('wpcm_listings_vehicle_thumbnail_size', 'wpcm_vehicle_listings_item'), array('title' => $title, 'alt' => $title, 'class' => 'wpcm-listings-item-image'));
// load template
wp_car_manager()->service('template_manager')->get_template_part('listings/item', '', array('url' => get_permalink($vehicle->get_id()), 'title' => $title, 'image' => $image, 'description' => $vehicle->get_short_description(), 'price' => $vehicle->get_formatted_price(), 'mileage' => $vehicle->get_formatted_mileage(), 'frdate' => $vehicle->get_formatted_frdate()));
}
} else {
wp_car_manager()->service('template_manager')->get_template_part('listings/no-results', '', array());
}
// bye
exit;
}
示例2: run
/**
* AJAX callback method
*
* @return void
*/
public function run()
{
// check nonce
$this->check_nonce();
// check if make is set
if (!isset($_GET['make'])) {
return;
}
// make
$make = absint($_GET['make']);
// models array
$models = array();
// get raw models
$models_raw = wp_car_manager()->service('make_model_manager')->get_models($make);
// check & loop
if (count($models_raw) > 0) {
foreach ($models_raw as $model_raw) {
// add to $models array
$models[] = array('id' => $model_raw['id'], 'name' => $model_raw['name']);
}
}
// send JSON
wp_send_json($models);
// bye
exit;
}
示例3: ajax_get_models
/**
* AJAX 'get_models' callback
*/
public function ajax_get_models()
{
// check nonce
check_ajax_referer('wpcm-dat-ajax-nonce', 'nonce');
// check if make is set
if (!isset($_POST['make'])) {
return;
}
// make
$make = absint($_POST['make']);
// models array
$models = array();
// get raw models
$models_raw = wp_car_manager()->service('make_model_manager')->get_models($make);
// check & loop
if (count($models_raw) > 0) {
foreach ($models_raw as $model_raw) {
// add to $models array
$models[] = array('id' => $model_raw['id'], 'name' => $model_raw['name']);
}
}
// send JSON
wp_send_json($models);
// bye
exit;
}
示例4: mileage
/**
* Formats mileage
*
* @param $mileage
*
* @return string
*/
public static function mileage($mileage)
{
/** @var Settings $settings */
$settings = wp_car_manager()->service('settings');
// translated distance units
$translated_distance_units = array('miles' => __('miles', 'wp-car-manager'), 'km' => __('km', 'wp-car-manager'));
return number_format($mileage ? $mileage : 0, 0, $settings->get_option('decimal_separator'), $settings->get_option('thousand_separator')) . ' ' . $translated_distance_units[$settings->get_option('distance_unit')];
}
示例5: output
/**
* @param array $atts
*
* @return string
*/
public function output($atts)
{
// JS
WPCarManager\Assets::enqueue_shortcode_submit_car_form();
// start output buffer
ob_start();
wp_car_manager()->service('submit_car_handler')->display_next_step();
return ob_get_clean();
}
示例6: meta_box_output
/**
* Actual meta box output
*
* @param \WP_Post $post
*/
public function meta_box_output($post)
{
// nonce
$this->output_nonce();
// vehicle
$vehicle = wp_car_manager()->service('vehicle_factory')->make($post->ID);
// load view
wp_car_manager()->service('view_manager')->display('meta-box/mb-data', array('mb_prefix' => 'wpcm-ld', 'vehicle' => $vehicle, 'fields' => array('condition' => array('type' => 'date', 'label' => __('Expiry Date:', 'wp-car-manager'), 'key' => 'expiration', 'required' => false), 'sold' => array('type' => 'checkbox', 'label' => __('Sold?', 'wp-car-manager'), 'key' => 'sold', 'required' => false))));
}
示例7: column_data
/**
* Custom column data
*
* @param string $column
*/
public function column_data($column)
{
global $post;
/** @var \Never5\WPCarManager\Vehicle\Vehicle $vehicle */
$vehicle = wp_car_manager()->service('vehicle_factory')->make($post->ID);
// val
$val = '';
// set correct column val
switch ($column) {
case 'image':
// title
$title = get_the_title($vehicle->get_id());
// check if there's a thumbnail
if (has_post_thumbnail($vehicle->get_id())) {
// get image
$val = get_the_post_thumbnail($vehicle->get_id(), apply_filters('wpcm_listings_vehicle_thumbnail_size', 'wpcm_vehicle_listings_item'), array('title' => $title, 'alt' => $title, 'class' => 'wpcm-admin-image'));
} else {
$placeholder = apply_filters('wpcm_listings_vehicle_thumbnail_placeholder', wp_car_manager()->service('file')->image_url('placeholder-list.png'), $vehicle);
$val = sprintf('<img src="%s" alt="%s" class="wpcm-admin-image" />', $placeholder, __('Placeholder', 'wp-car-manager'));
}
$val = '<a href="' . admin_url(sprintf('post.php?post=%d&action=edit', $post->ID)) . '">' . $val . '</a>';
break;
case 'make':
$val = $vehicle->get_make_name();
break;
case 'model':
$val = $vehicle->get_model_name();
break;
case 'price':
$val = $vehicle->get_formatted_price();
break;
case 'mileage':
$val = $vehicle->get_formatted_mileage();
break;
case 'frdate':
$val = $vehicle->get_formatted_frdate();
break;
case 'expires':
$expiration = $vehicle->get_expiration();
if (null != $expiration) {
$val = $expiration->format(str_ireplace('F', 'M', get_option('date_format')));
}
break;
case 'actions':
if ('pending' == $vehicle->get_status()) {
$val = '<a href="' . add_query_arg(array('wpcm_action' => 'approve', 'wpcm_action_val' => $post->ID, 'wpcm_nonce' => wp_create_nonce('wpcm_action_approve_' . $post->ID)), admin_url('edit.php?post_type=wpcm_vehicle')) . '" class="button wpcm-btn-approve"></a>';
}
break;
}
// if val is empty set to -
if ('' == $val) {
$val = '-';
}
// echo val
echo $val;
}
示例8: meta_box_output
/**
* Actual meta box output
*
* @param \WP_Post $post
*/
public function meta_box_output($post)
{
// nonce
$this->output_nonce();
// get attachments
$product_image_gallery = '';
if (metadata_exists('post', $post->ID, '_car_gallery')) {
$product_image_gallery = get_post_meta($post->ID, '_car_gallery', true);
}
// explode and filter
$attachments = array_filter(explode(',', $product_image_gallery));
// view
wp_car_manager()->service('view_manager')->display('meta-box/gallery', array('car_gallery' => $product_image_gallery, 'attachments' => $attachments));
}
示例9: output
/**
* @param array $atts
*
* @return string
*/
public function output($atts)
{
// get attributes, defaults filterable via 'wpcm_shortcode_cars_defaults' filter
$atts = shortcode_atts(apply_filters('wpcm_shortcode_' . $this->get_tag() . '_defaults', array('per_page' => -1, 'orderby' => 'date', 'order' => 'DESC')), $atts);
// start output buffer
ob_start();
// global $wp_query;
// echo '<pre>';
// print_r($wp_query->query_vars);
// echo '</pre>';
// load template
wp_car_manager()->service('template_manager')->get_template_part('listings-vehicle', '', array('atts' => $atts));
return ob_get_clean();
}
示例10: can_edit_listing
/**
* Check if current user is allowed to edit given listing
*
* @param int $listing_id
*
* @return bool
*/
public function can_edit_listing($listing_id)
{
$can_edit = true;
// deny access if user is not logged in or the listing id equals zero
if (!is_user_logged_in() || 0 == $listing_id) {
$can_edit = false;
} else {
/** @var Vehicle\Vehicle $listing */
$listing = wp_car_manager()->service('vehicle_factory')->make($listing_id);
// check if listing author is equal to currently logged in user and if user has permission to edit listing
if ($listing->get_author() != get_current_user_id() && !current_user_can('edit_car_listing', $listing->get_id())) {
$can_edit = false;
}
}
return apply_filters('wpcm_user_can_edit_listing', $can_edit, $listing_id);
}
示例11: run
/**
* Installation actions
*/
public static function run()
{
// register post type and custom taxonomies
Vehicle\PostType::register();
WPCarManager\Taxonomies::register_model_make();
WPCarManager\Taxonomies::register_features();
// setup user roles
$role_manager = new WPCarManager\RoleManager();
$role_manager->setup_roles();
// setup cron
$cron = new Vehicle\Cron();
$cron->schedule();
// flush rules after install
flush_rewrite_rules();
// set version
update_option(Upgrade::OPTION_CURRENT_VERSION, wp_car_manager()->get_version());
}
示例12: output
/**
* @param array $atts
*
* @return string
*/
public function output($atts)
{
// JS
WPCarManager\Assets::enqueue_shortcode_dashboard();
// get attributes, defaults filterable via 'wpcm_shortcode_dashboard_defaults' filter
$atts = shortcode_atts(apply_filters('wpcm_shortcode_' . $this->get_tag() . '_defaults', array('orderby' => 'date', 'order' => 'DESC')), $atts);
// start output buffer
ob_start();
if (is_user_logged_in()) {
// load dashboard template
wp_car_manager()->service('template_manager')->get_template_part('dashboard', '', array('atts' => $atts));
} else {
// load not logged in template
wp_car_manager()->service('template_manager')->get_template_part('dashboard/not-logged-in', '', array('atts' => $atts));
}
return ob_get_clean();
}
示例13: run
/**
* AJAX callback method
*
* @return void
*/
public function run()
{
// check nonce
$this->check_nonce();
// set sort
$sort = isset($_GET['sort']) ? esc_attr($_GET['sort']) : 'price-desc';
// get vehicles
$vehicle_manager = new Vehicle\Manager();
$vehicles = $vehicle_manager->get_vehicles(array(), $sort, -1, array('author' => get_current_user_id(), 'post_status' => apply_filters('wpcm_dashboard_post_status', array('publish', 'expired', 'pending'))));
// check & loop
if (count($vehicles) > 0) {
// Today
$today = new \DateTime();
$today->setTime(0, 0, 0);
foreach ($vehicles as $vehicle) {
// title
$title = get_the_title($vehicle->get_id());
// check if there's a thumbnail
if (has_post_thumbnail($vehicle->get_id())) {
// get image
$image = get_the_post_thumbnail($vehicle->get_id(), apply_filters('wpcm_dashboard_vehicle_thumbnail_size', 'wpcm_vehicle_listings_item'), array('title' => $title, 'alt' => $title, 'class' => 'wpcm-dashboard-item-image'));
} else {
$placeholder = apply_filters('wpcm_dashboard_vehicle_thumbnail_placeholder', wp_car_manager()->service('file')->image_url('placeholder-list.png'), $vehicle);
$image = sprintf('<img src="%s" alt="%s" class="wpcm-dashboard-item-image" />', $placeholder, __('Placeholder', 'wp-car-manager'));
}
$expires = 'n/a';
if (null != $vehicle->get_expiration()) {
if ($today > $vehicle->get_expiration()) {
$expires = __('Expired', 'wp-car-manager');
} else {
$expires = $vehicle->get_expiration()->format('d-m-Y');
}
}
// load template
wp_car_manager()->service('template_manager')->get_template_part('dashboard/item', '', array('id' => $vehicle->get_id(), 'url' => $vehicle->get_url(), 'title' => $title, 'image' => $image, 'price' => $vehicle->get_formatted_price(), 'mileage' => $vehicle->get_formatted_mileage(), 'frdate' => $vehicle->get_formatted_frdate(), 'expires' => $expires, 'vehicle' => $vehicle));
}
} else {
wp_car_manager()->service('template_manager')->get_template_part('dashboard/no-results', '', array());
}
// bye
exit;
}
示例14: get_price_format
/**
* Get price format
*
* @return String
*/
public static function get_price_format()
{
$currency_pos = wp_car_manager()->service('settings')->get_option('currency_pos');
$format = '%1$s%2$s';
switch ($currency_pos) {
case 'left':
$format = '%1$s%2$s';
break;
case 'right':
$format = '%2$s%1$s';
break;
case 'left_space':
$format = '%1$s %2$s';
break;
case 'right_space':
$format = '%2$s %1$s';
break;
}
return $format;
}
示例15: run
/**
* AJAX callback method
*
* @return void
*/
public function run()
{
// vehicle must be set
if (!isset($_POST['vehicle']) || empty($_POST['vehicle'])) {
wp_send_json(array('success' => false));
}
// check nonce
$this->check_nonce();
// sanitize variables
$vehicle_id = absint($_POST['vehicle']);
// check if user is allowed to edit this vehicle
if (!wp_car_manager()->service('user_manager')->can_edit_listing($vehicle_id)) {
wp_send_json(array('success' => false));
}
// delete vehicle
wp_trash_post($vehicle_id);
// done
wp_send_json(array('success' => true));
// bye
exit;
}