Example #1
0
 public function create_feedback($params)
 {
     global $un_settings;
     if (isset($params['title']) && $params['title']) {
         $title = $params['title'];
     }
     $content = $params['description'];
     if (empty($params['title'])) {
         $title = substr($content, 0, 150) . (strlen($content) < 150 ? '' : "…");
     }
     $id = wp_insert_post(array('post_type' => FEEDBACK, 'post_title' => wp_kses(apply_filters('un_feedback_title', $title, $params), wp_kses_allowed_html()), 'post_content' => wp_kses(apply_filters('un_feedback_content', $content, $params), wp_kses_allowed_html()), 'post_status' => un_get_option(UN_PUBLISH_DIRECTLY) ? 'publish' : 'pending', 'post_author' => 0));
     $email = isset($params['email']) ? trim($params['email']) : '';
     if ($email) {
         add_post_meta($id, '_email', $email);
     }
     if (is_user_logged_in()) {
         add_post_meta($id, '_author', get_current_user_id());
     }
     if (isset($params['name']) && trim($params['name'])) {
         add_post_meta($id, '_name', wp_kses(trim($params['name']), wp_kses_allowed_html()));
     }
     wp_set_post_terms($id, $params['type'], FEEDBACK_TYPE);
     do_action('un_feedback_created', $id, $params);
     $this->send_admin_message($id, $params);
 }
Example #2
0
 /**
  * Create or edit a a project
  *
  * @param null|int $project_id
  * @return int
  */
 function create($project_id = 0, $posted = array())
 {
     $is_update = $project_id ? true : false;
     $data = array('post_title' => $posted['project_name'], 'post_content' => $posted['project_description'], 'post_type' => 'project', 'post_status' => 'publish');
     if ($is_update) {
         $data['ID'] = $project_id;
         $project_id = wp_update_post($data);
     } else {
         $project_id = wp_insert_post($data);
     }
     if ($project_id) {
         $this->insert_project_user_role($posted, $project_id);
         wp_set_post_terms($project_id, $posted['project_cat'], 'project_category', false);
         if ($is_update) {
             do_action('cpm_project_update', $project_id, $data);
         } else {
             update_post_meta($project_id, '_project_archive', 'no');
             update_post_meta($project_id, '_project_active', 'yes');
             $settings = $this->settings_user_permission();
             update_post_meta($project_id, '_settings', $settings);
             do_action('cpm_project_new', $project_id, $data);
         }
     }
     return $project_id;
 }
 public function save_new_episode($item, $show_slug)
 {
     $item_date = $item->get_date('Y-m-d H:i:s');
     $enclosure = $item->get_enclosure();
     $post = array('post_title' => $item->get_title(), 'post_date' => $item_date, 'post_content' => $item->get_description(), 'post_status' => 'publish', 'post_type' => Dipo_Podcast_Post_Type::POST_TYPE, 'tags_input' => $enclosure->get_keywords());
     $post_id = wp_insert_post($post);
     if (!empty($show_slug)) {
         $term_id = term_exists($show_slug, 'podcast_show');
         wp_set_post_terms($post_id, $term_id, 'podcast_show');
     }
     // save episodes data as metadata for post
     $subtitle = htmlspecialchars($this->get_subtitle($item));
     update_post_meta($post_id, '_dipo_subtitle', $subtitle);
     $summary = htmlspecialchars($this->get_summary($item));
     update_post_meta($post_id, '_dipo_summary', $summary);
     $explicit = htmlspecialchars(strtolower($this->get_explicit($item)));
     $possible_values = array('yes', 'no', 'clean');
     if (in_array($explicit, $possible_values)) {
         update_post_meta($post_id, '_dipo_explicit', $explicit);
     }
     $medialink = esc_url_raw($enclosure->get_link());
     $type = htmlspecialchars($enclosure->get_type());
     $duration = htmlspecialchars($enclosure->get_duration('hh:mm:ss'));
     $length = htmlspecialchars($enclosure->get_length());
     $mediafile = array('id' => 1, 'medialink' => $medialink, 'mediatype' => $type, 'duration' => $duration, 'filesize' => $length);
     update_post_meta($post_id, '_dipo_mediafile1', $mediafile);
     update_post_meta($post_id, '_dipo_max_mediafile_number', '1');
     $this->created_episodes++;
     return $post_id;
 }
 public static function error_log($post_title, $error, $tags = array())
 {
     $post_content = (is_string($error) ? $error : print_r($error, true)) . "\n\n";
     $backtrace = debug_backtrace();
     // remove calls to this function and template tags that call it
     foreach ($backtrace as $i => $call) {
         if ('voce_error_log' === $call['function'] || 'error_log' === $call['function']) {
             unset($backtrace[$i]);
         }
     }
     $post_content .= "<hr>\n";
     foreach ($backtrace as $call) {
         if (isset($call['file']) && isset($call['line'])) {
             $post_content .= sprintf("%s - (%s:%d)\n", $call['function'], $call['file'], $call['line']);
         } else {
             $post_content .= $call['function'] . "\n";
             break;
             // stop when we get to the function containing the voce_error_log() call
         }
     }
     $postarr = compact('post_title', 'post_content');
     $postarr = array_merge($postarr, array('post_type' => self::POST_TYPE, 'post_status' => 'publish', 'post_tag' => $tags));
     $log_id = wp_insert_post($postarr);
     wp_set_post_terms($log_id, $tags, self::TAXONOMY);
 }
