• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_set_post_tags函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wp_set_post_tags函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_set_post_tags函数的具体用法?PHP wp_set_post_tags怎么用?PHP wp_set_post_tags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wp_set_post_tags函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: tweetimport_import_twitter_feed

function tweetimport_import_twitter_feed($twitter_account)
{
  require_once (ABSPATH . WPINC . '/class-feed.php');

  $feed = new SimplePie();

  $account_parts = explode ('/', $twitter_account['twitter_name'], 2);



  if ($twitter_account['account_type'] == 1): //Account is Favorites
    $feed->set_feed_url(str_replace('#=#USER#=#', $account_parts[0], TWEETIMPORT_API_FAVORITES_URL));
  elseif ($twitter_account['account_type'] == 0 && count($account_parts) == 1): //User timeline
      $feed->set_feed_url(str_replace('#=#USER#=#', $account_parts[0], TWEETIMPORT_API_USER_TIMELINE_URL));
  elseif ($twitter_account['account_type'] == 2 && count($account_parts) == 2): //Account is list
      $feed_url = str_replace('#=#USER#=#', $account_parts[0], TWEETIMPORT_API_LIST_URL);
      $feed_url = str_replace('#=#LIST#=#', $account_parts[1], $feed_url);
      $feed->set_feed_url($feed_url);
  else :
      return '<strong>ERROR: Account information not correct. Account type wrong?</strong>';
  endif;

  $feed->set_useragent('Tweet Import http://skinju.com/wordpress/tweetimport');
  $feed->set_cache_class('WP_Feed_Cache');
  $feed->set_file_class('WP_SimplePie_File');
  $feed->enable_cache(true);
  $feed->set_cache_duration (apply_filters('tweetimport_cache_duration', 880));
  $feed->enable_order_by_date(false);
  $feed->init();
  $feed->handle_content_type();

  if ($feed->error()):
   return '<strong>ERROR: Feed Reading Error.</strong>';
  endif;

  $rss_items = $feed->get_items();

  $imported_count = 0;
  foreach ($rss_items as $item)
  {
    $item = apply_filters ('tweetimport_tweet_before_new_post', $item); //return false to stop processing an item.
    if (!$item) continue;

    $processed_description = $item->get_description();

    //Get the twitter author from the beginning of the tweet text
    $twitter_author = trim(preg_replace("~^(\w+):(.*?)$~", "\\1", $processed_description));

    if ($twitter_account['strip_name'] == 1):
      $processed_description = preg_replace("~^(\w+):(.*?)~i", "\\2", $processed_description);
    endif;

    if ($twitter_account['names_clickable'] == 1):
      $processed_description = preg_replace("~@(\w+)~", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $processed_description);
      $processed_description = preg_replace("~^(\w+):~", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>:", $processed_description);
    endif;

    if ($twitter_account['hashtags_clickable'] == 1):
      if ($twitter_account['hashtags_clickable_twitter'] == 1):
          $processed_description = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $processed_description);
      else:
        $processed_description = preg_replace("/#(\w+)/", "<a href=\"" . skinju_get_tag_link("\\1") . "\">#\\1</a>", $processed_description);
      endif;
    endif;

  $processed_description = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $processed_description);
  $processed_description = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $processed_description);

    $new_post = array('post_title' => trim (substr (preg_replace("~{$account_parts[0]}: ~i", "", $item->get_title()), 0, 25) . '...'),
                      'post_content' => trim ($processed_description),
                      'post_date' => $item->get_date('Y-m-d H:i:s'),
                      'post_author' => $twitter_account['author'],
                      'post_category' => array($twitter_account['category']),
                      'post_status' => 'publish');

    $new_post = apply_filters('tweetimport_new_post_before_create', $new_post); // Offer the chance to manipulate new post data. return false to skip
    if (!$new_post) continue;
    $new_post_id = wp_insert_post($new_post);

    $imported_count++;

    add_post_meta ($new_post_id, 'tweetimport_twitter_author', $twitter_author, true); 
    add_post_meta ($new_post_id, 'tweetimport_date_imported', date ('Y-m-d H:i:s'), true);
    add_post_meta ($new_post_id, 'tweetimport_twitter_id', $item->get_id(), true);
    add_post_meta ($new_post_id, 'tweetimport_twitter_id', $item->get_id(), true);
    add_post_meta ($new_post_id, '_tweetimport_twitter_id_hash', $item->get_id(true), true);
    add_post_meta ($new_post_id, 'tweetimport_twitter_post_uri', $item->get_link(0));
    add_post_meta ($new_post_id, 'tweetimport_author_avatar', $item->get_link(0, 'image'));

    preg_match_all ('~#([A-Za-z0-9_]+)(?=\s|\Z)~', $item->get_description(), $out);
    if ($twitter_account['add_tag']) $out[0][] = $twitter_account['add_tag'];
    wp_set_post_tags($new_post_id, implode (',', $out[0]));
  }

  return $imported_count;
}
开发者ID:robotconscience,项目名称:Robotconscience.com,代码行数:96,代码来源:tweet-import.php


