/**
  * @param int $id
  *
  * @throws \Exception
  *
  * @return \stdClass();
  */
 public function retrieve($id)
 {
     $post = get_post($id);
     if (null === $post) {
         throw new \Exception('Vehicle not found');
     }
     $data = new \stdClass();
     $pm_prefix = 'wpcm_';
     $data->id = $post->ID;
     $data->short_description = $post->post_excerpt;
     $data->condition = get_post_meta($post->ID, $pm_prefix . 'condition', true);
     $data->make = get_post_meta($post->ID, $pm_prefix . 'make', true);
     $data->model = get_post_meta($post->ID, $pm_prefix . 'model', true);
     $data->frdate = new \DateTime(get_post_meta($post->ID, $pm_prefix . 'frdate', true));
     $data->price = get_post_meta($post->ID, $pm_prefix . 'price', true);
     $data->color = get_post_meta($post->ID, $pm_prefix . 'color', true);
     $data->mileage = get_post_meta($post->ID, $pm_prefix . 'mileage', true);
     $data->fuel_type = get_post_meta($post->ID, $pm_prefix . 'fuel_type', true);
     $data->transmission = get_post_meta($post->ID, $pm_prefix . 'transmission', true);
     $data->engine = get_post_meta($post->ID, $pm_prefix . 'engine', true);
     $data->body_style = get_post_meta($post->ID, $pm_prefix . 'body_style', true);
     $data->doors = get_post_meta($post->ID, $pm_prefix . 'doors', true);
     $data->features = wp_get_post_terms($post->ID, Taxonomies::FEATURES, array('fields' => 'names'));
     // get product gallery
     $product_image_gallery = '';
     if (metadata_exists('post', $post->ID, '_car_gallery')) {
         $product_image_gallery = get_post_meta($post->ID, '_car_gallery', true);
     }
     // set attachments ids
     $data->gallery_attachment_ids = array_filter(explode(',', $product_image_gallery));
     return $data;
 }
function bogo_update_user_option($user_id)
{
    global $wpdb;
    $meta_key = $wpdb->get_blog_prefix() . 'accessible_locale';
    if (!empty($_POST['setting_bogo_accessible_locales'])) {
        delete_user_meta($user_id, $meta_key);
        if (isset($_POST['bogo_accessible_locales'])) {
            $locales = (array) $_POST['bogo_accessible_locales'];
            $locales = bogo_filter_locales($locales);
            foreach ($locales as $locale) {
                add_user_meta($user_id, $meta_key, $locale);
            }
        }
        if (!metadata_exists('user', $user_id, $meta_key)) {
            add_user_meta($user_id, $meta_key, 'zxx');
            // zxx is a special code in ISO 639-2
        }
    }
    if (isset($_POST['bogo_own_locale'])) {
        $locale = trim($_POST['bogo_own_locale']);
        if (bogo_is_available_locale($locale)) {
            update_user_option($user_id, 'locale', $locale, true);
        }
    }
}
Example #3
0
 public function getValue($postID = null)
 {
     $value = false;
     if (empty($this->settings['id'])) {
         return $value;
     }
     if ($this->type == self::TYPE_ADMIN) {
         $value = $this->getFramework()->getInternalAdminPageOption($this->settings['id'], $this->settings['default']);
     } else {
         if ($this->type == self::TYPE_META) {
             if (empty($postID)) {
                 $postID = $this->owner->postID;
             }
             // If no $postID is given, try and get it if we are in a loop.
             if (empty($postID) && !is_admin() && get_post() != null) {
                 $postID = get_the_ID();
             }
             // for meta options, use the default value for new posts/pages
             if (metadata_exists('post', $postID, $this->getID())) {
                 $value = get_post_meta($postID, $this->getID(), true);
             } else {
                 $value = $this->settings['default'];
             }
         } else {
             if ($this->type == self::TYPE_CUSTOMIZER) {
                 $value = get_theme_mod($this->getID(), $this->settings['default']);
             }
         }
     }
     // Apply cleaning method for the value (for serialized data, slashes, etc).
     $value = $this->cleanValueForGetting($value);
     return apply_filters('tf_get_value_' . $this->settings['type'] . '_' . $this->getOptionNamespace(), $value, $postID, $this);
 }
 public function __construct($post = null)
 {
     if (!empty($post) && ($post = get_post($post))) {
         $this->id = $post->ID;
         $this->date = get_the_time(__('Y/m/d g:i:s A', 'flamingo'), $this->id);
         $this->subject = get_post_meta($post->ID, '_subject', true);
         $this->from = get_post_meta($post->ID, '_from', true);
         $this->from_name = get_post_meta($post->ID, '_from_name', true);
         $this->from_email = get_post_meta($post->ID, '_from_email', true);
         $this->fields = get_post_meta($post->ID, '_fields', true);
         foreach ($this->fields as $key => $value) {
             $meta_key = sanitize_key('_field_' . $key);
             if (metadata_exists('post', $post->ID, $meta_key)) {
                 $value = get_post_meta($post->ID, $meta_key, true);
                 $this->fields[$key] = $value;
             }
         }
         $this->meta = get_post_meta($post->ID, '_meta', true);
         $this->akismet = get_post_meta($post->ID, '_akismet', true);
         $terms = wp_get_object_terms($this->id, self::channel_taxonomy);
         if (!empty($terms) && !is_wp_error($terms)) {
             $this->channel = $terms[0]->slug;
         }
         if (self::spam_status == get_post_status($post)) {
             $this->spam = true;
         } else {
             $this->spam = !empty($this->akismet['spam']);
         }
     }
 }
 public function __construct($post = null)
 {
     $this->initial = true;
     $this->form = '';
     $this->mail = array();
     $this->mail_2 = array();
     $this->messages = array();
     $this->additional_settings = '';
     $post = get_post($post);
     if ($post && self::post_type == get_post_type($post)) {
         $this->initial = false;
         $this->id = $post->ID;
         $this->title = $post->post_title;
         $props = $this->get_properties();
         foreach ($props as $prop => $value) {
             if (metadata_exists('post', $post->ID, '_' . $prop)) {
                 $this->{$prop} = get_post_meta($post->ID, '_' . $prop, true);
             } else {
                 $this->{$prop} = get_post_meta($post->ID, $prop, true);
             }
         }
         $this->upgrade();
     }
     do_action_ref_array('wpcf7_contact_form', array(&$this));
 }