function scoper_force_custom_taxonomy_filters($post_id, $post)
{
    $post_type_obj = get_post_type_object($post->post_type);
    foreach ($post_type_obj->taxonomies as $taxonomy) {
        // if terms were selected, WP core already applied the filter and there is no need to apply default terms
        if (in_array($taxonomy, array('category', 'post_tag')) || did_action("pre_post_{$taxonomy}")) {
            continue;
        }
        // don't filter term selection for non-hierarchical taxonomies
        if (empty($GLOBALS['wp_taxonomies'][$taxonomy]->hierarchical)) {
            continue;
        }
        if ($taxonomy_obj = get_taxonomy($taxonomy)) {
            if (!empty($_POST['tax_input'][$taxonomy]) && is_array($_POST['tax_input'][$taxonomy]) && (reset($_POST['tax_input'][$taxonomy]) || count($_POST['tax_input'][$taxonomy]) > 1)) {
                // complication because (as of 3.0) WP always includes a zero-valued first array element
                $tags = $_POST['tax_input'][$taxonomy];
            } elseif ('auto-draft' != $post->post_status) {
                $tags = (array) get_option("default_{$taxonomy}");
            } else {
                $tags = array();
            }
            if ($tags) {
                if (!empty($_POST['tax_input']) && is_array($_POST['tax_input'][$taxonomy])) {
                    // array = hierarchical, string = non-hierarchical.
                    $tags = array_filter($tags);
                }
                if (current_user_can($taxonomy_obj->cap->assign_terms)) {
                    $tags = apply_filters("pre_post_{$taxonomy}", $tags);
                    $tags = apply_filters("{$taxonomy}_pre", $tags);
                    wp_set_post_terms($post_id, $tags, $taxonomy);
                }
            }
        }
    }
}
Example #6
0
 public function postStoreProcess($table, $newTags = array(), $replace = true)
 {
     return false;
     if (!empty($table->newTags) && empty($newTags)) {
         $newTags = $table->newTags;
     }
     // If existing row, check to see if tags have changed.
     $newTable = clone $table;
     $newTable->reset();
     $key = $newTable->getKeyName();
     $typeAlias = $this->typeAlias;
     $result = false;
     if ($this->tagsChanged || !empty($newTags) && $newTags[0] != '') {
         $taxonomy_obj = get_taxonomy($typeAlias);
         if (is_array($newTags)) {
             // array = hierarchical, string = non-hierarchical.
             $newTags = array_filter($newTags);
         }
         if (current_user_can($taxonomy_obj->cap->assign_terms)) {
             $result = wp_set_post_terms($table->id, $newTags, $typeAlias);
             if (is_array($result) && count($result) > 0) {
                 $result = true;
             } elseif (is_object($result)) {
                 $result = false;
             }
         }
     }
     return $result;
 }
 function post_add_tax($value, $object, $field_name)
 {
     //var_dump( $value );
     foreach ($value as $term => $tax) {
         wp_set_post_terms($object->ID, array(intval($term)), $tax, true);
     }
 }
 public static function save($post_id)
 {
     if (isset($_POST['_unit'])) {
         update_post_meta($post_id, '_unit', sanitize_text_field($_POST['_unit']));
     }
     if (isset($_POST['_unit_base'])) {
         update_post_meta($post_id, '_unit_base', $_POST['_unit_base'] === '' ? '' : wc_format_decimal($_POST['_unit_base']));
     }
     if (isset($_POST['_unit_price_regular'])) {
         update_post_meta($post_id, '_unit_price_regular', $_POST['_unit_price_regular'] === '' ? '' : wc_format_decimal($_POST['_unit_price_regular']));
         update_post_meta($post_id, '_unit_price', $_POST['_unit_price_regular'] === '' ? '' : wc_format_decimal($_POST['_unit_price_regular']));
     }
     if (isset($_POST['_unit_price_sale'])) {
         update_post_meta($post_id, '_unit_price_sale', '');
         // Update Sale Price only if is on sale (Cron?!)
         if (get_post_meta($post_id, '_price', true) != $_POST['_regular_price'] && $_POST['_unit_price_sale'] !== '') {
             update_post_meta($post_id, '_unit_price_sale', $_POST['_unit_price_sale'] === '' ? '' : wc_format_decimal($_POST['_unit_price_sale']));
             update_post_meta($post_id, '_unit_price', $_POST['_unit_price_sale'] === '' ? '' : wc_format_decimal($_POST['_unit_price_sale']));
         }
     }
     if (isset($_POST['_mini_desc'])) {
         update_post_meta($post_id, '_mini_desc', esc_html($_POST['_mini_desc']));
     }
     if (isset($_POST['delivery_time']) && !is_numeric($_POST['delivery_time'])) {
         wp_set_post_terms($post_id, sanitize_text_field($_POST['delivery_time']), 'product_delivery_time');
     } else {
         wp_set_object_terms($post_id, absint($_POST['delivery_time']), 'product_delivery_time');
     }
 }