示例2: custom_bulk_action


//.........这里部分代码省略.........
                         $content_post = get_post($post_id);
                         $content = strip_tags($content_post->post_content);
                         $arraytags = array();
                         if ($idioma1 === 'English') {
                             $engine = "https://api.monkeylearn.com/v2/extractors/ex_isnnZRbS/extract/";
                             $keywords = "https://api.monkeylearn.com/v2/extractors/ex_y7BPYzNG/extract/";
                             $location = "LOCATION";
                             $organization = "ORGANIZATION";
                             $person = "PERSON";
                             $other = "OTRO";
                         } elseif ($idioma1 === 'Español') {
                             $engine = "https://api.monkeylearn.com/v2/extractors/ex_Kc8uzhSi/extract/";
                             $keywords = "https://api.monkeylearn.com/v2/extractors/ex_eV2dppYE/extract/";
                             $location = "LUG";
                             $organization = "ORG";
                             $person = "PERS";
                             $other = "OTROS";
                         }
                         //ENTITIES ANALYSIS
                         if ($peopleopt || $organizationsopt || $otheropt || $placesopt) {
                             $url = $engine;
                             $result = wp_autoTAG_remoteApiCall($content, $url, $valuetoken);
                             $jsonIterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(json_decode($result, true)), RecursiveIteratorIterator::SELF_FIRST);
                             $push = false;
                             foreach ($jsonIterator as $key => $val) {
                                 if (is_array($val)) {
                                     // Nothing to do here?
                                 } else {
                                     if ($peopleopt) {
                                         if ($key === 'tag' && $val === $person) {
                                             $push = true;
                                         }
                                     }
                                     if ($placesopt) {
                                         if ($key === 'tag' && $val === $location) {
                                             $push = true;
                                         }
                                     }
                                     if ($organizationsopt) {
                                         if ($key === 'tag' && $val === $organization) {
                                             $push = true;
                                         }
                                     }
                                     if ($otheropt) {
                                         if ($key === 'tag' && $val === $other) {
                                             $push = true;
                                         }
                                     }
                                     if ($key === 'entity' && $push == true) {
                                         $entity = $val;
                                         array_push($arraytags, $entity);
                                         $push = false;
                                     }
                                 }
                             }
                         }
                         // RELEVANT KEYWORDS ANALYSIS
                         if ($keywordsopt) {
                             $limite = $relevanceopt;
                             $url = $keywords;
                             $result2 = wp_autoTAG_remoteApiCall($content, $url, $valuetoken);
                             $jsonIterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(json_decode($result2, TRUE)), RecursiveIteratorIterator::SELF_FIRST);
                             foreach ($jsonIterator as $key => $val) {
                                 if (is_array($val)) {
                                     // Nothing to do here?
                                 } else {
                                     // CHECK RELEVANCE
                                     if ($key === 'relevance') {
                                         if (floatval($val) > floatval($limite)) {
                                             $push = true;
                                         } else {
                                             $push = false;
                                         }
                                     }
                                     // ADD KEYWORDS TO ARRAY
                                     if ($key === 'keyword') {
                                         if ($push == true) {
                                             array_push($arraytags, $val);
                                         }
                                     }
                                 }
                             }
                         }
                         wp_set_post_tags($post_id, $arraytags);
                     }
                     if (!$this->perform_export($post_id)) {
                         wp_die(__('Error adding tags.'));
                     }
                     $tags_added++;
                 }
                 $sendback = add_query_arg(array('exported' => $tags_added, 'ids' => join(',', $post_ids)), $sendback);
                 break;
             default:
                 return;
         }
         $sendback = remove_query_arg(array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback);
         wp_redirect($sendback);
         exit;
     }
 }
开发者ID:8mikelx8,项目名称:wp_autotag,代码行数:101,代码来源:WP_autotag.php


示例3: ct_update_tags

 public function ct_update_tags($tags, $object, $field_name)
 {
     if (empty($tags) || !tags) {
         return;
     }
     return wp_set_post_tags($object->ID, $tags);
 }
开发者ID:judahnator,项目名称:WP-API-Categories-Tags,代码行数:7,代码来源:posts.class.php


示例4: wp_aatags_alts