/**
 * Update a product's stock amount.
 *
 * @param  int $product_id
 * @param  int $new_stock_level
 */
function wc_update_product_stock($product_id, $new_stock_level)
{
    $product = wc_get_product($product_id);
    if (!metadata_exists('post', $product_id, '_stock') || $product->get_stock_quantity() !== $new_stock_level) {
        $product->set_stock($new_stock_level);
    }
}
 /**
  * __isset function.
  *
  * @access public
  * @param mixed $key
  * @return bool
  */
 public function __isset($key)
 {
     if (!$this->id) {
         return false;
     }
     return metadata_exists('post', $this->id, '_' . $key);
 }
 /**
  * Read from the database.
  * @since 2.7.0
  * @param int $id ID of object to read.
  */
 public function read($id)
 {
     parent::read($id);
     if (!$this->get_id()) {
         return;
     }
     $post_object = get_post($id);
     $this->set_props(array('amount' => get_post_meta($this->get_id(), '_refund_amount', true), 'refunded_by' => metadata_exists('post', $this->get_id(), '_refunded_by') ? get_post_meta($this->get_id(), '_refunded_by', true) : absint($post_object->post_author), 'reason' => metadata_exists('post', $this->get_id(), '_refund_reason') ? get_post_meta($this->get_id(), '_refund_reason', true) : $post_object->post_excerpt));
 }
    /**
     * Output the metabox
     */
    public static function output($post)
    {
        ?>
		<div id="wps_deals_images_container">
			<ul class="wps_deals_images">
				<?php 
        $prefix = WPS_DEALS_META_PREFIX;
        if (metadata_exists('post', $post->ID, $prefix . 'image_gallery')) {
            $wps_deals_image_gallery = get_post_meta($post->ID, $prefix . 'image_gallery', true);
        } else {
            // Backwards compat
            $attachment_ids = get_posts('post_parent=' . $post->ID . '&numberposts=-1&post_type=attachment&orderby=menu_order&order=ASC&post_mime_type=image&fields=ids&meta_key=_deals_exclude_image&meta_value=0');
            $attachment_ids = array_diff($attachment_ids, array(get_post_thumbnail_id()));
            $wps_deals_image_gallery = implode(',', $attachment_ids);
        }
        $attachments = array_filter(explode(',', $wps_deals_image_gallery));
        if (!empty($attachments)) {
            foreach ($attachments as $attachment_id) {
                echo '<li class="image" data-attachment_id="' . esc_attr($attachment_id) . '">
								' . wp_get_attachment_image($attachment_id, 'thumbnail') . '
								<ul class="actions">
									<li><a href="#" class="delete tips" data-tip="' . esc_attr__('Delete image', 'wpsdeals') . '">' . __('Delete', 'wpsdeals') . '</a></li>
								</ul>
							</li>';
            }
        }
        ?>
			</ul>

			<input type="hidden" id="wps_deals_image_gallery" name="wps_deals_image_gallery" value="<?php 
        echo esc_attr($wps_deals_image_gallery);
        ?>
" />

		</div>
		<p class="add_wps_deals_images hide-if-no-js">
			<a href="#" data-choose="<?php 
        esc_attr_e('Add Images to Deals Gallery', 'wpsdeals');
        ?>
" data-update="<?php 
        esc_attr_e('Add to gallery', 'wpsdeals');
        ?>
" data-delete="<?php 
        esc_attr_e('Delete image', 'wpsdeals');
        ?>
" data-text="<?php 
        esc_attr_e('Delete', 'wpsdeals');
        ?>
"><?php 
        _e('Add Deals gallery images', 'wpsdeals');
        ?>
</a>
		</p>
		<?php 
    }