function add_post_to_cat()
{
    // Get the Post ID
    if (isset($_POST['post_id']) && !empty($_POST['post_id'])) {
        $post_id = esc_html($_POST['post_id']);
    } else {
        echo json_encode(array('success' => false, 'reason' => 'No Post ID.'));
        exit;
    }
    // Get the Category
    if (isset($_POST['cat_id']) && !empty($_POST['cat_id'])) {
        $cat_id = esc_html($_POST['cat_id']);
    } else {
        echo json_encode(array('success' => false, 'reason' => 'No Cat ID.'));
        exit;
    }
    // Check if Post is already in this category
    if (has_term($cat_id, 'bookmark-category', $post_id)) {
        echo json_encode(array('success' => true, 'reason' => 'duplicate'));
        exit;
    }
    // Add Post to Bookmark Category
    $did_add_cat = wp_set_post_terms($post_id, $cat_id, 'bookmark-category', true);
    if ($did_add_cat) {
        echo json_encode(array('success' => true, 'reason' => 'inserted'));
    } else {
        echo json_encode(array('success' => false, 'reason' => "Couldn't add cat."));
    }
    exit;
}
 public function post()
 {
     if (isset($_POST['review_id'])) {
         update_post_meta($_POST['review_id'], 'color', $_POST['color']);
         update_post_meta($_POST['review_id'], 'espuma', $_POST['espuma']);
         update_post_meta($_POST['review_id'], 'alcohol', $_POST['alcohol']);
         update_post_meta($_POST['review_id'], 'cuerpo', $_POST['cuerpo']);
         update_post_meta($_POST['review_id'], 'final', $_POST['final']);
         update_post_meta($_POST['review_id'], 'amargor', $_POST['amargor']);
         update_post_meta($_POST['review_id'], 'rating', $_POST['rating']);
         $cerveza_id = get_post_meta($_POST['review_id'], 'cerveza_id', true);
         $flavors = $_POST['tax_input']['flavor_of_beer'];
         $aromas = $_POST['tax_input']['aroma_of_beer'];
         wp_set_post_terms($_POST['review_id'], $flavors, 'flavor_of_beer');
         wp_set_post_terms($_POST['review_id'], $aromas, 'aroma_of_beer');
         global $wpdb;
         $sql = 'SELECT * FROM nwm_loc_hielera ';
         $sql .= 'WHERE beer=' . $cerveza_id . ' ';
         $sql .= 'AND user='******'user' => get_current_user_id(), 'beer' => $cerveza_id, 'review' => 1, 'rate' => 1, 'forlater' => 0, 'favorite' => 0, 'status' => 'Review');
             $wpdb->insert('nwm_loc_hielera', $newCoolerRow);
         } else {
             $updateCoolerRow = array('status' => 'Review', 'review' => 1);
             $wpdb->update('nwm_loc_hielera', $updateCoolerRow, array('user' => get_current_user_id(), 'beer' => $cerveza_id));
         }
         $wpdb->insert('nwm_loc_hielera', array('user' => get_current_user_id(), 'beer' => $cerveza_id));
         $wpdb->update('nwm_loc_hielera', array('status' => 'Reviewed', 'review' => 1, 'rate' => 1), array('user' => get_current_user_id(), 'beer' => $cerveza_id));
     }
 }
Example #11
0
 function handle_question_editing()
 {
     global $wpdb;
     if (!wp_verify_nonce($_POST['_wpnonce'], 'qa_edit')) {
         wp_die(__('Are you sure you want to do that?', QA_TEXTDOMAIN));
     }
     $question_id = (int) $_POST['question_id'];
     if (!$question_id && !current_user_can('publish_questions')) {
         wp_die(__('You are not allowed to post questions', QA_TEXTDOMAIN));
     }
     $question = array('post_title' => trim($_POST['question_title']), 'post_content' => trim($_POST['question_content']));
     if (empty($question['post_title']) || empty($question['post_content'])) {
         wp_die(__('Questions must have both a title and a body.', QA_TEXTDOMAIN));
     }
     // Check for duplicates
     if (!$question_id) {
         $dup_id = $wpdb->get_var($wpdb->prepare("\n\t\t\t\tSELECT ID\n\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\tWHERE post_type = 'question'\n\t\t\t\tAND post_status = 'publish'\n\t\t\t\tAND (post_title = %s OR post_content = %s)\n\t\t\t\tLIMIT 1\n\t\t\t", $question['post_title'], $question['post_content']));
         if ($dup_id) {
             wp_die(sprintf(__('It seems that question was <a href="%s">already asked</a>.', QA_TEXTDOMAIN), qa_get_url('single', $dup_id)));
         }
     }
     $question_id = $this->_insert_post($question_id, $question, array('post_type' => 'question', 'comment_status' => 'open'));
     wp_set_post_terms($question_id, $_POST['question_tags'], 'question_tag');
     return qa_get_url('single', $question_id);
 }
Example #12
0
function wdm_modified_bid_place($args)
{
    global $wpdb;
    $wpdb->show_errors();
    $wpdb->insert($wpdb->prefix . 'wdm_bidders', array('name' => $args['orig_name'], 'email' => $args['orig_email'], 'auction_id' => $args['auc_id'], 'bid' => $args['orig_bid'], 'date' => date("Y-m-d H:i:s", time())), array('%s', '%s', '%d', '%f', '%s'));
    update_post_meta($args['auc_id'], 'wdm_previous_bid_value', $args['mod_bid']);
    //store bid value of the most recent bidder
    $place_bid = $wpdb->insert($wpdb->prefix . 'wdm_bidders', array('name' => $args['mod_name'], 'email' => $args['mod_email'], 'auction_id' => $args['auc_id'], 'bid' => $args['mod_bid'], 'date' => date("Y-m-d H:i:s", time())), array('%s', '%s', '%d', '%f', '%s'));
    if ($place_bid) {
        $c_code = substr(get_option('wdm_currency'), -3);
        $char = $args['site_char'];
        $ret_url = $args['auc_url'];
        $adm_email = get_option("wdm_auction_email");
        if ($args['email_type'] === 'winner') {
            update_post_meta($args['auc_id'], 'wdm_listing_ends', date("Y-m-d H:i:s", time()));
            $check_term = term_exists('expired', 'auction-status');
            wp_set_post_terms($args['auc_id'], $check_term["term_id"], 'auction-status');
            update_post_meta($args['auc_id'], 'email_sent_imd', 'sent_imd');
            $args['stat'] = "Won";
        } else {
            $args['stat'] = "Placed";
        }
        $args['adm_email'] = $adm_email;
        $args['ret_url'] = $ret_url;
        $args['type'] = 'proxy';
        echo json_encode($args);
    }
}
function cjtheme_insert_question()
{
    global $wpdb;
    $errors = null;
    parse_str($_POST['data'], $postdata);
    if ($postdata['question'] == '') {
        $errors[] = __('Please enter some content to ask.', 'cjtheme');
    }
    if ($postdata['category'] == '') {
        $errors[] = __('You must select a category for this question.', 'cjtheme');
    }
    if (!is_null($errors)) {
        $return['errors'] = cjtheme_show_message('error', implode('<br>', $errors));
    } else {
        // $post_title = cjtheme_trim_text($postdata['question'], '60');
        $post_title = $postdata['question'];
        $question_data = array('post_title' => $post_title, 'post_name' => sanitize_title($post_title), 'post_content' => esc_textarea($postdata['question']), 'post_type' => 'questions', 'post_status' => 'publish');
        $post_id = wp_insert_post($question_data);
        wp_set_post_terms($post_id, $postdata['category'], 'qna_type');
        //$return['success'] = $postdata['current_url'].'#question-'.$post_id;
        $return['success'] = get_permalink($post_id);
    }
    echo json_encode($return);
    die;
}
 /**
  * Wrapper for terms setting to post.
  *
  * @param array  $terms    List of terms to set.
  * @param string $taxonomy Name of taxonomy to set terms to.
  * @param bool   $append   When true post may have multiple same instances.
  *
  * @return bool Success.
  */
 public function set_terms(array $terms, $taxonomy, $append = false)
 {
     $result = wp_set_post_terms($this->_post_id, $terms, $taxonomy, $append);
     if (is_wp_error($result)) {
         return false;
     }
     return $result;
 }
function copy_tags_from_old_to_new($old_id, $new_id)
{
    $old_terms = wp_get_post_terms($old_id, 'post_tag');
    $old_term_ids = array_map(function ($term) {
        return $term->term_id;
    }, $old_terms);
    wp_set_post_terms($new_id, $old_term_ids, 'post_tag', true);
}
function wpdr_update_type($postID)
{
    $wpdr = Document_Revisions::$instance;
    if (!$wpdr->verify_post_type($postID)) {
        return;
    }
    wp_set_post_terms($postID, array($wpdr->get_extension($postID)), 'filetype', false);
}
Example #17
0
function toggle_case()
{
    global $post;
    if (isset($_POST['closeCase'])) {
        $tag = get_term_by('id', $_POST['result_select'], 'results');
        wp_set_post_terms($post->ID, $tag->slug, 'results');
    } elseif (isset($_POST['openCase'])) {
        wp_delete_object_term_relationships($post->ID, 'results');
    }
}
Example #18
0
function chef_gift_registry_add_action_callback()
{
    if (!wp_verify_nonce($_POST['_wpnonce'], 'add_to_wishlist') || !absint($_POST['u'])) {
        _e('Adding the item to your wishlist failed.', 'ignitewoo-wishlists-pro');
        die;
    }
    $taxonomy_id = absint($_POST['wishlist_num']);
    if (!$taxonomy_id) {
        _e('There was an error adding the wishlist. Please try again shortly.', 'ignitewoo-wishlists-pro');
        die;
    }
    $wishlist_type = get_term($taxonomy_id, 'c_wishlists_cat', OBJECT);
    if (!$wishlist_type) {
        _e('There was an error adding the wishlist. Please try again shortly.', 'ignitewoo-wishlists-pro');
        die;
    }
    if ('' == trim(strip_tags($_POST['wishlist_title']))) {
        _e('You must specify a Wishlist title.', 'ignitewoo-wishlists-pro');
        die;
    }
    $user = absint($_POST['u']);
    // We have 3 predefined types: public, private, and shared.
    // Parse to find which string is in the slug so we can define the list.
    // Do this just in case an admin modifies the taxonomies.
    if (strpos($wishlist_type->slug, 'wishlist_public') !== false) {
        $wishlist_type = 'public';
    } else {
        if (strpos($wishlist_type->slug, 'wishlist_private') !== false) {
            $wishlist_type = 'private';
        } else {
            if (strpos($wishlist_type->slug, 'wishlist_shared') !== false) {
                $wishlist_type = 'shared';
            } else {
                $wishlist_type = 'public';
            }
        }
    }
    $wishlist_title = $_POST['wishlist_title'];
    $args = array('post_type' => 'custom_wishlists', 'post_title' => strip_tags($wishlist_title), 'post_content' => '', 'post_status' => 'publish', 'post_author' => $user);
    $post_id = wp_insert_post($args);
    if ($post_id) {
        wp_set_post_terms($post_id, array($taxonomy_id), 'c_wishlists_cat');
        update_post_meta($post_id, 'wishlist_type', $wishlist_type);
        $event_type = isset($_POST['event-type']) ? $_POST['event-type'] : "";
        $event_date = isset($_POST['event-date']) ? $_POST['event-date'] : "";
        $co_registrant_name = isset($_POST['co-registrant-name']) ? $_POST['co-registrant-name'] : "";
        $co_registrant_email = isset($_POST['co-registrant-email']) ? $_POST['co-registrant-email'] : "";
        save_additional_wishlists_info($post_id, $user, $event_type, $event_date, $co_registrant_name, $co_registrant_email);
        include CHEF_GIFT_REGISTRY_PLUGIN_DIR . '/wishlist-add-action-success-result.tpl.php';
        die;
    } else {
        _e('There was an error adding the wishlist. Please try again shortly.', 'ignitewoo-wishlists-pro');
        die;
    }
}
Example #19
0
function wpmp_add_product()
{
    if (isset($_POST['__product_wpmp']) && wp_verify_nonce($_POST['__product_wpmp'], 'wpmp-product') && $_POST['task'] == '') {
        //echo "here";exit;
        if ($_POST['post_type'] == "wpmarketplace") {
            global $current_user, $wpdb;
            get_currentuserinfo();
            $settings = get_option('_wpmp_settings');
            $pstatus = $settings['fstatus'] ? $settings['fstatus'] : "draft";
            $my_post = array('post_title' => $_POST['product']['post_title'], 'post_content' => $_POST['product']['post_content'], 'post_excerpt' => $_POST['product']['post_excerpt'], 'post_status' => $pstatus, 'post_author' => $current_user->ID, 'post_type' => "wpmarketplace");
            if ($_POST['id']) {
                //update post
                $my_post['ID'] = $_REQUEST['id'];
                wp_update_post($my_post);
                $postid = $_REQUEST['id'];
            } else {
                //insert post
                $postid = wp_insert_post($my_post);
            }
            update_post_meta($postid, "wpmp_list_opts", $_POST['wpmp_list']);
            //set the product type
            wp_set_post_terms($postid, $_POST['product_type'], "ptype");
            foreach ($_POST['wpmp_list'] as $k => $v) {
                update_post_meta($postid, $k, $v);
            }
            if ($_POST['wpmp_list']['fimage']) {
                $wp_filetype = wp_check_filetype(basename($_POST['wpmp_list']['fimage']), null);
                $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($_POST['wpmp_list']['fimage'])), 'post_content' => '', 'guid' => $_POST['wpmp_list']['fimage'], 'post_status' => 'inherit');
                $attach_id = wp_insert_attachment($attachment, $_POST['wpmp_list']['fimage'], $postid);
                // you must first include the image.php file
                // for the function wp_generate_attachment_metadata() to work
                require_once ABSPATH . 'wp-admin/includes/image.php';
                $attach_data = wp_generate_attachment_metadata($attach_id, $_POST['wpmp_list']['fimage']);
                wp_update_attachment_metadata($attach_id, $attach_data);
                set_post_thumbnail($postid, $attach_id);
            }
            //send admin email
            if ($pstatus == "draft") {
                //get user emai
                global $current_user;
                get_currentuserinfo();
                mail($current_user->user_email, "New Product Added", "Your product is successfully added and is waiting to admin review. You will be notified if your product is accepetd or rejected.");
                //now send notification to site admin about newly added product
                $admin_email = get_bloginfo('admin_email');
                mail($admin_email, "Product Review", "New Product is added by user " . $current_user->user_login . ". Please review this product to add your store.");
                //add a new post meta to identify only drafted post
                if (!update_post_meta($postid, '_z_user_review', '1')) {
                    add_post_meta($postid, '_z_user_review', '1', true);
                }
            }
        }
        header("Location: " . $_SERVER['HTTP_REFERER']);
        die;
    }
}
 /**
  * Save meta box data
  */
 public static function save($post_id, $post)
 {
     update_post_meta($post_id, 'sp_minutes', sp_array_value($_POST, 'sp_minutes', get_option('sportspress_event_minutes', 90)));
     $venues = array_filter(sp_array_value(sp_array_value($_POST, 'tax_input', array()), 'sp_venue', array()));
     if (empty($venues)) {
         $teams = sp_array_value($_POST, 'sp_team', array());
         $team = reset($teams);
         $venue = sp_get_the_term_id($team, 'sp_venue');
         wp_set_post_terms($post_id, $venue, 'sp_venue');
     }
 }
