Ejemplo n.º 1
0
/**
 * Custom class for the WP 'body_class()' function
 * updated: 4/15/10
 */
function dbdb_body_classes($classes)
{
    // source http://darrinb.com/notes/2010/customizing-the-wordpress-body_class-function/
    global $post;
    global $wp_query;
    // if there is no parent ID and it's not a single post page, category page, or 404 page, give it
    // a class of "parent-page"
    if ($post->post_parent < 1 && !is_single() && !is_archive() && !is_404()) {
        $classes[] = 'parent-page';
    }
    // if the page/post has a parent, it's a child, give it a class of its parent name
    if ($post->post_parent > 0) {
        /* $parent_title = get_the_title($wp_query->post->post_parent);
           $parent_title = preg_replace('#\s#','-', $parent_title);
           $parent_title = strtolower($parent_title);
           $classes[] = 'parent-pagename-'.$parent_title; */
        $parent_id = wp_get_post_parent_id($wp_query->post);
        // $parent_id = get_the_ID($wp_query->post->post_parent);
        echo "PARENT ID : " . $parent_id;
        // $parent_id = preg_replace('#\s#','-', $parent_id);
        $parent_id = strtolower($parent_id);
        $classes[] = 'parent-id-' . $parent_id;
    }
    // add a class = to the name of post or page
    $classes[] = $wp_query->queried_object->post_name;
    return array_unique($classes);
}
Ejemplo n.º 2
0
 function woocommerce_get_product_thumbnail($size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0)
 {
     global $product;
     if ($product->is_type('variable')) {
         global $prdctfltr_global;
         $pf_activated = isset($prdctfltr_global['active_filters']) ? $prdctfltr_global['active_filters'] : array();
         if (!empty($pf_activated)) {
             $attrs = array();
             foreach ($pf_activated as $k => $v) {
                 if (substr($k, 0, 3) == 'pa_') {
                     $attrs = $attrs + array($k => $v[0]);
                 }
             }
             if (count($attrs) > 0) {
                 $curr_var = $product->get_available_variations();
                 foreach ($curr_var as $key => $var) {
                     $curr_var_set[$key]['attributes'] = $var['attributes'];
                     $curr_var_set[$key]['variation_id'] = $var['variation_id'];
                 }
                 $found = WC_Prdctfltr::prdctrfltr_search_array($curr_var_set, $attrs);
             }
         }
     }
     if (isset($found[0]) && $found[0]['variation_id'] && has_post_thumbnail($found[0]['variation_id'])) {
         $image = get_the_post_thumbnail($found[0]['variation_id'], $size);
     } elseif (has_post_thumbnail($product->id)) {
         $image = get_the_post_thumbnail($product->id, $size);
     } elseif (($parent_id = wp_get_post_parent_id($product->id)) && has_post_thumbnail($parent_id)) {
         $image = get_the_post_thumbnail($product, $size);
     } else {
         $image = wc_placeholder_img($size);
     }
     return $image;
 }
Ejemplo n.º 3
0
function applegate_get_top_bucket_parent($ID)
{
    if ($parent = wp_get_post_parent_id($ID)) {
        $ID = applegate_get_top_bucket_parent($parent);
    }
    return $ID;
}
Ejemplo n.º 4
0
function getpp_replace_hierarchicals($value)
{
    $value = str_replace('this', get_the_ID(), $value);
    $value = str_replace('parent', wp_get_post_parent_id(get_the_ID()), $value);
    $value = str_replace('top', end(get_post_ancestors(get_the_ID())), $value);
    return $value;
}
 /**
  * Gets addons assigned to a product by ID
  *
  * @param  int $post_id ID of the product to get addons for
  * @param  string $prefix for addon field names. Defaults to postid-
  * @param  bool $inc_parent Set to false to not include parent product addons.
  * @param  bool $inc_global Set to false to not include global addons.
  * @return array array of addons
  */
 function get_product_addons($post_id, $prefix = false, $inc_parent = true, $inc_global = true)
 {
     if (!$post_id) {
         return array();
     }
     $addons = array();
     $raw_addons = array();
     $product_terms = apply_filters('get_product_addons_product_terms', wp_get_post_terms($post_id, 'product_cat', array('fields' => 'ids')), $post_id);
     $exclude = get_post_meta($post_id, '_product_addons_exclude_global', true);
     // Product Parent Level Addons
     if ($inc_parent && ($parent_id = wp_get_post_parent_id($post_id))) {
         $raw_addons[10]['parent'] = apply_filters('get_parent_product_addons_fields', get_product_addons($parent_id, $parent_id . '-', false, false), $post_id, $parent_id);
     }
     // Product Level Addons
     $raw_addons[10]['product'] = apply_filters('get_product_addons_fields', array_filter((array) get_post_meta($post_id, '_product_addons', true)), $post_id);
     // Global level addons (all products)
     if ('1' !== $exclude && $inc_global) {
         $args = array('posts_per_page' => -1, 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_key' => '_priority', 'post_type' => 'global_product_addon', 'post_status' => 'publish', 'suppress_filters' => true, 'meta_query' => array(array('key' => '_all_products', 'value' => '1')));
         $global_addons = get_posts($args);
         if ($global_addons) {
             foreach ($global_addons as $global_addon) {
                 $priority = get_post_meta($global_addon->ID, '_priority', true);
                 $raw_addons[$priority][$global_addon->ID] = apply_filters('get_product_addons_fields', array_filter((array) get_post_meta($global_addon->ID, '_product_addons', true)), $global_addon->ID);
             }
         }
         // Global level addons (categories)
         if ($product_terms) {
             $args = apply_filters('get_product_addons_global_query_args', array('posts_per_page' => -1, 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_key' => '_priority', 'post_type' => 'global_product_addon', 'post_status' => 'publish', 'suppress_filters' => true, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $product_terms, 'include_children' => false))), $product_terms);
             $global_addons = get_posts($args);
             if ($global_addons) {
                 foreach ($global_addons as $global_addon) {
                     $priority = get_post_meta($global_addon->ID, '_priority', true);
                     $raw_addons[$priority][$global_addon->ID] = apply_filters('get_product_addons_fields', array_filter((array) get_post_meta($global_addon->ID, '_product_addons', true)), $global_addon->ID);
                 }
             }
         }
     }
     ksort($raw_addons);
     foreach ($raw_addons as $addon_group) {
         if ($addon_group) {
             foreach ($addon_group as $addon) {
                 $addons = array_merge($addons, $addon);
             }
         }
     }
     // Generate field names with unqiue prefixes
     if (!$prefix) {
         $prefix = apply_filters('product_addons_field_prefix', "{$post_id}-", $post_id);
     }
     foreach ($addons as $addon_key => $addon) {
         if (empty($addon['name'])) {
             unset($addons[$addon_key]);
             continue;
         }
         if (empty($addons[$addon_key]['field-name'])) {
             $addons[$addon_key]['field-name'] = sanitize_title($prefix . $addon['name']);
         }
     }
     return apply_filters('get_product_addons', $addons);
 }
function display_price_in_variation_option_name($term)
{
    global $wpdb, $product;
    $term_temp = $term;
    $term = strtolower($term);
    $term = str_replace(' ', '-', $term);
    $result = $wpdb->get_col("SELECT slug FROM {$wpdb->prefix}terms WHERE name = '{$term}'");
    $term_slug = !empty($result) ? $result[0] : $term;
    $query = "SELECT postmeta.post_id AS product_id\nFROM {$wpdb->prefix}postmeta AS postmeta\nLEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id )\nWHERE postmeta.meta_key LIKE 'attribute_%'\nAND postmeta.meta_value = '{$term_slug}'\nAND products.post_parent = {$product->id}";
    $variation_id = $wpdb->get_col($query);
    $parent = wp_get_post_parent_id($variation_id[0]);
    if ($parent > 0) {
        $_product = new WC_Product_Variation($variation_id[0]);
        $testVariable = $_product->get_variation_attributes();
        $itemPrice = strip_tags(woocommerce_price($_product->get_price()));
        $getPrice = $_product->get_price();
        $itemPriceInt = (int) $getPrice;
        $term = $term_temp;
        //this is where you can actually customize how the price is displayed
        if ($itemPriceInt > 0) {
            return $term . ' (' . $itemPrice . ' incl. GST)';
        } else {
            return $term . ' (' . $itemPrice . ')';
        }
    }
    return $term;
}
Ejemplo n.º 7
0
 public function shortcode_handler($atts, $content = null, $tag = '')
 {
     $id = get_the_ID();
     $args = ['order' => 'ASC', 'orderby' => 'menu_order', 'post__not_in' => [$id], 'post_parent' => wp_get_post_parent_id($id), 'post_type' => get_post_type(), 'posts_per_page' => 20];
     $query = new WP_Query($args);
     $r = [];
     if ($query->have_posts()) {
         while ($query->have_posts()) {
             $query->the_post();
             $classes = ['hestia-sibling', 'hestia-wrap', sprintf('post-%s', esc_attr(get_the_ID()))];
             $has_thumbnail = has_post_thumbnail();
             $permalink = get_permalink();
             if ($has_thumbnail) {
                 // Because who doesn't love a properly alphabetized list?
                 array_unshift($classes, 'has-post-thumbnail');
             }
             $r[] = sprintf('<div class="%s">', implode(' ', $classes));
             $r[] = sprintf('<a href="%s">', esc_attr($permalink));
             if ($has_thumbnail) {
                 $r[] = get_the_post_thumbnail();
             }
             $r[] = get_the_title();
             $r[] = '</a>';
             $r[] = '</div>';
         }
     }
     wp_reset_postdata();
     return implode("\n", $r);
 }
Ejemplo n.º 8
0
/**
 * Displays a list of pages which are either:
 * The children of the current page, or
 * The children of the parent page with a back to parent link
 */
function getParentId($pageId, $idsArray)
{
    $parentId = wp_get_post_parent_id($pageId);
    if ($parentId !== 0) {
        array_unshift($idsArray, $parentId);
        return getParentId($parentId, $idsArray);
    }
    return $idsArray;
}
function job_notification_templates($post_id, $notification_receiver)
{
    // Applied job title
    $job_title = get_the_title($post_id);
    // Site URL
    $site_url = get_option('siteurl');
    $parent_id = wp_get_post_parent_id($post_id);
    $job_post_keys = get_post_custom_keys($parent_id);
    $applicant_post_keys = get_post_custom_keys($post_id);
    if (NULL != $job_post_keys) {
        if (in_array('jobfeature_company_name', $job_post_keys)) {
            $company_name = get_post_meta($parent_id, 'jobfeature_company_name', TRUE);
        }
    }
    if (NULL != $applicant_post_keys) {
        if (in_array('jobapp_name', $applicant_post_keys)) {
            $applicant_name = get_post_meta($post_id, 'jobapp_name', TRUE);
        }
    }
    if ('applicant' != $notification_receiver) {
        $message = '<div style="width:700px; margin:0 auto;  border: 1px solid #95B3D7;font-family:Arial;">' . '<div style="border: 1px solid #95B3D7; background-color:#95B3D7;">' . ' <h2 style="text-align:center;">Job Application </h2>' . ' </div>' . '<div  style="margin:10px;">' . '<p>' . date("Y/m/d") . '</p>' . '<p>';
        if (NULL != $notification_receiver) {
            $message .= 'Hi ' . $notification_receiver . ',';
        }
        $message .= '</p>' . '<p>I ';
        if (NULL != $applicant_name) {
            $message .= $applicant_name . '';
        }
        $message .= ',would like to apply for the post of ' . $job_title . ' at your company ';
        if (NULL != $company_name) {
            $message .= $company_name . '';
        }
        $message .= '.</p>' . '<p>I have gone through the application criterion and requirements for the particular job and have posted my resume at given address  ' . $site_url . '<br/>' . 'I have also filled the detail of the online application form on ' . date("Y/m/d") . '.' . '</p>' . '<p>I sincerely believe that my educational qualifications and extra-curricular activities will be appropriate for the job and the type of applicant it possible requires.' . 'I promiss to devote my heart and soul to the job once selected to serve your company ';
        if (NULL != $company_name) {
            $message .= $company_name . '';
        }
        $message .= '.</p>' . 'I will be extremely grateful if you kindly glance through my application and consider me for the interview and the adjacent processes.' . '</p>' . '<p>I will be eagerly looking forward to your reply mail.</p>' . '<p>Thank you</p>' . '<p>Sincerely,</p>';
        if (NULL != $applicant_name) {
            $message .= $applicant_name . '';
        }
        $message .= '</div>' . ' </div>';
    } else {
        $message = '<div style="width:700px; margin:0 auto;  border: 1px solid #95B3D7;font-family:Arial;">' . '<div style="border: 1px solid #95B3D7; background-color:#95B3D7;">' . ' <h2 style="text-align:center;">Job Application Acknowledgement</h2>' . ' </div>' . '<div  style="margin:10px;">' . '<p>' . date("Y/m/d") . '</p>' . '<p>';
        $message .= 'Hi ';
        if (NULL != $applicant_name) {
            $message .= '' . $applicant_name . ',';
        }
        $message .= '<p>Thank you for your interest in ';
        if (NULL != $company_name) {
            $message .= $company_name . '.';
        }
        $message .= 'We acknowledge receipt of your resume and application for a position ' . $job_title . ' and sincerely appreciate your interest in our company.' . '</p>' . '<p>We will screen all applicants and select candidates whose qualifications seem to meet our needs.' . ' We will carefully consider your application during the initial screening and will contact you if you are selected to continue in the recruitment process. ' . 'We wish you every success.</p>' . '<p>Regards,</p>' . '<p>Admin,</p>' . '<p>' . get_bloginfo('name') . '</p>';
        $message .= '</div>' . ' </div>';
    }
    return $message;
}
Ejemplo n.º 10
0
function storeCanastaAlCorteCliente($cliente, $variacion, $adicionales)
{
    $actualizacionID = getActualizacionCanasta($cliente->club_id);
    $producto = wp_get_post_parent_id($cliente->producto_id);
    $canasta = getIdCanastaClube($cliente->club_id, $producto);
    $actualizacionId = getIdActualizacionCanasta($cliente->club_id, $producto, $actualizacionID);
    $arr = ['cliente_id' => $cliente->cliente_id, 'saldo_anterior' => $cliente->saldo, 'costo_canasta' => $variacion->costoSemanal, 'variation_id' => $cliente->producto_id, 'club_id' => $cliente->club_id, 'adicionales' => serialize($adicionales), 'fecha_corte' => date('Y-m-d'), 'actualizacion_id' => $actualizacionId, 'canasta_id' => $canasta];
    saveCanastaAlCorteCliente($arr);
    destroyAdicionalesCliente($cliente->cliente_id, $adicionales);
}
 /**
  * wcj_get_product_image_url.
  *
  * @version 2.5.7
  * @since   2.5.7
  * @todo    placeholder
  */
 function wcj_get_product_image_url($product_id, $image_size = 'shop_thumbnail')
 {
     if (has_post_thumbnail($product_id)) {
         $image_url = get_the_post_thumbnail_url($product_id, $image_size);
     } elseif (($parent_id = wp_get_post_parent_id($product_id)) && has_post_thumbnail($parent_id)) {
         $image_url = get_the_post_thumbnail_url($parent_id, $image_size);
     } else {
         $image_url = '';
     }
     return $image_url;
 }
Ejemplo n.º 12
0
 public function set_default_language($post_id)
 {
     if (!$this->model->post->get_language($post_id)) {
         if (isset($_GET['new_lang']) && ($lang = $this->model->get_language($_GET['new_lang']))) {
             $this->model->post->set_language($post_id, $lang);
         } elseif (($parent_id = wp_get_post_parent_id($post_id)) && ($parent_lang = $this->model->post->get_language($parent_id))) {
             $this->model->post->set_language($post_id, $parent_lang);
         } else {
             $this->model->post->set_language($post_id, $this->pref_lang);
         }
     }
 }
 /**
  * Get meta value
  *
  * @param int   $post_id
  * @param bool  $saved
  * @param array $field
  *
  * @return mixed
  */
 static function meta($post_id, $saved, $field)
 {
     $parent_id = wp_get_post_parent_id($post_id);
     if ($parent_id) {
         $post_id = $parent_id;
     }
     $options = $field['options'];
     $meta = wp_get_post_terms($post_id, $options['taxonomy']);
     $meta = is_array($meta) ? $meta : (array) $meta;
     $meta = wp_list_pluck($meta, 'term_id');
     return $meta;
 }
Ejemplo n.º 14
0
 function getAncestors($post_id)
 {
     $a = array();
     while (true) {
         $parent = (int) wp_get_post_parent_id($post_id);
         if ($parent < 1) {
             break;
         }
         $post_id = $parent;
         $a[] = array('type' => 'post', 'id' => $post_id);
     }
     return $a;
 }
function gpbbp_new_post($post_id, $post, $update)
{
    $TOPIC_POST_TYPE = bbp_get_topic_post_type();
    $REPLY_POST_TYPE = bbp_get_reply_post_type();
    $post_type = get_post_type($post);
    $forum_id = NULL;
    if ($post_type == $TOPIC_POST_TYPE) {
        $forum_id = wp_get_post_parent_id($post_id);
        gpbbp_apply_capabilities_from_forum($post_id, $forum_id);
    }
    if ($post_type == $REPLY_POST_TYPE) {
        $forum_id = bbp_get_forum_id();
        gpbbp_apply_capabilities_from_forum($post_id, $forum_id);
    }
    gpbbp_new_post_notification($post_id, $post, $post_type);
}
 /**
  * Extends the parent constructor to overwrite with variable data
  *
  * @param   int     ID of the product to load
  * @return  object
  */
 public function __construct($ID)
 {
     // Setup the product
     $parent_id = wp_get_post_parent_id($ID);
     parent::__construct($parent_id);
     // Get the meta & for each meta item overwrite with the variations ID
     $meta = get_post_custom($ID);
     $variable_stock = 0;
     foreach ($meta as $key => $array) {
         if ($array[0]) {
             $this->meta[$key] = $array;
         }
         if ($key == 'sku') {
             if (empty($array[0])) {
                 $tempsku = $ID;
             }
         }
         if ($key == 'stock') {
             // if no value then parent stock value is used for variation stock tracking
             // otherwise the variation stock even if '0' as that is a value, is used
             if ($array[0] == '') {
                 $variable_stock = '-9999999';
             } else {
                 $variable_stock = $array[0];
             }
         }
     }
     // Merge with the variation data
     $this->variation_id = $ID;
     if (isset($this->meta['variation_data'][0])) {
         $this->variation_data = maybe_unserialize($this->meta['variation_data'][0]);
     }
     $sale_from = $this->sale_price_dates_from;
     $sale_to = $this->sale_price_dates_to;
     parent::__construct($ID);
     // Restore the parent ID
     $this->ID = $parent_id;
     $this->id = $parent_id;
     if (!empty($tempsku)) {
         $this->sku = $tempsku;
     }
     $this->sale_price_dates_from = $sale_from;
     $this->sale_price_dates_to = $sale_to;
     // signal parent stock tracking or variation stock tracking
     $this->stock = $variable_stock == '-9999999' ? $variable_stock : $this->stock;
     return $this;
 }
Ejemplo n.º 17
0
 /**
  * Outputs the content of the widget
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     // outputs the content of the widget
     $sortby = empty($instance['sortby']) ? 'menu_order' : $instance['sortby'];
     $exclude = empty($instance['exclude']) ? '' : $instance['exclude'];
     $showall = empty($instance['showall']) ? 'off' : $instance['showall'];
     $siblings = empty($instance['siblings']) ? 'off' : $instance['siblings'];
     $parent_id = empty($instance['parent']) ? -1 : $instance['parent'];
     $depth = empty($instance['depth']) ? 0 : $instance['depth'];
     if ($showall == 'off' && $siblings == 'off' && $parent_id == -1 && !is_page()) {
         return;
     }
     // If we are not viewing a page AND a parent page has not been specified AND  we are not viewing ALL pages, don't show widget at all ...
     $exclude_tree = '';
     if ($siblings != 'off') {
         $parent_id = wp_get_post_parent_id(get_the_ID());
         // Add current page id to exclude tree list ...
         $exclude_tree .= get_the_ID();
     } else {
         if ($showall != 'off') {
             $parent_id = 0;
         } else {
             if ($parent_id == -1) {
                 $parent_id = get_the_ID();
             }
         }
     }
     if ($sortby == 'menu_order') {
         $sortby = 'menu_order, post_title';
     }
     $out = wp_list_pages(apply_filters('ccchildpages_widget_pages_args', array('title_li' => '', 'child_of' => $parent_id, 'echo' => 0, 'depth' => $depth, 'sort_column' => $sortby, 'exclude' => $exclude, 'exclude_tree' => $exclude_tree), $args, $instance));
     if (empty($out)) {
         return;
     }
     // Give up if the page has no children
     $ul_open = apply_filters('ccchildpages_widget_start_ul', '<ul>', $args, $instance);
     $ul_close = apply_filters('ccchildpages_widget_end_ul', '</ul>', $args, $instance);
     $out = apply_filters('ccchildpages_widget_output', $ul_open . $out . $ul_close, $args, $instance);
     echo apply_filters('ccchildpages_before_widget', $args['before_widget'], $args, $instance);
     if (!empty($instance['title'])) {
         $before_title = apply_filters('ccchildpages_widget_before_title', $args['before_title'], $args, $instance);
         $after_title = apply_filters('ccchildpages_widget_after_title', $args['after_title'], $args, $instance);
         echo $before_title . apply_filters('widget_title', $instance['title'], $args, $instance) . $after_title;
     }
     echo $out;
     echo apply_filters('ccchildpages_after_widget', $args['after_widget'], $args, $instance);
 }
Ejemplo n.º 18
0
 /**
  * @group canonical
  * @covers ::bbp_insert_reply
  */
 public function test_bbp_insert_reply()
 {
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create(array('post_title' => 'Reply To: Topic 1', 'post_content' => 'Content of reply to Topic 1', 'post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     // Get the reply.
     $reply = bbp_get_reply($r);
     remove_all_filters('bbp_get_reply_content');
     // Reply post.
     $this->assertSame('Reply To: Topic 1', bbp_get_reply_title($r));
     $this->assertSame('Content of reply to Topic 1', bbp_get_reply_content($r));
     $this->assertSame('publish', bbp_get_reply_status($r));
     $this->assertSame($t, wp_get_post_parent_id($r));
     $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?reply=' . $reply->post_name, $reply->guid);
     // Reply meta.
     $this->assertSame($f, bbp_get_reply_forum_id($r));
     $this->assertSame($t, bbp_get_reply_topic_id($r));
 }
 /**
  * Assign/unassign the sale category after post meta was updated.
  */
 public function assign_sale_category($meta_id, $post_id, $meta_key, $meta_value)
 {
     if ($meta_key != '_price') {
         return;
         // do nothing, if the meta key is not _price
     }
     if (wp_get_post_parent_id($post_id)) {
         return;
         // bail if this is a variation
     }
     $product = wc_get_product($post_id);
     if ($product->is_on_sale()) {
         // product is on sale, let's assign the sale category
         wp_set_object_terms($post_id, $this->sale_category, 'product_cat', true);
     } else {
         // product is not on sale, let's remove the sale category
         wp_remove_object_terms($post_id, $this->sale_category, 'product_cat');
     }
 }
 /**
  * trigger function.
  *
  * @access public
  * @return void
  */
 function trigger($order_id)
 {
     if (!$this->is_enabled() || empty($order_id) || !wp_get_post_parent_id($order_id)) {
         return false;
     }
     $this->object = wc_get_order($order_id);
     $this->vendor = yith_get_vendor($this->object->post->post_author, 'user');
     if (!$this->vendor->is_valid()) {
         return false;
     }
     $this->find['order-date'] = '{order_date}';
     $this->find['order-number'] = '{order_number}';
     $this->replace['order-date'] = date_i18n(wc_date_format(), strtotime($this->object->order_date));
     $this->replace['order-number'] = $this->object->get_order_number();
     $vendor_email = $this->vendor->store_email;
     if (empty($vendor_email)) {
         $vendor_owner = get_user_by('id', absint($this->vendor->get_owner()));
         $vendor_email = $vendor_owner instanceof WP_User ? $vendor_owner->user_email : false;
     }
     // Send Email to Vendor
     $this->send($vendor_email, $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments());
 }
Ejemplo n.º 21
0
 function attachment_field_course_set($form_fields, $post)
 {
     global $wpdb;
     $form_fields['linked-course'] = array('label' => 'Course', 'input' => 'html', 'helps' => __('Add this Media to a Canvas Course'));
     $course_of_post = get_post_meta(wp_get_post_parent_id($post->ID), "CanvasCourse", true);
     if ($course_of_post == "") {
         $course_of_post = get_post_meta($post->ID, "CanvasCourse", true);
     }
     $courses = $wpdb->get_results("select * from " . $wpdb->prefix . "posts where post_type='linkedcanvascourse' and post_status='publish'");
     $form_fields['linked-course']['html'] = '<select name="linked-course" id="linked-course">';
     $form_fields['linked-course']['html'] .= '<option>' . __("No course") . $course_of_post . '</option>';
     foreach ($courses as $course) {
         $id = get_post_meta($course->ID, "courseID", true);
         $selected = "";
         if ($id == $course_of_post) {
             $selected = " selected ";
         }
         $form_fields['linked-course']['html'] .= '<option value="' . $id . '" ' . $selected . '>' . $course->post_title . '</option>';
     }
     $form_fields['linked-course']['html'] .= '</select>';
     return $form_fields;
 }
Ejemplo n.º 22
0
 /**
  * single_page_layout_permalink
  *
  * Because the site uses a "single-page-layout", if a page has a parent with the template
  * 'single_page.php', then we want to #hash the child page links, instead of placing them in sub-folders.
  *
  * @param $permalink
  * @param $id
  * @return string
  */
 public static function single_page_permalink($permalink, $id)
 {
     if ($parent_id = wp_get_post_parent_id($id)) {
         if ($parent = get_post($parent_id)) {
             if (preg_match('/single-page.php$/', get_page_template_slug($parent_id))) {
                 $post = get_post($id);
                 if (is_array($permalink)) {
                     // this is for the admin sample permalink
                     $permalink = str_replace('/%pagename%', '#%pagename%', $permalink);
                 } else {
                     if (!is_admin() && get_permalink($parent) === get_permalink()) {
                         // relative
                         $permalink = "#{$post->post_name}";
                     } else {
                         // absolute
                         $permalink = preg_replace('/\\/' . preg_quote($post->post_name, '/') . '\\/$/', "#{$post->post_name}", $permalink);
                     }
                 }
             }
         }
     }
     return $permalink;
 }
function save_book_meta($post_id)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    $post = get_post($post_id);
    if (!$post) {
        return;
    }
    if ($post->post_type != 'page') {
        return;
    }
    if ($post->post_status == 'trash') {
        $term_id = get_post_meta($post_id, 'page_term_id', true);
        wp_delete_term($term_id, 'pages');
        return;
    } else {
        $tax_id = get_post_meta($post_id, 'page_term_id', true);
        if ($tax_id) {
            $current .= "tax_id" . $tax_id . "\n";
        }
        if (!$tax_id) {
            $page_id = $post->ID;
            $page_title = $post->post_title;
            $parent_id = wp_get_post_parent_id($page_id);
            $parent_tax_id = get_post_meta($parent_id, 'page_term_id', true);
            //remove_action( 'save_post', 'save_book_meta', 10, 2 );
            $term = wp_insert_term($page_title, 'pages', array('parent' => $parent_tax_id));
            if ($term) {
                $term_id = $term['term_id'];
                update_post_meta($page_id, 'page_term_id', $term_id);
            }
            //add_action( 'save_post', 'save_book_meta', 10, 2 );
        }
    }
}
Ejemplo n.º 24
0
 /**
  * Returns the main product image
  *
  * @param string $size (default: 'shop_thumbnail')
  * @return string
  */
 public function get_image($size = 'shop_thumbnail', $attr = array())
 {
     if (has_post_thumbnail($this->id)) {
         $image = get_the_post_thumbnail($this->id, $size, $attr);
     } elseif (($parent_id = wp_get_post_parent_id($this->id)) && has_post_thumbnail($parent_id)) {
         $image = get_the_post_thumbnail($parent_id, $size, $attr);
     } else {
         $image = wc_placeholder_img($size);
     }
     return $image;
 }
 /**
  * When the status changes
  */
 public function transition_post_status($new_status, $old_status, $post)
 {
     if ('job_application' !== $post->post_type) {
         return;
     }
     $statuses = get_job_application_statuses();
     // Add a note
     if ($old_status !== $new_status && array_key_exists($old_status, $statuses) && array_key_exists($new_status, $statuses)) {
         $user = get_user_by('id', get_current_user_id());
         $comment_author = $user->display_name;
         $comment_author_email = $user->user_email;
         $comment_post_ID = $post->ID;
         $comment_author_url = '';
         $comment_content = sprintf(__('Application status changed from "%s" to "%s"', 'wp-job-manager-applications'), $statuses[$old_status], $statuses[$new_status]);
         $comment_agent = 'WP Job Manager';
         $comment_type = 'job_application_note';
         $comment_parent = 0;
         $comment_approved = 1;
         $commentdata = apply_filters('job_application_note_data', compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_agent', 'comment_type', 'comment_parent', 'comment_approved'), $application_id);
         $comment_id = wp_insert_comment($commentdata);
     }
     if ('hired' === $new_status) {
         update_post_meta(wp_get_post_parent_id($post->ID), '_filled', 1);
     }
 }
Ejemplo n.º 26
0
 public function pre_comment_approved($approved, $commentdata)
 {
     if ($approved == '1') {
         $post_type = get_post_type($commentdata->comment_post_ID);
         if ($post_type == 'question') {
             // set updated meta for sorting purpose
             update_post_meta($commentdata->comment_post_ID, ANSPRESS_UPDATED_META, current_time('mysql'));
             // add participant
             //ap_add_parti($commentdata->comment_post_ID, $commentdata->user_ID, 'comment');
         } elseif ($post_type == 'answer') {
             $post_id = wp_get_post_parent_id($commentdata->comment_post_ID);
             // set updated meta for sorting purpose
             update_post_meta($post_id, ANSPRESS_UPDATED_META, current_time('mysql'));
             // add participant only
             //ap_add_parti($post_id, $commentdata->user_ID, 'comment');
         }
     }
 }
Ejemplo n.º 27
0
 /**
  * Add a product to the cart.
  *
  * @param int $product_id contains the id of the product to add to the cart
  * @param int $quantity contains the quantity of the item to add
  * @param int $variation_id
  * @param array $variation attribute values
  * @param array $cart_item_data extra cart item data we want to pass into the item
  * @return string|bool $cart_item_key
  */
 public function add_to_cart($product_id = 0, $quantity = 1, $variation_id = 0, $variation = array(), $cart_item_data = array())
 {
     // Wrap in try catch so plugins can throw an exception to prevent adding to cart
     try {
         $product_id = absint($product_id);
         $variation_id = absint($variation_id);
         // Ensure we don't add a variation to the cart directly by variation ID
         if ('product_variation' == get_post_type($product_id)) {
             $variation_id = $product_id;
             $product_id = wp_get_post_parent_id($variation_id);
         }
         // Get the product
         $product_data = wc_get_product($variation_id ? $variation_id : $product_id);
         // Sanity check
         if ($quantity <= 0 || !$product_data || 'trash' === $product_data->post->post_status) {
             return false;
         }
         // Load cart item data - may be added by other plugins
         $cart_item_data = (array) apply_filters('woocommerce_add_cart_item_data', $cart_item_data, $product_id, $variation_id);
         // Generate a ID based on product ID, variation ID, variation data, and other cart item data
         $cart_id = $this->generate_cart_id($product_id, $variation_id, $variation, $cart_item_data);
         // Find the cart item key in the existing cart
         $cart_item_key = $this->find_product_in_cart($cart_id);
         // Force quantity to 1 if sold individually and check for existing item in cart
         if ($product_data->is_sold_individually()) {
             $quantity = apply_filters('woocommerce_add_to_cart_sold_individually_quantity', 1, $quantity, $product_id, $variation_id, $cart_item_data);
             $in_cart_quantity = $cart_item_key ? $this->cart_contents[$cart_item_key]['quantity'] : 0;
             if ($in_cart_quantity > 0) {
                 throw new Exception(sprintf('<a href="%s" class="button wc-forward">%s</a> %s', wc_get_cart_url(), __('View Cart', 'woocommerce'), sprintf(__('You cannot add another &quot;%s&quot; to your cart.', 'woocommerce'), $product_data->get_title())));
             }
         }
         // Check product is_purchasable
         if (!$product_data->is_purchasable()) {
             throw new Exception(__('Sorry, this product cannot be purchased.', 'woocommerce'));
         }
         // Stock check - only check if we're managing stock and backorders are not allowed
         if (!$product_data->is_in_stock()) {
             throw new Exception(sprintf(__('You cannot add &quot;%s&quot; to the cart because the product is out of stock.', 'woocommerce'), $product_data->get_title()));
         }
         if (!$product_data->has_enough_stock($quantity)) {
             throw new Exception(sprintf(__('You cannot add that amount of &quot;%s&quot; to the cart because there is not enough stock (%s remaining).', 'woocommerce'), $product_data->get_title(), $product_data->get_stock_quantity()));
         }
         // Stock check - this time accounting for whats already in-cart
         if ($managing_stock = $product_data->managing_stock()) {
             $products_qty_in_cart = $this->get_cart_item_quantities();
             if ($product_data->is_type('variation') && true === $managing_stock) {
                 $check_qty = isset($products_qty_in_cart[$variation_id]) ? $products_qty_in_cart[$variation_id] : 0;
             } else {
                 $check_qty = isset($products_qty_in_cart[$product_id]) ? $products_qty_in_cart[$product_id] : 0;
             }
             /**
              * Check stock based on all items in the cart.
              */
             if (!$product_data->has_enough_stock($check_qty + $quantity)) {
                 throw new Exception(sprintf('<a href="%s" class="button wc-forward">%s</a> %s', wc_get_cart_url(), __('View Cart', 'woocommerce'), sprintf(__('You cannot add that amount to the cart &mdash; we have %s in stock and you already have %s in your cart.', 'woocommerce'), $product_data->get_stock_quantity(), $check_qty)));
             }
         }
         // If cart_item_key is set, the item is already in the cart
         if ($cart_item_key) {
             $new_quantity = $quantity + $this->cart_contents[$cart_item_key]['quantity'];
             $this->set_quantity($cart_item_key, $new_quantity, false);
         } else {
             $cart_item_key = $cart_id;
             // Add item after merging with $cart_item_data - hook to allow plugins to modify cart item
             $this->cart_contents[$cart_item_key] = apply_filters('woocommerce_add_cart_item', array_merge($cart_item_data, array('product_id' => $product_id, 'variation_id' => $variation_id, 'variation' => $variation, 'quantity' => $quantity, 'data' => $product_data)), $cart_item_key);
         }
         if (did_action('wp')) {
             $this->set_cart_cookies(!$this->is_empty());
         }
         do_action('woocommerce_add_to_cart', $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data);
         return $cart_item_key;
     } catch (Exception $e) {
         if ($e->getMessage()) {
             wc_add_notice($e->getMessage(), 'error');
         }
         return false;
     }
 }
 /**
  * Add an extra body classes for vendors dashboard
  *
  * @author Andrea Grillo <*****@*****.**>
  * @since  1.5.1
  *
  * @param $admin_body_classes
  *
  * @return string
  */
 public function admin_body_class($admin_body_classes)
 {
     global $post;
     $vendor = yith_get_vendor('current', 'user');
     $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
     $is_order_details = is_admin() && !$is_ajax && 'shop_order' == get_current_screen()->id;
     $refund_management = 'yes' == get_option('yith_wpv_vendors_option_order_refund_synchronization', 'no') ? true : false;
     $quote_management = 'yes' == get_option('yith_wpv_vendors_enable_request_quote', 'no') ? true : false;
     if ($vendor->is_valid() && $vendor->has_limited_access()) {
         $admin_body_classes = $admin_body_classes . ' vendor_limited_access';
         if ($is_order_details && $refund_management) {
             $admin_body_classes = $admin_body_classes . ' vendor_refund_management';
         }
         if (function_exists('YITH_Vendor_Request_Quote') && $quote_management && $post instanceof WP_Post && YITH_Vendor_Request_Quote()->is_quote($post->ID)) {
             $admin_body_classes = $admin_body_classes . ' vendor_quote_management';
         }
     } else {
         if ($vendor->is_super_user()) {
             $admin_body_classes = $admin_body_classes . ' vendor_super_user';
             if ($post && wp_get_post_parent_id($post->ID) && 'shop_order' == $post->post_type && $is_order_details) {
                 $admin_body_classes = $admin_body_classes . ' vendor_suborder_detail';
             }
         }
     }
     return $admin_body_classes;
 }
Ejemplo n.º 29
0
 function display_price_in_variation_option_name($term)
 {
     global $wpdb, $product;
     $result = $wpdb->get_col("SELECT slug FROM {$wpdb->prefix}terms WHERE name = '{$term}'");
     $term_slug = !empty($result) ? $result[0] : $term;
     $query = "SELECT postmeta.post_id AS product_id\n\t\t\tFROM {$wpdb->prefix}postmeta AS postmeta\n\t\t\tLEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id )\n\t\t\tWHERE postmeta.meta_key LIKE 'attribute_%'\n\t\t\tAND postmeta.meta_value = '{$term_slug}'\n\t\t\tAND products.post_parent = {$product->id}";
     $variation_id = $wpdb->get_col($query);
     $parent = wp_get_post_parent_id($variation_id[0]);
     if ($parent > 0) {
         $_product = new WC_Product_Variation($variation_id[0]);
         //this is where you can actually customize how the price is displayed
         return wp_strip_all_tags($term . ' (' . woocommerce_price($_product->get_price()) . ')', true);
     }
     return wp_strip_all_tags($term, true);
 }
Ejemplo n.º 30
0
 static function init()
 {
     add_action('switch_theme', array(__CLASS__, 'reset'));
     add_action('wp_restore_post_revision', array(__CLASS__, 'restore_revision'), 10, 2);
     // Save revisions for posts of type safecss.
     add_action('load-revision.php', array(__CLASS__, 'add_revision_redirect'));
     // Override the edit link, the default link causes a redirect loop
     add_filter('get_edit_post_link', array(__CLASS__, 'revision_post_link'), 10, 3);
     // Overwrite the content width global variable if one is set in the custom css
     add_action('template_redirect', array(__CLASS__, 'set_content_width'));
     add_action('admin_init', array(__CLASS__, 'set_content_width'));
     if (!is_admin()) {
         add_filter('stylesheet_uri', array(__CLASS__, 'style_filter'));
     }
     define('SAFECSS_USE_ACE', !jetpack_is_mobile() && !Jetpack_User_Agent_Info::is_ipad() && apply_filters('safecss_use_ace', true));
     // Register safecss as a custom post_type
     // Explicit capability definitions are largely unnecessary because the posts are manipulated in code via an options page, managing CSS revisions does check the capabilities, so let's ensure that the proper caps are checked.
     register_post_type('safecss', array('supports' => array('revisions'), 'label' => 'Custom CSS', 'can_export' => false, 'rewrite' => false, 'capabilities' => array('edit_post' => 'edit_theme_options', 'read_post' => 'read', 'delete_post' => 'edit_theme_options', 'edit_posts' => 'edit_theme_options', 'edit_others_posts' => 'edit_theme_options', 'publish_posts' => 'edit_theme_options', 'read_private_posts' => 'read')));
     // Short-circuit WP if this is a CSS stylesheet request
     if (isset($_GET['custom-css'])) {
         header('Content-Type: text/css', true, 200);
         header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
         // 1 year
         Jetpack_Custom_CSS::print_css();
         exit;
     }
     add_action('admin_enqueue_scripts', array('Jetpack_Custom_CSS', 'enqueue_scripts'));
     if (isset($_GET['page']) && 'editcss' == $_GET['page'] && is_admin()) {
         // Do migration routine if necessary
         Jetpack_Custom_CSS::upgrade();
         /**
          * Allows additional work when migrating safecss from wp_options to wp_post.
          *
          * @module custom-css
          *
          * @since 1.7.0
          */
         do_action('safecss_migrate_post');
     }
     /**
      * Never embed the style in the head on wpcom.
      * Yes, this filter should be added to an unsynced file on wpcom, but
      * there is no good syntactically-correct location to put it yet.
      * @link https://github.com/Automattic/jetpack/commit/a1be114e9179f64d147124727a58e2cf76c7e5a1#commitcomment-7763921
      */
     if (defined('IS_WPCOM') && IS_WPCOM) {
         add_filter('safecss_embed_style', '__return_false');
     } else {
         add_filter('safecss_embed_style', array('Jetpack_Custom_CSS', 'should_we_inline_custom_css'), 10, 2);
     }
     add_action('wp_head', array('Jetpack_Custom_CSS', 'link_tag'), 101);
     add_filter('jetpack_content_width', array('Jetpack_Custom_CSS', 'jetpack_content_width'));
     add_filter('editor_max_image_size', array('Jetpack_Custom_CSS', 'editor_max_image_size'), 10, 3);
     if (!current_user_can('switch_themes') && !is_super_admin()) {
         return;
     }
     add_action('admin_menu', array('Jetpack_Custom_CSS', 'menu'));
     if (isset($_POST['safecss']) && false == strstr($_SERVER['REQUEST_URI'], 'options.php')) {
         check_admin_referer('safecss');
         $save_result = self::save(array('css' => stripslashes($_POST['safecss']), 'is_preview' => isset($_POST['action']) && $_POST['action'] == 'preview', 'preprocessor' => isset($_POST['custom_css_preprocessor']) ? $_POST['custom_css_preprocessor'] : '', 'add_to_existing' => isset($_POST['add_to_existing']) ? $_POST['add_to_existing'] == 'true' : true, 'content_width' => isset($_POST['custom_content_width']) ? $_POST['custom_content_width'] : false));
         if ($_POST['action'] == 'preview') {
             wp_safe_redirect(add_query_arg('csspreview', 'true', get_option('home')));
             exit;
         }
         if ($save_result) {
             add_action('admin_notices', array('Jetpack_Custom_CSS', 'saved_message'));
         }
     }
     // Prevent content filters running on CSS when restoring revisions
     if (isset($_REQUEST['action']) && 'restore' === $_REQUEST['action'] && false !== strstr($_SERVER['REQUEST_URI'], 'revision.php')) {
         $parent_post = get_post(wp_get_post_parent_id(intval($_REQUEST['revision'])));
         if ($parent_post && !is_wp_error($parent_post) && 'safecss' === $parent_post->post_type) {
             // Remove wp_filter_post_kses, this causes CSS escaping issues
             remove_filter('content_save_pre', 'wp_filter_post_kses');
             remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');
             remove_all_filters('content_save_pre');
         }
     }
     // Modify all internal links so that preview state persists
     if (Jetpack_Custom_CSS::is_preview()) {
         ob_start(array('Jetpack_Custom_CSS', 'buffer'));
     }
 }