/**
 * Add `VATNumber` tag data
 *
 * this function searches for a VAT number order meta key used by the more
 * popular Tax/VAT plugins
 *
 * @param \WC_Order $order the order object
 * @return string - the VAT data to print
 */
function sv_wc_xml_export_vat_number_data($order)
{
    $vat_number = '';
    // find VAT number if one exists for the order
    $vat_number_meta_keys = array('_vat_number', 'VAT Number', 'vat_number', '_billing_wc_avatax_vat_id');
    foreach ($vat_number_meta_keys as $meta_key) {
        if (metadata_exists('post', $order->id, $meta_key)) {
            return get_post_meta($order->id, $meta_key, true);
        }
    }
    return $vat_number;
}
function vantage_metaslider_page_setting_metabox_render($post)
{
    $metaslider = get_post_meta($post->ID, 'vantage_metaslider_slider', true);
    $is_home = $post->ID == get_option('page_on_front');
    // If we're on the home page and the user hasn't explicitly set something here use the 'home_slider' theme setting.
    if ($is_home && empty($metaslider)) {
        $metaslider = siteorigin_setting('home_slider');
    }
    // Default stretch setting to theme setting.
    $metaslider_stretch = siteorigin_setting('home_slider_stretch');
    //Include the demo slider in the options if it's the home page.
    $options = siteorigin_metaslider_get_options($is_home);
    if (metadata_exists('post', $post->ID, 'vantage_metaslider_slider_stretch')) {
        $metaslider_stretch = get_post_meta($post->ID, 'vantage_metaslider_slider_stretch', true);
    }
    ?>
	<label><strong><?php 
    _e('Display Page Meta Slider', 'vantage');
    ?>
</strong></label>
	<p>
		<select name="vantage_page_metaslider">
			<?php 
    foreach ($options as $id => $name) {
        ?>
				<option value="<?php 
        echo esc_attr($id);
        ?>
" <?php 
        selected($metaslider, $id);
        ?>
><?php 
        echo esc_html($name);
        ?>
</option>
			<?php 
    }
    ?>
		</select>
	</p>
	<p class="checkbox-wrapper">
		<input id="vantage_page_metaslider_stretch" name="vantage_page_metaslider_stretch" type="checkbox" <?php 
    checked($metaslider_stretch);
    ?>
 />
		<label for="vantage_page_metaslider_stretch"><?php 
    _e('Stretch Page Meta Slider', 'vantage');
    ?>
</label>
	</p>
	<?php 
    wp_nonce_field('save', '_vantage_metaslider_nonce');
}
 /**
  * Read from the database.
  * @since 2.7.0
  * @param int $id ID of object to read.
  */
 public function read($id)
 {
     parent::read($id);
     // Read additonal order data
     if ($this->get_id()) {
         $post_object = get_post($id);
         $this->set_amount(get_post_meta($this->get_id(), '_refund_amount', true));
         // post_author was used before refunded_by meta.
         $this->set_refunded_by(metadata_exists('post', $this->get_id(), '_refunded_by') ? get_post_meta($this->get_id(), '_refunded_by', true) : absint($post_object->post_author));
         // post_excerpt was used before refund_reason meta.
         $this->set_reason(metadata_exists('post', $this->get_id(), '_refund_reason') ? get_post_meta($this->get_id(), '_refund_reason', true) : absint($post_object->post_excerpt));
     }
 }
    /**
     * Output the metabox
     */
    public function gallery_output($post)
    {
        ?>
		<div id="recipe_images_container">
			<ul class="recipe_images">
				<?php 
        if (metadata_exists('post', $post->ID, '_recipe_image_gallery')) {
            $recipe_image_gallery = get_post_meta($post->ID, '_recipe_image_gallery', true);
        } else {
            $recipe_image_gallery = '';
        }
        $attachments = array_filter(explode(',', $recipe_image_gallery));
        if ($attachments) {
            foreach ($attachments as $attachment_id) {
                echo '<li class="image" data-attachment_id="' . esc_attr($attachment_id) . '">
								' . wp_get_attachment_image($attachment_id, 'thumbnail') . '
								<ul class="actions">
									<li><a href="#" class="delete tips" data-tip="' . __('Delete image', 'recipe-hero') . '">' . __('Delete', 'recipe-hero') . '</a></li>
								</ul>
							</li>';
            }
        }
        ?>
			</ul>

			<input type="hidden" id="recipe_image_gallery" name="recipe_image_gallery" value="<?php 
        echo esc_attr($recipe_image_gallery);
        ?>
" />

		</div>
		<p class="add_recipe_images hide-if-no-js">
			<a href="#" data-choose="<?php 
        _e('Add Images to Recipe Gallery', 'recipe-hero');
        ?>
" data-update="<?php 
        _e('Add to gallery', 'recipe-hero');
        ?>
" data-delete="<?php 
        _e('Delete image', 'recipe-hero');
        ?>
" data-text="<?php 
        _e('Delete', 'recipe-hero');
        ?>
"><?php 
        _e('Add recipe gallery images', 'recipe-hero');
        ?>
</a>
		</p>
		<?php 
    }
Example #14
0
 /**
  * Loads post's meta fields.
  */
 function fetch_post_meta()
 {
     if (false == $this->meta_data_loaded) {
         $this->meta_data_loaded = true;
         foreach ($this->meta_data_defaults as $key => $value) {
             if (metadata_exists('post', $this->post_id, $this->META_PREFIX . $key)) {
                 $this->meta_data[$key] = get_post_meta($this->post_id, $this->META_PREFIX . $key, true);
             } else {
                 $this->meta_data[$key] = $this->meta_data_defaults[$key];
             }
         }
     }
     return $this;
 }
 /**
  * job_listing_fields function.
  *
  * @access public
  * @return void
  */
 public function job_listing_fields()
 {
     global $post;
     $current_user = wp_get_current_user();
     $fields = array('_job_location' => array('label' => __('Location', 'wp-job-manager'), 'placeholder' => __('e.g. "London"', 'wp-job-manager'), 'description' => __('Leave this blank if the location is not important', 'wp-job-manager')), '_application' => array('label' => __('Application email/URL', 'wp-job-manager'), 'placeholder' => __('URL or email which applicants use to apply', 'wp-job-manager'), 'description' => __('This field is required for the "application" area to appear beneath the listing.', 'wp-job-manager'), 'value' => metadata_exists('post', $post->ID, '_application') ? get_post_meta($post->ID, '_application', true) : $current_user->user_email), '_company_name' => array('label' => __('Company name', 'wp-job-manager'), 'placeholder' => ''), '_company_website' => array('label' => __('Company website', 'wp-job-manager'), 'placeholder' => ''), '_company_tagline' => array('label' => __('Company tagline', 'wp-job-manager'), 'placeholder' => __('Brief description about the company', 'wp-job-manager')), '_company_twitter' => array('label' => __('Company Twitter', 'wp-job-manager'), 'placeholder' => '@yourcompany'), '_company_logo' => array('label' => __('Company logo', 'wp-job-manager'), 'placeholder' => __('URL to the company logo', 'wp-job-manager'), 'type' => 'file'), '_company_video' => array('label' => __('Company video', 'wp-job-manager'), 'placeholder' => __('URL to the company video', 'wp-job-manager'), 'type' => 'file'), '_filled' => array('label' => __('Position filled?', 'wp-job-manager'), 'type' => 'checkbox'));
     if ($current_user->has_cap('manage_job_listings')) {
         $fields['_featured'] = array('label' => __('Feature this listing?', 'wp-job-manager'), 'type' => 'checkbox', 'description' => __('Featured listings will be sticky during searches, and can be styled differently.', 'wp-job-manager'));
         $fields['_job_expires'] = array('label' => __('Expires', 'wp-job-manager'), 'placeholder' => __('yyyy-mm-dd', 'wp-job-manager'));
     }
     if ($current_user->has_cap('edit_others_job_listings')) {
         $fields['_job_author'] = array('label' => __('Posted by', 'wp-job-manager'), 'type' => 'author');
     }
     return apply_filters('job_manager_job_listing_data_fields', $fields);
 }
Example #16
0
 /**
  * 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));
 }
function bogo_update_nav_menu_item($menu_id, $menu_item_id)
{
    delete_post_meta($menu_item_id, '_locale');
    if (isset($_POST['menu-item-bogo-locale'][$menu_item_id])) {
        $locales = (array) $_POST['menu-item-bogo-locale'][$menu_item_id];
        $locales = bogo_filter_locales($locales);
        foreach ($locales as $locale) {
            add_post_meta($menu_item_id, '_locale', $locale);
        }
    }
    if (!metadata_exists('post', $menu_item_id, '_locale')) {
        add_post_meta($menu_item_id, '_locale', 'zxx');
        // special code in ISO 639-2
    }
}
	 */
    public function __construct()
    {
        add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
        add_action('save_post', array($this, 'save_post'), 1, 2);
        add_action('event_manager_save_event_listing', array($this, 'save_event_listing_data'), 20, 2);
    }
    /**
	 * event_listing_fields function.
	 *
	 * @access public
	 * @return void
	 */
    public function event_listing_fields()
    {
        global $post;
        $current_user = wp_get_current_user();
 /**
  * job_listing_fields function.
  *
  * @access public
  * @return void
  */
 public function job_listing_fields()
 {
     global $post;
     $current_user = wp_get_current_user();
     $fields = array('_job_location' => array('label' => __('Location', 'wp-job-manager'), 'placeholder' => __('e.g. "London"', 'wp-job-manager'), 'description' => __('Leave this blank if the location is not important.', 'wp-job-manager'), 'priority' => 1), '_application' => array('label' => __('Application Email or URL', 'wp-job-manager'), 'placeholder' => __('URL or email which applicants use to apply', 'wp-job-manager'), 'description' => __('This field is required for the "application" area to appear beneath the listing.', 'wp-job-manager'), 'value' => metadata_exists('post', $post->ID, '_application') ? get_post_meta($post->ID, '_application', true) : $current_user->user_email, 'priority' => 2), '_company_name' => array('label' => __('Company Name', 'wp-job-manager'), 'placeholder' => '', 'priority' => 3), '_company_website' => array('label' => __('Company Website', 'wp-job-manager'), 'placeholder' => '', 'priority' => 4), '_company_tagline' => array('label' => __('Company Tagline', 'wp-job-manager'), 'placeholder' => __('Brief description about the company', 'wp-job-manager'), 'priority' => 5), '_company_twitter' => array('label' => __('Company Twitter', 'wp-job-manager'), 'placeholder' => '@yourcompany', 'priority' => 6), '_company_logo' => array('label' => __('Company Logo', 'wp-job-manager'), 'placeholder' => __('URL to the company logo', 'wp-job-manager'), 'type' => 'file', 'priority' => 7), '_company_video' => array('label' => __('Company Video', 'wp-job-manager'), 'placeholder' => __('URL to the company video', 'wp-job-manager'), 'type' => 'file', 'priority' => 8), '_filled' => array('label' => __('Position Filled', 'wp-job-manager'), 'type' => 'checkbox', 'priority' => 9, 'description' => __('Filled listings will no longer accept applications.', 'wp-job-manager')));
     if ($current_user->has_cap('manage_job_listings')) {
         $fields['_featured'] = array('label' => __('Featured Listing', 'wp-job-manager'), 'type' => 'checkbox', 'description' => __('Featured listings will be sticky during searches, and can be styled differently.', 'wp-job-manager'), 'priority' => 10);
         $fields['_job_expires'] = array('label' => __('Listing Expiry Date', 'wp-job-manager'), 'placeholder' => __('yyyy-mm-dd', 'wp-job-manager'), 'priority' => 11, 'value' => metadata_exists('post', $post->ID, '_job_expires') ? get_post_meta($post->ID, '_job_expires', true) : calculate_job_expiry($post->ID));
     }
     if ($current_user->has_cap('edit_others_job_listings')) {
         $fields['_job_author'] = array('label' => __('Posted by', 'wp-job-manager'), 'type' => 'author', 'priority' => 12);
     }
     $fields = apply_filters('job_manager_job_listing_data_fields', $fields);
     uasort($fields, array($this, 'sort_by_priority'));
     return $fields;
 }
 /**
  * @param int $id
  *
  * @throws \Exception
  *
  * @return \stdClass();
  */
 public function retrieve($id)
 {
     $post = get_post($id);
     if (null === $post) {
         throw new \Exception('Vehicle not found');
     }
     $data = new \stdClass();
     $pm_prefix = 'wpcm_';
     $data->id = $post->ID;
     $data->status = $post->post_status;
     $data->title = $post->post_title;
     $data->author = $post->post_author;
     $data->expiration = false != get_post_meta($post->ID, $pm_prefix . 'expiration', true) ? new \DateTime(get_post_meta($post->ID, $pm_prefix . 'expiration', true)) : null;
     $data->description = $post->post_content;
     // @todo check if we need to apply filters here
     $data->short_description = wp_trim_words(!empty($post->post_excerpt) ? $post->post_excerpt : $post->post_content, absint(apply_filters('wpcm_vehicle_short_description_length', 30)));
     $data->condition = get_post_meta($post->ID, $pm_prefix . 'condition', true);
     $data->make = get_post_meta($post->ID, $pm_prefix . 'make', true);
     $data->model = get_post_meta($post->ID, $pm_prefix . 'model', true);
     $data->price = get_post_meta($post->ID, $pm_prefix . 'price', true);
     $data->color = get_post_meta($post->ID, $pm_prefix . 'color', true);
     $data->mileage = get_post_meta($post->ID, $pm_prefix . 'mileage', true);
     $data->fuel_type = get_post_meta($post->ID, $pm_prefix . 'fuel_type', true);
     $data->transmission = get_post_meta($post->ID, $pm_prefix . 'transmission', true);
     $data->engine = get_post_meta($post->ID, $pm_prefix . 'engine', true);
     $data->power_hp = get_post_meta($post->ID, $pm_prefix . 'power_hp', true);
     $data->power_kw = get_post_meta($post->ID, $pm_prefix . 'power_kw', true);
     $data->body_style = get_post_meta($post->ID, $pm_prefix . 'body_style', true);
     $data->doors = get_post_meta($post->ID, $pm_prefix . 'doors', true);
     $data->sold = get_post_meta($post->ID, $pm_prefix . 'sold', true);
     // wrap frdate in try-catch in case someone enters an incorrect date
     try {
         $data->frdate = new \DateTime(get_post_meta($post->ID, $pm_prefix . 'frdate', true));
     } catch (\Exception $e) {
         $data->frdate = '';
     }
     // get and format features
     $data->features = $this->get_formatted_features($post->ID);
     // get product gallery
     $product_image_gallery = '';
     if (metadata_exists('post', $post->ID, '_car_gallery')) {
         $product_image_gallery = get_post_meta($post->ID, '_car_gallery', true);
     }
     // set attachments ids
     $data->gallery_attachment_ids = array_filter(explode(',', $product_image_gallery));
     return $data;
 }
 /**
  * Helper method that updates all the post meta for an order based on it's settings in the WC_Order class.
  *
  * @param WC_Order
  * @param bool $force Force all props to be written even if not changed. This is used during creation.
  * @since 2.7.0
  */
 protected function update_post_meta(&$order, $force = false)
 {
     $updated_props = array();
     $changed_props = $order->get_changes();
     $meta_key_to_props = array('_order_key' => 'order_key', '_customer_user' => 'customer_id', '_payment_method' => 'payment_method', '_payment_method_title' => 'payment_method_title', '_transaction_id' => 'transaction_id', '_customer_ip_address' => 'customer_ip_address', '_customer_user_agent' => 'customer_user_agent', '_created_via' => 'created_via', '_completed_date' => 'date_completed', '_paid_date' => 'date_paid', '_cart_hash' => 'cart_hash');
     foreach ($meta_key_to_props as $meta_key => $prop) {
         if (!array_key_exists($prop, $changed_props) && !$force) {
             continue;
         }
         $value = $order->{"get_{$prop}"}('edit');
         if ('' !== $value ? update_post_meta($order->get_id(), $meta_key, $value) : delete_post_meta($order->get_id(), $meta_key)) {
             $updated_props[] = $prop;
         }
     }
     $address_props = array('billing' => array('_billing_first_name' => 'billing_first_name', '_billing_last_name' => 'billing_last_name', '_billing_company' => 'billing_company', '_billing_address_1' => 'billing_address_1', '_billing_address_2' => 'billing_address_2', '_billing_city' => 'billing_city', '_billing_state' => 'billing_state', '_billing_postcode' => 'billing_postcode', '_billing_country' => 'billing_country', '_billing_email' => 'billing_email', '_billing_phone' => 'billing_phone'), 'shipping' => array('_shipping_first_name' => 'shipping_first_name', '_shipping_last_name' => 'shipping_last_name', '_shipping_company' => 'shipping_company', '_shipping_address_1' => 'shipping_address_1', '_shipping_address_2' => 'shipping_address_2', '_shipping_city' => 'shipping_city', '_shipping_state' => 'shipping_state', '_shipping_postcode' => 'shipping_postcode', '_shipping_country' => 'shipping_country'));
     foreach ($address_props as $props_key => $props) {
         foreach ($props as $meta_key => $prop) {
             $prop_key = substr($prop, 8);
             if (!$force && (!isset($changed_props[$props_key]) || !array_key_exists($prop_key, $changed_props[$props_key]))) {
                 continue;
             }
             $value = $order->{"get_{$prop}"}('edit');
             if ('' !== $value ? update_post_meta($order->get_id(), $meta_key, $value) : delete_post_meta($order->get_id(), $meta_key)) {
                 $updated_props[] = $prop;
                 $updated_props[] = $props_key;
             }
         }
     }
     parent::update_post_meta($order, $force);
     // If address changed, store concatinated version to make searches faster.
     if (in_array('billing', $updated_props) || !metadata_exists('post', $order->get_id(), '_billing_address_index')) {
         update_post_meta($order->get_id(), '_billing_address_index', implode(' ', $order->get_address('billing')));
     }
     if (in_array('shipping', $updated_props) || !metadata_exists('post', $order->get_id(), '_shipping_address_index')) {
         update_post_meta($order->get_id(), '_shipping_address_index', implode(' ', $order->get_address('shipping')));
     }
     // If customer changed, update any downloadable permissions.
     if (in_array('customer_user', $updated_props) || in_array('billing_email', $updated_props)) {
         $data_store = WC_Data_Store::load('customer-download');
         $data_store->update_user_by_order_id($order->get_id(), $order->get_customer_id(), $order->get_billing_email());
     }
 }
Example #22
0
 /**
  * Handle variation duplicate
  *
  * @return boolean false if the from product contains no variatoins
  */
 public function duplicate()
 {
     $fromVariation = $this->from->get_available_variations();
     if (empty($fromVariation)) {
         return false;
     }
     if ($this->to->id === $this->from->id) {
         /*
          * In such a case just add the duplicate meta key
          */
         foreach ($fromVariation as $variation) {
             if (!metadata_exists('post', $variation['variation_id'], self::DUPLICATE_KEY)) {
                 update_post_meta($variation['variation_id'], self::DUPLICATE_KEY, $variation['variation_id']);
             }
         }
     } else {
         /* This could be a very long operation */
         set_time_limit(0);
         foreach ($fromVariation as $variation) {
             /*
              * First we check if the "to" product contains the duplicate meta
              * key to find out if we have to update or insert
              */
             $posts = get_posts(array('meta_key' => self::DUPLICATE_KEY, 'meta_value' => $variation['variation_id'], 'post_type' => 'product_variation', 'post_parent' => $this->to->id));
             switch (count($posts)) {
                 case 1:
                     // update
                     $this->update(wc_get_product($variation['variation_id']), $posts[0], $variation);
                     break;
                 case 0:
                     // insert
                     $this->insert(wc_get_product($variation['variation_id']), $variation);
                     break;
                 default:
                     // we can not handle, something wrong here
                     break;
             }
         }
         /* Restore original timeout */
         set_time_limit(ini_get('max_execution_time'));
     }
 }
Example #23
0
function wp_install_defaults($user_id)
{
    global $wpdb, $wp_rewrite, $current_site, $table_prefix;
    // Default category
    $cat_name = __('Uncategorized');
    /* translators: Default category slug */
    $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
    if (global_terms_enabled()) {
        $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
        if ($cat_id == null) {
            $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
            $cat_id = $wpdb->insert_id;
        }
        update_option('default_category', $cat_id);
    } else {
        $cat_id = 1;
    }
    $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
    $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
    $cat_tt_id = $wpdb->insert_id;
    if (!is_multisite()) {
        update_user_meta($user_id, 'show_welcome_panel', 1);
    } elseif (!is_super_admin($user_id) && !metadata_exists('user', $user_id, 'show_welcome_panel')) {
        update_user_meta($user_id, 'show_welcome_panel', 2);
    }
    if (is_multisite()) {
        // Flush rules to pick up the new page.
        $wp_rewrite->init();
        $wp_rewrite->flush_rules();
        $user = new WP_User($user_id);
        $wpdb->update($wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email'));
        // Remove all perms except for the login user.
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level'));
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities'));
        // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
        if (!is_super_admin($user_id) && $user_id != 1) {
            $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => $wpdb->base_prefix . '1_capabilities'));
        }
    }
    $wpdb->query("UPDATE {$wpdb->options} SET option_value = '' WHERE option_id = 3");
    $wpdb->query("UPDATE {$wpdb->options} SET option_value = '/%postname%/' WHERE option_id = 30");
}
Example #24
0
function wpcf7_prepend_underscore($new_ver, $old_ver)
{
    if (version_compare($old_ver, '3.0-dev', '<')) {
        return;
    }
    if (!version_compare($old_ver, '3.3-dev', '<')) {
        return;
    }
    $posts = WPCF7_ContactForm::find(array('post_status' => 'any', 'posts_per_page' => -1));
    foreach ($posts as $post) {
        $props = $post->get_properties();
        foreach ($props as $prop => $value) {
            if (metadata_exists('post', $post->id, '_' . $prop)) {
                continue;
            }
            update_post_meta($post->id, '_' . $prop, $value);
            delete_post_meta($post->id, $prop);
        }
    }
}
Example #25
0
 public function update_profile()
 {
     foreach ($this->profile as $key => $val) {
         if (isset($this->profile[$key])) {
             if (in_array($key, array('user_url', 'display_name'))) {
                 wp_update_user(array('ID' => $this->user_id, $key => $val));
             } else {
                 if (metadata_exists('user', $this->user_id, $key)) {
                     $result = update_user_meta($this->user_id, $key, $val, get_user_meta($this->user_id, $key, true));
                 } else {
                     $result = add_user_meta($this->user_id, $key, $val, true);
                 }
             }
         }
     }
     if (!is_wp_error($result)) {
         return true;
     } else {
         return false;
     }
 }
/**
 * Add `vat_number` column data
 *
 * this function searches for a VAT number order meta key used by the more
 * popular Tax/VAT plugins
 *
 * @param array $order_data the original column data
 * @param \WC_Order $order the order object
 * @param \WC_Customer_Order_CSV_Export_Generator $csv_generator the generator instance
 * @return array the updated column data
 */
function sv_wc_csv_export_modify_row_data_vat_number($order_data, $order, $csv_generator)
{
    $vat_number = '';
    $new_order_data = array();
    // find VAT number if one exists for the order
    $vat_number_meta_keys = array('_vat_number', 'VAT Number', 'vat_number', '_billing_wc_avatax_vat_id');
    foreach ($vat_number_meta_keys as $meta_key) {
        if (metadata_exists('post', $order->id, $meta_key)) {
            $vat_number = get_post_meta($order->id, $meta_key, true);
            break;
        }
    }
    $custom_data = array('vat_number' => $vat_number);
    if (sv_wc_csv_export_is_one_row($csv_generator)) {
        foreach ($order_data as $data) {
            $new_order_data[] = array_merge((array) $data, $custom_data);
        }
    } else {
        $new_order_data = array_merge($order_data, $custom_data);
    }
    return $new_order_data;
}
Example #27
0
function post_images_box()
{
    global $post;
    ?>
    <div id="post_images_container">
        <ul class="post_images">
            <?php 
    if (metadata_exists('post', $post->ID, '_format_gallery_images')) {
        $product_image_gallery = get_post_meta($post->ID, '_format_gallery_images', true);
    } else {
        // Backwards compat
        $attachment_ids = get_posts('post_parent=' . $post->ID . '&posts_per_page=-1&post_type=attachment&orderby=menu_order&order=ASC&post_mime_type=image&fields=ids&meta_key=_woocommerce_exclude_image&meta_value=0');
        $attachment_ids = array_diff($attachment_ids, array(get_post_thumbnail_id()));
        $product_image_gallery = implode(',', $attachment_ids);
    }
    $attachments = array_filter(explode(',', $product_image_gallery));
    if ($attachments) {
        foreach ($attachments as $attachment_id) {
            echo '<li class="image" data-attachment_id="' . $attachment_id . '">
                            ' . wp_get_attachment_image($attachment_id, 'thumbnail') . '
                            <ul class="actions">
                                <li><a href="#" class="delete" title="' . __('Delete image', 'themeton') . '">' . __('Delete', 'themeton') . '</a></li>
                            </ul>
                        </li>';
        }
    }
    ?>
        </ul>

    </div>
    <p class="add_post_images hide-if-no-js">
        <a href="#"><?php 
    _e('Add post gallery images', 'themeton');
    ?>
</a>
    </p>
    <?php 
}
 /**
  * __isset function.
  *
  * @param mixed $key
  * @return bool
  */
 public function __isset($key)
 {
     $result = isset($this->user_data->{$key});
     if (!$result) {
         if ($this->user_id > 0) {
             $result = metadata_exists('user', $this->user_id, '_' . $key);
             if (!$result) {
                 $result = metadata_exists('user', $this->user_id, $key);
             }
         } else {
             if ($this->order_id > 0) {
                 $result = metadata_exists('post', $this->order_id, '_' . $key);
                 if (!$result) {
                     $result = metadata_exists('post', $this->order_id, $key);
                 }
                 if (!$result) {
                     $result = metadata_exists('wc_crm_customer', $this->customer_id, $key);
                 }
             }
         }
     }
     return $result;
 }