Example #21
0
 function save($data, $terms)
 {
     extract($data);
     if ('terminput' == $type) {
         wp_set_post_terms($post_id, $terms, $taxonomy);
     } else {
         wp_set_object_terms($post_id, absint($terms), $taxonomy);
     }
     $content = get_the_term_list($post_id, $taxonomy, $before, $sep, $after);
     return $this->placehold($content);
 }
function wpdr_update_type($postID)
{
    $wpdr = Document_Revisions::$instance;
    if (!$wpdr->verify_post_type($postID)) {
        return;
    }
    $post = get_post($postID);
    $attachment = get_post($post->post_content);
    $extensions = array($wpdr->get_extension(get_attached_file($attachment->ID)));
    wp_set_post_terms($postID, $extensions, 'filetype', false);
}
 public function test_term_flushing_cache()
 {
     $post_id = $this->factory->post->create();
     $term_id = $this->factory->term->create(['banana', 'post_tag']);
     wp_set_post_terms($post_id, 'banana');
     $first_run = $this->query->query([]);
     $this->assertSame($this->obj->all_post_ids, false);
     clean_term_cache($term_id);
     $second_run = $this->query->query([]);
     $this->assertSame($this->obj->all_post_ids, false);
 }
Example #24
0
 /**
  * Tag the slide attachment to the slider tax category
  */
 public function tag_slide_to_slider()
 {
     if (!term_exists($this->slider->ID, 'ml-slider')) {
         // create the taxonomy term, the term is the ID of the slider itself
         wp_insert_term($this->slider->ID, 'ml-slider');
     }
     // get the term thats name is the same as the ID of the slider
     $term = get_term_by('name', $this->slider->ID, 'ml-slider');
     // tag this slide to the taxonomy term
     wp_set_post_terms($this->slide->ID, $term->term_id, 'ml-slider', true);
 }
Example #25
0
function property_detail_content($content)
{
    if (get_post_meta(get_the_ID(), 'property_id', true) != '' && get_post_meta(get_the_ID(), 'bapi_last_update', true) < time() - 3600 * 60 * 24) {
        remove_filter('save_post', 'update_post_bapi');
        wp_update_post(mod_post_builder($propid, get_the_ID()));
        update_post_meta(get_the_ID(), 'bapi_last_update', time());
        wp_set_post_terms(get_the_ID(), wp_create_category(get_option('property_category_name')), 'category');
        add_filter('save_post', 'update_post_bapi');
    }
    bapi_search_page_body($content);
    return $content;
}
Example #26
0
 public function test_topic_count_text_callback()
 {
     register_taxonomy('wptests_tax', 'post');
     $terms = $this->factory->term->create_many(2, array('taxonomy' => 'wptests_tax'));
     $posts = $this->factory->post->create_many(2);
     wp_set_post_terms($posts[0], $terms, 'wptests_tax');
     wp_set_post_terms($posts[1], array($terms[1]), 'wptests_tax');
     $term_objects = $this->retrieve_terms(array('include' => $terms), 'wptests_tax');
     $actual = wp_generate_tag_cloud($term_objects, array('format' => 'array', 'topic_count_text_callback' => array($this, 'topic_count_text_callback')));
     $this->assertContains("title='1 foo'", $actual[0]);
     $this->assertContains("title='2 foo'", $actual[1]);
 }
 public function test_delete_object_term_relationships()
 {
     $anther_term = wp_insert_term('mouse', $this->taxonomy);
     wp_set_post_terms($this->post_id, array($anther_term['term_id']), $this->taxonomy, false);
     $anther_term_2 = wp_insert_term('cat', $this->taxonomy);
     wp_set_post_terms($this->post_id, array($anther_term_2['term_id']), $this->taxonomy, true);
     wp_delete_object_term_relationships($this->post_id, array($this->taxonomy));
     $this->client->do_sync();
     $object_terms = get_the_terms($this->post_id, $this->taxonomy);
     $server_object_terms = $this->server_replica_storage->get_the_terms($this->post_id, $this->taxonomy);
     $this->assertEquals($object_terms, $server_object_terms);
 }
Example #28
0
/**
 * Get the proxy post for a term
 *
 * @param string $taxnomy
 * @param int $term_id
 *
 * @return int $post_id
 */
function largo_get_term_meta_post($taxonomy, $term_id)
{
    $query = new WP_Query(array('post_type' => '_term_meta', 'posts_per_page' => 1, 'post_status' => 'any', 'tax_query' => array(array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $term_id, 'include_children' => false))));
    if ($query->found_posts) {
        return $query->posts[0]->ID;
    } else {
        $tax_input = array();
        $post_id = wp_insert_post(array('post_type' => '_term_meta', 'post_title' => "{$taxonomy}:{$term_id}"));
        wp_set_post_terms($post_id, array((int) $term_id), $taxonomy);
        return $post_id;
    }
}
function wdm_email_auction_winner()
{
    global $wpdb;
    $all_auc = array('posts_per_page' => -1, 'post_type' => 'ultimate-auction');
    if (!empty($all_auc)) {
        $all_auctions = get_posts($all_auc);
        foreach ($all_auctions as $single_auc) {
            $active_term = wp_get_post_terms($single_auc->ID, 'auction-status', array("fields" => "names"));
            if (time() >= strtotime(get_post_meta($single_auc->ID, 'wdm_listing_ends', true))) {
                if (!in_array('expired', $active_term)) {
                    $check_tm = term_exists('expired', 'auction-status');
                    wp_set_post_terms($single_auc->ID, $check_tm["term_id"], 'auction-status');
                }
            }
        }
        $comp_auc = array('posts_per_page' => -1, 'post_type' => 'ultimate-auction', 'auction-status' => 'expired');
        $completed_auctions = get_posts($comp_auc);
        //$perm_type = get_option('permalink_structure');
        //if(empty($perm_type))
        //        $set_perm = "&";
        //else
        //        $set_perm = "?";
        foreach ($completed_auctions as $ca) {
            if (get_post_meta($ca->ID, 'auction_email_sent', true) !== 'sent') {
                $bought = get_post_meta($ca->ID, 'auction_bought_status', true);
                $count_qry = "SELECT COUNT(bid) FROM " . $wpdb->prefix . "wdm_bidders WHERE auction_id =" . $ca->ID;
                $count_bid = $wpdb->get_var($count_qry);
                $was_sent_imd = get_post_meta($ca->ID, 'email_sent_imd', true);
                $is_in_progress = get_post_meta($ca->ID, 'wdm_to_be_sent', true);
                if ($bought !== 'bought' && $count_bid > 0 && $was_sent_imd !== 'sent_imd') {
                    $reserve_price_met = get_post_meta($ca->ID, 'wdm_lowest_bid', true);
                    $winner_bid = "";
                    $bid_qry = "SELECT MAX(bid) FROM " . $wpdb->prefix . "wdm_bidders WHERE auction_id =" . $ca->ID . " ORDER BY id DESC";
                    $winner_bid = $wpdb->get_var($bid_qry);
                    if ($winner_bid >= $reserve_price_met) {
                        update_post_meta($ca->ID, 'wdm_to_be_sent', 'in_progress');
                        $winner_email = "";
                        $email_qry = "SELECT email FROM " . $wpdb->prefix . "wdm_bidders WHERE bid =" . $winner_bid . " AND auction_id =" . $ca->ID . " ORDER BY id DESC";
                        $winner_email = $wpdb->get_var($email_qry);
                        //$name_qry = "SELECT name FROM ".$wpdb->prefix."wdm_bidders WHERE bid =".$winner_bid." AND auction_id =".$ca->ID." ORDER BY id DESC";
                        //
                        //$winner_name = $wpdb->get_var($name_qry);
                        //$winner = get_user_by('login', $winner_name);
                        //$winner_email = $winner->user_email;
                        $return_url = get_post_meta($ca->ID, 'current_auction_permalink', true);
                        wp_enqueue_script('jquery');
                        require 'ajax-actions/send-email.php';
                    }
                }
            }
        }
    }
}
Example #30
0
 public function create()
 {
     $error_obj = "";
     if (isset($this->TP_title)) {
         if ($this->TP_type == 'page') {
             $post = get_page_by_title($this->TP_title, 'OBJECT', $this->TP_type);
         } else {
             $post = get_page_by_title($this->TP_title, 'OBJECT', $this->TP_type);
         }
         $post_data = array('post_title' => wp_strip_all_tags($this->TP_title), 'post_name' => $this->TP_slug, 'post_content' => $this->TP_content, 'post_status' => $this->TP_status, 'post_type' => $this->TP_type, 'post_author' => $this->TP_auth_id, 'post_category' => $this->TP_category, 'page_template' => $this->TP_template, 'post_date' => $this->TP_date);
         if (!isset($post)) {
             $this->TP_current_post_id = wp_insert_post($post_data, $error_obj);
             $this->TP_current_post = get_post((int) $this->TP_current_post_id, 'OBJECT');
             $this->TP_current_post_permalink = get_permalink((int) $this->TP_current_post_id);
             $terms = array();
             $terms_array = explode(',', $this->TP_terms);
             foreach ($terms_array as $singleterm) {
                 $term = get_term_by('slug', $singleterm, 'essential_grid_category');
                 $terms[] = $term->term_id;
             }
             wp_set_post_terms($this->TP_current_post_id, $terms, 'essential_grid_category');
             if (!empty($this->TP_post_tags)) {
                 wp_set_post_terms($this->TP_current_post_id, $this->TP_post_tags, 'post_tag');
             }
             foreach ($this->TP_meta as $meta_key => $meta_value) {
                 if ($meta_key == 'eg-clients-icon' && !empty($meta_value)) {
                     $attach_id = $this->create_image('client.png');
                     $meta_value = $attach_id;
                 }
                 if ($meta_key == 'eg-clients-icon-dark' && !empty($meta_value)) {
                     $attach_id = $this->create_image('client_dark.png');
                     $meta_value = $attach_id;
                 }
                 update_post_meta($this->TP_current_post_id, $meta_key, $meta_value);
             }
             global $imagenr;
             if ($imagenr == 4) {
                 $imagenr = 1;
             }
             $attach_id = $this->create_image('demoimage' . $imagenr++ . '.jpg');
             set_post_thumbnail($this->TP_current_post_id, $attach_id);
             return $this->TP_current_post_id;
         } else {
             //$this->update();
             $this->errors[] = 'That page already exists. Try updating instead. Control passed to the update() function.';
             return FALSE;
         }
     } else {
         $this->errors[] = 'Title has not been set.';
         return FALSE;
     }
 }