function wp_aatags_alts($post_ID, $post_title, $post_content)
{
    $tags = get_tags(array('hide_empty' => false));
    $tagx = get_option('wp_aatags_opts');
    $number = get_option('wp_aatags_aadnumber');
    switch ($tagx) {
        case 3:
            $d = strtolower($post_title . ' ' . wp_trim_words($post_content, 333, ''));
            break;
        case 2:
            $d = strtolower($post_title . ' ' . wp_trim_words($post_content, 999, ''));
            break;
        default:
            $d = strtolower($post_title);
            break;
    }
    if ($tags) {
        $i = 0;
        foreach ($tags as $tag) {
            if (strpos($d, strtolower($tag->name)) !== false) {
                wp_set_post_tags($post_ID, $tag->name, true);
                $i++;
            }
            if ($i == $number) {
                break;
            }
        }
    }
}
开发者ID:yszar,项目名称:linuxwp,代码行数:29,代码来源:wp-autotags.php


示例5: set_tags

 /**
  * Set tags to the post.
  *
  * @param  int   $post_id Post ID.
  * @param  array $post	Post object.
  * @return none
  * @since  0.1.0
  */
 public static function set_tags($post_id, $post)
 {
     if (!is_wp_error($post_id)) {
         if (isset($post['tags_input'])) {
             wp_set_post_tags($post_id, $post['tags_input'], true);
         }
     }
 }
开发者ID:adaminfinitum,项目名称:advanced-csv-importer,代码行数:16,代码来源:Actions.php


示例6: image_keyword_tagger_add_keywords

function image_keyword_tagger_add_keywords($mid, $object_id, $meta_key, $_meta_value)
{
    if ('_wp_attachment_metadata' == $meta_key) {
        $attachment_meta = wp_get_attachment_metadata($object_id);
        if (!empty($attachment_meta['image_meta']['keywords'])) {
            wp_set_post_tags($object_id, implode(',', $attachment_meta['image_meta']['keywords']), true);
        }
    }
}
开发者ID:2ndkauboy,项目名称:image-keyword-tagger,代码行数:9,代码来源:image-keyword-tagger.php


示例7: set_tags

 public function set_tags($value, $object, $field_name)
 {
     $tags = [];
     foreach ($value as $k => $v) {
         error_log("Setting tag: {$k}");
         $tags[] = $k;
     }
     return wp_set_post_tags($object->ID, $tags);
 }
开发者ID:nabsul,项目名称:wp-linkoscope-plugin,代码行数:9,代码来源:class-linkoscope-post-meta.php


示例8: test_get_the_taxonomies

 function test_get_the_taxonomies()
 {
     $post_id = $this->factory->post->create();
     $taxes = get_the_taxonomies($post_id);
     $this->assertNotEmpty($taxes);
     $this->assertEquals(array('category'), array_keys($taxes));
     $id = $this->factory->tag->create();
     wp_set_post_tags($post_id, array($id));
     $taxes = get_the_taxonomies($post_id);
     $this->assertNotEmpty($taxes);
     $this->assertCount(2, $taxes);
     $this->assertEquals(array('category', 'post_tag'), array_keys($taxes));
 }
开发者ID:Benrajalu,项目名称:philRaj,代码行数:13,代码来源:taxonomy.php


示例9: tdomf_widget_tags_post

 function tdomf_widget_tags_post($args)
 {
     extract($args);
     $options = tdomf_widget_tags_options($tdomf_form_id);
     $tagslist = '';
     if ($options['default']) {
         $tagslist = strip_tags($options['default']);
     }
     if (isset($tags) && !empty($tags)) {
         if (!empty($tagslist)) {
             $tagslist .= ',';
         }
         $tagslist .= strip_tags($tags);
     }
     if (!empty($tagslist)) {
         # set last var to true to just append
         wp_set_post_tags($post_ID, strip_tags($tagslist), false);
     }
     return NULL;
 }
开发者ID:TheReaCompany,项目名称:pooplog,代码行数:20,代码来源:tdomf-tags-widget.php


示例10: test_empty_category__in

 /**
  * @ticket 28099
  * @group taxonomy
  */
 function test_empty_category__in()
 {
     $cat_id = $this->factory->category->create();
     $post_id = $this->factory->post->create();
     wp_set_post_categories($post_id, $cat_id);
     $q1 = get_posts(array('category__in' => array($cat_id)));
     $this->assertNotEmpty($q1);
     $q2 = get_posts(array('category__in' => array()));
     $this->assertNotEmpty($q2);
     $tag = wp_insert_term('woo', 'post_tag');
     $tag_id = $tag['term_id'];
     $slug = get_tag($tag_id)->slug;
     wp_set_post_tags($post_id, $slug);
     $q3 = get_posts(array('tag__in' => array($tag_id)));
     $this->assertNotEmpty($q3);
     $q4 = get_posts(array('tag__in' => array()));
     $this->assertNotEmpty($q4);
     $q5 = get_posts(array('tag_slug__in' => array($slug)));
     $this->assertNotEmpty($q5);
     $q6 = get_posts(array('tag_slug__in' => array()));
     $this->assertNotEmpty($q6);
 }
开发者ID:Benrajalu,项目名称:philRaj,代码行数:26,代码来源:query.php