if (!$sidebar_exists) {
    $content_css = 'width:100%';
    $sidebar_css = 'display:none';
    $sidebar_exists = false;
} elseif (get_post_meta($post->ID, 'pyre_sidebar_position', true) == 'left') {
    $content_css = 'float:right;';
    $sidebar_css = 'float:left;';
    $content_class = 'portfolio-one-sidebar';
    $sidebar_exists = true;
    $sidebar_left = 1;
} elseif (get_post_meta($post->ID, 'pyre_sidebar_position', true) == 'right') {
    $content_css = 'float:left;';
    $sidebar_css = 'float:right;';
    $content_class = 'portfolio-one-sidebar';
    $sidebar_exists = true;
} elseif (get_post_meta($post->ID, 'pyre_sidebar_position', true) == 'default' || !metadata_exists('post', $post->ID, 'pyre_sidebar_position')) {
    $content_class = 'portfolio-one-sidebar';
    if ($smof_data['default_sidebar_pos'] == 'Left') {
        $content_css = 'float:right;';
        $sidebar_css = 'float:left;';
        $sidebar_exists = true;
        $sidebar_left = 1;
    } elseif ($smof_data['default_sidebar_pos'] == 'Right') {
        $content_css = 'float:left;';
        $sidebar_css = 'float:right;';
        $sidebar_exists = true;
        $sidebar_left = 2;
    }
}
if (get_post_meta($post->ID, 'pyre_sidebar_position', true) == 'right') {
    $sidebar_left = 2;
 /**
  * Redirect issets to WC_Product Class
  *  
  * @param  string  $key 
  * @return boolean      
  */
 public function __isset($key)
 {
     if ($this->child->variation_id && in_array($key, array_keys($this->gzd_variation_level_meta))) {
         return metadata_exists('post', $this->child->variation_id, '_' . $key);
     } else {
         return isset($this->child->{$key});
     }
 }