示例11: ipin_edit

function ipin_edit()
{
    $nonce = $_POST['nonce'];
    if (!wp_verify_nonce($nonce, 'ajax-nonce')) {
        die;
    }
    do_action('ipin_before_edit_pin', $_POST);
    global $user_ID;
    $postinfo = get_post(intval($_POST['postdata_pid']), ARRAY_A);
    $user_id = $postinfo['post_author'];
    if (!(current_user_can('administrator') || current_user_can('editor') || $user_id == $user_ID)) {
        die;
    }
    //Get board info
    $board_add_new = sanitize_text_field($_POST['postdata_board_add_new']);
    $board_add_new_category = $_POST['postdata_board_add_new_category'];
    $board_parent_id = get_user_meta($user_id, '_Board Parent ID', true);
    if ($board_add_new !== '') {
        $board_children = get_term_children($board_parent_id, 'board');
        $found = '0';
        foreach ($board_children as $board_child) {
            $board_child_term = get_term_by('id', $board_child, 'board');
            if (stripslashes(htmlspecialchars($board_add_new, ENT_NOQUOTES, 'UTF-8')) == $board_child_term->name) {
                $found = '1';
                $found_board_id = $board_child_term->term_id;
                break;
            }
        }
        if ($found == '0') {
            $slug = wp_unique_term_slug($board_add_new . '__ipinboard', 'board');
            //append __ipinboard to solve slug conflict with category and 0 in title
            if ($board_add_new_category == '-1') {
                $board_add_new_category = '1';
            }
            $new_board_id = wp_insert_term($board_add_new, 'board', array('description' => $board_add_new_category, 'parent' => $board_parent_id, 'slug' => $slug));
            $postdata_board = $new_board_id['term_id'];
        } else {
            $postdata_board = $found_board_id;
        }
    } else {
        $postdata_board = $_POST['postdata_board'];
    }
    //category ID is stored in the board description field
    $category_id = get_term_by('id', $postdata_board, 'board');
    $post_id = intval($_POST['postdata_pid']);
    $edit_post = array();
    $edit_post['ID'] = $post_id;
    $edit_post['post_category'] = array($category_id->description);
    $edit_post['post_name'] = '';
    $allowed_html = array('a' => array('href' => true), 'em' => array(), 'blockquote' => array(), 'p' => array(), 'li' => array(), 'ol' => array(), 'strong' => array(), 'ul' => array());
    if (of_get_option('htmltags') != 'enable') {
        unset($allowed_html);
        $allowed_html = array();
    }
    if (of_get_option('form_title_desc') != 'separate') {
        $edit_post['post_title'] = balanceTags(wp_kses($_POST['postdata_title'], $allowed_html), true);
    } else {
        $edit_post['post_title'] = sanitize_text_field($_POST['postdata_title']);
    }
    $edit_post['post_content'] = balanceTags(wp_kses($_POST['postdata_content'], $allowed_html), true);
    remove_action('save_post', 'ipin_save_post', 50, 2);
    wp_update_post($edit_post);
    wp_set_post_terms($post_id, array($postdata_board), 'board');
    //update postmeta for new post
    if ($_POST['postdata_source'] != '') {
        update_post_meta($post_id, '_Photo Source', esc_url($_POST['postdata_source']));
        update_post_meta($post_id, '_Photo Source Domain', parse_url(esc_url($_POST['postdata_source']), PHP_URL_HOST));
    } else {
        delete_post_meta($post_id, '_Photo Source');
        delete_post_meta($post_id, '_Photo Source Domain');
    }
    //add tags
    wp_set_post_tags($post_id, sanitize_text_field($_POST['postdata_tags']));
    //add price
    if ($_POST['postdata_price']) {
        if (strpos($_POST['postdata_price'], '.') !== false) {
            $_POST['postdata_price'] = number_format($_POST['postdata_price'], 2);
        }
        update_post_meta($post_id, '_Price', sanitize_text_field($_POST['postdata_price']));
    } else {
        if (get_post_meta($post_id, '_Price', true) !== '') {
            delete_post_meta($post_id, '_Price');
        }
    }
    //add new board to followers who fully follow user
    if ($new_board_id && !is_wp_error($new_board_id)) {
        $usermeta_followers_id_allboards = get_user_meta($user_id, '_Followers User ID All Boards');
        $followers_id_allboards = $usermeta_followers_id_allboards[0];
        if (!empty($followers_id_allboards)) {
            foreach ($followers_id_allboards as $followers_id_allboard) {
                $usermeta_following_board_id = get_user_meta($followers_id_allboard, '_Following Board ID');
                $following_board_id = $usermeta_following_board_id[0];
                array_unshift($following_board_id, $new_board_id['term_id']);
                update_user_meta($followers_id_allboard, '_Following Board ID', $following_board_id);
            }
        }
    }
    do_action('ipin_after_edit_pin', $post_id);
    echo get_permalink($post_id);
    exit;
//.........这里部分代码省略.........
开发者ID:leshuis,项目名称:testwp,代码行数:101,代码来源:functions.php


示例12: mass_photo_posting

function mass_photo_posting()
{
    global $box;
    // check user permission to use bulk photo posting
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.', MAX_SHORTNAME));
    }
    // get the current user object
    $current_user = wp_get_current_user();
    if (!empty($_POST) && !empty($_POST['post'])) {
        ksort($_POST['post']);
        foreach ($_POST['post'] as $key => $value) {
            $imageID = $key;
            $photos[$imageID]['id_photo'] = $imageID;
            $photos[$imageID]['post_name'] = $_POST['post_name'][$imageID];
            foreach (@$_POST['galleries'] as $key => $value) {
                if ($key == $imageID) {
                    foreach ($value as $key2 => $value2) {
                        $photos[$imageID]['gal'] .= $key2 . ",";
                    }
                }
            }
            $photos[$imageID]['photo_copyright_information_value'] = $_POST['photo_copyright_information_value'][$imageID];
            $photos[$imageID]['photo_copyright_link_value'] = $_POST['photo_copyright_link_value'][$imageID];
            $photos[$imageID]['photo_location_value'] = $_POST['photo_location_value'][$imageID];
            $photos[$imageID]['photo_date_value'] = strtotime($_POST['photo_date_value'][$imageID]);
            $photos[$imageID]['photo_item_type_value'] = $_POST['photo_item_type_value'][$imageID];
            $photos[$imageID]['photo_cropping_direction_value'] = $_POST['photo_cropping_direction_value'][$imageID];
            $photos[$imageID]['photo_lightbox_type_value'] = "Photo";
            // Get fullsize background
            if ($_POST['fullsize_background'][$imageID] == 'nofullsize') {
                $photos[$imageID]['show_post_fullsize_value'] = 'false';
            } else {
                $photos[$imageID]['show_post_fullsize_value'] = 'true';
            }
            if ($_POST['fullsize_background'][$imageID] == 'random') {
                $photos[$imageID]['show_random_fullsize_value'] = 'true';
            } else {
                if ($_POST['fullsize_background'][$imageID] == 'featured') {
                    $photos[$imageID]['show_random_fullsize_value'] = 'false';
                } else {
                    $photos[$imageID]['show_random_fullsize_value'] = 'false';
                }
            }
            if ($_POST['fullsize_background_url'][$imageID] != '') {
                $photos[$imageID]['show_page_fullsize_url_value'] = $_POST['fullsize_background_url'][$imageID];
            }
            // get the tags array
            $photos[$imageID]['post_tags'] = explode(",", trim($_POST['post_tags'][$imageID]));
        }
        if (!empty($photos)) {
            foreach ($photos as $photo) {
                $cat_array = explode(',', substr($photo['gal'], 0, -1));
                // prepare the photo post values
                $post = array('post_title' => $photo['post_name'], 'post_content' => '', 'post_status' => 'publish', 'post_author' => $current_user->ID, 'post_type' => POST_TYPE_GALLERY, 'tax_input' => array(GALLERY_TAXONOMY => $cat_array));
                // add the new post
                $post_id = wp_insert_post($post);
                // add the tags to the new post
                if (!empty($photo['post_tags'])) {
                    wp_set_post_tags($post_id, $photo['post_tags']);
                    unset($GLOBALS['tag_cache']);
                }
                // add the meta fields from $_POST values to the new post
                foreach ($photo as $index => $value) {
                    add_post_meta($post_id, MAX_SHORTNAME . '_' . $index, $photo[$index]);
                }
                // Set featured post from media attachment
                set_post_thumbnail($post_id, $photo['id_photo']);
                $image_post = array();
                $image_post['ID'] = $photo['id_photo'];
                $image_post['post_parent'] = $post_id;
                // update the post
                wp_update_post($image_post);
                // show update message
                $_saved = true;
            }
        }
    } else {
        $_saved = false;
    }
    // Get unassigned attachments
    $images_args = array('numberposts' => 99999, 'orderby' => 'post_date', 'order' => 'ASC', 'post_type' => 'attachment', 'post_parent' => 0, 'post_status' => 'inherit');
    $images = get_posts($images_args);
    // Get Gallery Categories
    $gallery_args = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 0, 'hierarchical' => 1, 'taxonomy' => GALLERY_TAXONOMY, 'pad_counts' => false);
    $galleries = get_categories($gallery_args);
    // get the custom post type for further use
    $post_types = max_get_custom_post_type();
    // get galleries in hirachical order
    $taxonomy_names = get_object_taxonomies('gallery');
    $hierarchical_taxonomies = array();
    $flat_taxonomies = array();
    foreach ($taxonomy_names as $taxonomy_name) {
        $taxonomy = get_taxonomy($taxonomy_name);
        if (!$taxonomy->show_ui) {
            continue;
        }
        if ($taxonomy->hierarchical) {
            $hierarchical_taxonomies[] = $taxonomy;
        } else {
//.........这里部分代码省略.........
开发者ID:erdidoqan,项目名称:fishcom,代码行数:101,代码来源:max_mass_upload.php


示例13: usp_createPublicSubmission

function usp_createPublicSubmission($title, $content, $authorName, $authorID, $authorUrl, $tags, $category, $fileData)
{
    global $usp_options, $usp_post_meta_IsSubmission, $usp_post_meta_SubmitterIp, $usp_post_meta_Submitter, $usp_post_meta_SubmitterUrl, $usp_post_meta_Image;
    $authorName = strip_tags($authorName);
    $authorUrl = strip_tags($authorUrl);
    if (isset($_SERVER['REMOTE_ADDR'])) {
        $authorIp = stripslashes(trim($_SERVER['REMOTE_ADDR']));
    }
    if (isset($_POST['user-submitted-captcha'])) {
        $captcha = stripslashes(trim($_POST['user-submitted-captcha']));
    }
    if (isset($_POST['user-submitted-verify'])) {
        $verify = stripslashes(trim($_POST['user-submitted-verify']));
    }
    if (!usp_validateTitle($title)) {
        return false;
    }
    if (!usp_validateTags($tags)) {
        return false;
    }
    if (!empty($verify)) {
        return false;
    }
    if ($usp_options['usp_captcha'] == 'show') {
        if (!usp_spam_question($captcha)) {
            return false;
        }
    }
    $postData = array();
    $postData['post_title'] = $title;
    $postData['post_content'] = $content;
    $postData['post_status'] = 'pending';
    $postData['post_author'] = $authorID;
    $numberApproved = $usp_options['number-approved'];
    if ($numberApproved < 0) {
    } elseif ($numberApproved == 0) {
        $postData['post_status'] = 'publish';
    } else {
        $posts = get_posts(array('post_status' => 'publish', 'meta_key' => $usp_post_meta_Submitter, 'meta_value' => $authorName));
        $counter = 0;
        foreach ($posts as $post) {
            $submitterUrl = get_post_meta($post->ID, $usp_post_meta_SubmitterUrl, true);
            $submitterIp = get_post_meta($post->ID, $usp_post_meta_SubmitterIp, true);
            if ($submitterUrl == $authorUrl && $submitterIp == $authorIp) {
                $counter++;
            }
        }
        if ($counter >= $numberApproved) {
            $postData['post_status'] = 'publish';
        }
    }
    $newPost = wp_insert_post($postData);
    if ($newPost) {
        wp_set_post_tags($newPost, $tags);
        wp_set_post_categories($newPost, array($category));
        if ($usp_options['usp_email_alerts'] == true) {
            $to = $usp_options['usp_email_address'];
            if ($to !== '') {
                $subject = 'New user-submitted post!';
                $message = 'Hey, there is a new user-submitted post waiting for you.';
                wp_mail($to, $subject, $message);
            }
        }
        if (!function_exists('media_handle_upload')) {
            require_once ABSPATH . '/wp-admin/includes/media.php';
            require_once ABSPATH . '/wp-admin/includes/file.php';
            require_once ABSPATH . '/wp-admin/includes/image.php';
        }
        $attachmentIds = array();
        $imageCounter = 0;
        if ($fileData !== '') {
            for ($i = 0; $i < count($fileData['name']); $i++) {
                $imageInfo = @getimagesize($fileData['tmp_name'][$i]);
                if (false === $imageInfo || !usp_imageIsRightSize($imageInfo[0], $imageInfo[1])) {
                    continue;
                }
                $key = "public-submission-attachment-{$i}";
                $_FILES[$key] = array();
                $_FILES[$key]['name'] = $fileData['name'][$i];
                $_FILES[$key]['tmp_name'] = $fileData['tmp_name'][$i];
                $_FILES[$key]['type'] = $fileData['type'][$i];
                $_FILES[$key]['error'] = $fileData['error'][$i];
                $_FILES[$key]['size'] = $fileData['size'][$i];
                $attachmentId = media_handle_upload($key, $newPost);
                if (!is_wp_error($attachmentId) && wp_attachment_is_image($attachmentId)) {
                    $attachmentIds[] = $attachmentId;
                    add_post_meta($newPost, $usp_post_meta_Image, wp_get_attachment_url($attachmentId));
                    $imageCounter++;
                } else {
                    wp_delete_attachment($attachmentId);
                }
                if ($imageCounter == $usp_options['max-images']) {
                    break;
                }
            }
        }
        if (count($attachmentIds) < $usp_options['min-images']) {
            foreach ($attachmentIds as $idToDelete) {
                wp_delete_attachment($idToDelete);
            }
//.........这里部分代码省略.........
开发者ID:klebercarvalho,项目名称:demo,代码行数:101,代码来源:user-submitted-posts-bkp.php


示例14: tag_post_image_luminance

function tag_post_image_luminance($post_id)
{
    $threshold = 128;
    $tags = array();
    // Get the image data
    $image_src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'small');
    $image_url = $image_src[0];
    if (empty($image_url)) {
        return $post_id;
    }
    // detect luminence value
    $luminance = calculate_image_luminance($image_url);
    $tags = wp_get_post_tags($post_id, array('fields' => 'names'));
    if ($luminance < $threshold) {
        $tags[] = 'dark';
    } elseif (false !== ($key = array_search('dark', $messages))) {
        unset($tags[$key]);
    }
    // Set a tag class
    if (!empty($tags)) {
        wp_set_post_tags($post_id, $tags, true);
    }
    return $post_id;
}
开发者ID:emutavchi,项目名称:WebKitForWayland,代码行数:24,代码来源:functions.php


示例15: test_get_objects_in_term_should_return_objects_ids

 public function test_get_objects_in_term_should_return_objects_ids()
 {
     $tag_id = $this->factory->tag->create();
     $cat_id = $this->factory->category->create();
     $posts_with_tag = array();
     $posts_with_category = array();
     for ($i = 0; $i < 3; $i++) {
         $post_id = $this->factory->post->create();
         wp_set_post_tags($post_id, array($tag_id));
         $posts_with_tag[] = $post_id;
     }
     for ($i = 0; $i < 3; $i++) {
         $post_id = $this->factory->post->create();
         wp_set_post_categories($post_id, array($cat_id));
         $posts_with_category[] = $post_id;
     }
     for ($i = 0; $i < 3; $i++) {
         $this->factory->post->create();
     }
     $posts_with_terms = array_merge($posts_with_tag, $posts_with_category);
     $this->assertEquals($posts_with_tag, get_objects_in_term($tag_id, 'post_tag'));
     $this->assertEquals($posts_with_category, get_objects_in_term($cat_id, 'category'));
     $this->assertEquals($posts_with_terms, get_objects_in_term(array($tag_id, $cat_id), array('post_tag', 'category')));
     $this->assertEquals(array_reverse($posts_with_tag), get_objects_in_term($tag_id, 'post_tag', array('order' => 'desc')));
 }
开发者ID:plis197715,项目名称:wordpress-develop,代码行数:25,代码来源:taxonomy.php


示例16: wp_insert_attachment


//.........这里部分代码省略.........
        $post_name = sanitize_title($post_name);
    }
    // expected_slashed ($post_name)
    $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent);
    if (empty($post_date)) {
        $post_date = current_time('mysql');
    }
    if (empty($post_date_gmt)) {
        $post_date_gmt = current_time('mysql', 1);
    }
    if (empty($post_modified)) {
        $post_modified = $post_date;
    }
    if (empty($post_modified_gmt)) {
        $post_modified_gmt = $post_date_gmt;
    }
    if (empty($comment_status)) {
        if ($update) {
            $comment_status = 'closed';
        } else {
            $comment_status = get_option('default_comment_status');
        }
    }
    if (empty($ping_status)) {
        $ping_status = get_option('default_ping_status');
    }
    if (isset($to_ping)) {
        $to_ping = preg_replace('|\\s+|', "\n", $to_ping);
    } else {
        $to_ping = '';
    }
    if (isset($post_parent)) {
        $post_parent = (int) $post_parent;
    } else {
        $post_parent = 0;
    }
    if (isset($menu_order)) {
        $menu_order = (int) $menu_order;
    } else {
        $menu_order = 0;
    }
    if (!isset($post_password)) {
        $post_password = '';
    }
    if (!isset($pinged)) {
        $pinged = '';
    }
    // expected_slashed (everything!)
    $data = compact(array('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type', 'guid'));
    $data = wp_unslash($data);
    if ($update) {
        $wpdb->update($wpdb->posts, $data, array('ID' => $post_ID));
    } else {
        // If there is a suggested ID, use it if not already present
        if (!empty($import_id)) {
            $import_id = (int) $import_id;
            if (!$wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE ID = %d", $import_id))) {
                $data['ID'] = $import_id;
            }
        }
        $wpdb->insert($wpdb->posts, $data);
        $post_ID = (int) $wpdb->insert_id;
    }
    if (empty($post_name)) {
        $post_name = sanitize_title($post_title, $post_ID);
        $wpdb->update($wpdb->posts, compact("post_name"), array('ID' => $post_ID));
    }
    if (is_object_in_taxonomy($post_type, 'category')) {
        wp_set_post_categories($post_ID, $post_category);
    }
    if (isset($tags_input) && is_object_in_taxonomy($post_type, 'post_tag')) {
        wp_set_post_tags($post_ID, $tags_input);
    }
    // support for all custom taxonomies
    if (!empty($tax_input)) {
        foreach ($tax_input as $taxonomy => $tags) {
            $taxonomy_obj = get_taxonomy($taxonomy);
            if (is_array($tags)) {
                // array = hierarchical, string = non-hierarchical.
                $tags = array_filter($tags);
            }
            if (current_user_can($taxonomy_obj->cap->assign_terms)) {
                wp_set_post_terms($post_ID, $tags, $taxonomy);
            }
        }
    }
    if ($file) {
        update_attached_file($post_ID, $file);
    }
    clean_post_cache($post_ID);
    if (!empty($context)) {
        add_post_meta($post_ID, '_wp_attachment_context', $context, true);
    }
    if ($update) {
        do_action('edit_attachment', $post_ID);
    } else {
        do_action('add_attachment', $post_ID);
    }
    return $post_ID;
}
开发者ID:palimadra,项目名称:bubblegraphics-wpsite,代码行数:101,代码来源:post.php


示例17: maybe_update_post_fields

 /**
  * Loop through the fields being edited and if they include Post fields, update the Entry's post object
  *
  * @param array $form Gravity Forms form
  *
  * @return void
  */
 function maybe_update_post_fields($form)
 {
     $post_id = $this->entry['post_id'];
     // Security check
     if (false === GVCommon::has_cap('edit_post', $post_id)) {
         do_action('gravityview_log_error', 'The current user does not have the ability to edit Post #' . $post_id);
         return;
     }
     $update_entry = false;
     $updated_post = $original_post = get_post($post_id);
     foreach ($this->entry as $field_id => $value) {
         //todo: only run through the edit entry configured fields
         $field = RGFormsModel::get_field($form, $field_id);
         if (class_exists('GF_Fields')) {
             $field = GF_Fields::create($field);
         }
         if (GFCommon::is_post_field($field)) {
             // Get the value of the field, including $_POSTed value
             $value = RGFormsModel::get_field_value($field);
             // Convert the field object in 1.9 to an array for backward compatibility
             $field_array = GVCommon::get_field_array($field);
             switch ($field_array['type']) {
                 case 'post_title':
                 case 'post_content':
                 case 'post_excerpt':
                     $updated_post->{$field_array['type']} = $value;
                     break;
                 case 'post_tags':
                     wp_set_post_tags($post_id, $value, false);
                     break;
                 case 'post_category':
                     $categories = is_array($value) ? array_values($value) : (array) $value;
                     $categories = array_filter($categories);
                     wp_set_post_categories($post_id, $categories, false);
                     // prepare value to be saved in the entry
                     $field = GFCommon::add_categories_as_choices($field, '');
                     // if post_category is type checkbox, then value is an array of inputs
                     if (isset($value[strval($field_id)])) {
                         foreach ($value as $input_id => $val) {
                             $input_name = 'input_' . str_replace('.', '_', $input_id);
                             $this->entry[strval($input_id)] = RGFormsModel::prepare_value($form, $field, $val, $input_name, $this->entry['id']);
                         }
                     } else {
                         $input_name = 'input_' . str_replace('.', '_', $field_id);
                         $this->entry[strval($field_id)] = RGFormsModel::prepare_value($form, $field, $value, $input_name, $this->entry['id']);
                     }
                     break;
                 case 'post_custom_field':
                     $input_type = RGFormsModel::get_input_type($field);
                     $custom_field_name = $field_array['postCustomFieldName'];
                     // Only certain custom field types are supported
                     if (!in_array($input_type, array('list', 'fileupload'))) {
                         update_post_meta($post_id, $custom_field_name, $value);
                     }
                     break;
                 case 'post_image':
                     $value = '';
                     break;
             }
             //ignore fields that have not changed
             if ($value === rgget((string) $field_id, $this->entry)) {
                 continue;
             }
             // update entry
             if ('post_category' !== $field->type) {
                 $this->entry[strval($field_id)] = $value;
             }
             $update_entry = true;
         }
     }
     if ($update_entry) {
         $return_entry = GFAPI::update_entry($this->entry);
         if (is_wp_error($return_entry)) {
             do_action('gravityview_log_error', 'Updating the entry post fields failed', $return_entry);
         } else {
             do_action('gravityview_log_debug', 'Updating the entry post fields for post #' . $post_id . ' succeeded');
         }
     }
     $return_post = wp_update_post($updated_post, true);
     if (is_wp_error($return_post)) {
         do_action('gravityview_log_error', 'Updating the post content failed', $return_post);
     } else {
         do_action('gravityview_log_debug', 'Updating the post content for post #' . $post_id . ' succeeded');
     }
 }
开发者ID:hansstam,

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_set_post_terms函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_set_post_lock函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap