本文整理汇总了PHP中set_post_format函数的典型用法代码示例。如果您正苦于以下问题:PHP set_post_format函数的具体用法?PHP set_post_format怎么用?PHP set_post_format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_post_format函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: A_insert_post_format
function A_insert_post_format($post_ID, $ablog, $item)
{
if (!empty($ablog['postformat'])) {
set_post_format($post_ID, $ablog['postformat']);
} else {
set_post_format($post_ID, 'standard');
}
}
示例2: wpSetUpBeforeClass
public static function wpSetUpBeforeClass(WP_UnitTest_Factory $factory)
{
self::$page_on_front = $factory->post->create_and_get(array('post_type' => 'page', 'post_name' => 'page-on-front'));
self::$page_for_posts = $factory->post->create_and_get(array('post_type' => 'page', 'post_name' => 'page-for-posts'));
self::$page = $factory->post->create_and_get(array('post_type' => 'page', 'post_name' => 'page-name'));
add_post_meta(self::$page->ID, '_wp_page_template', 'templates/page.php');
self::$post = $factory->post->create_and_get(array('post_type' => 'post', 'post_name' => 'post-name', 'post_date' => '1984-02-25 12:34:56'));
set_post_format(self::$post, 'quote');
}
示例3: press_it
/**
* Press It form handler.
*
* @package WordPress
* @subpackage Press_This
* @since 2.6.0
*
* @return int Post ID
*/
function press_it() {
$post = get_default_post_to_edit();
$post = get_object_vars($post);
$post_ID = $post['ID'] = (int) $_POST['post_id'];
if ( !current_user_can('edit_post', $post_ID) )
wp_die(__('You are not allowed to edit this post.'));
$post['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : '';
$post['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : '';
$post['post_title'] = isset($_POST['title']) ? $_POST['title'] : '';
$content = isset($_POST['content']) ? $_POST['content'] : '';
$upload = false;
if ( !empty($_POST['photo_src']) && current_user_can('upload_files') ) {
foreach( (array) $_POST['photo_src'] as $key => $image) {
// see if files exist in content - we don't want to upload non-used selected files.
if ( strpos($_POST['content'], htmlspecialchars($image)) !== false ) {
$desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : '';
$upload = media_sideload_image($image, $post_ID, $desc);
// Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes
if ( !is_wp_error($upload) )
$content = preg_replace('/<img ([^>]*)src=\\\?(\"|\')'.preg_quote(htmlspecialchars($image), '/').'\\\?(\2)([^>\/]*)\/*>/is', $upload, $content);
}
}
}
// set the post_content and status
$post['post_content'] = $content;
if ( isset( $_POST['publish'] ) && current_user_can( 'publish_posts' ) )
$post['post_status'] = 'publish';
elseif ( isset( $_POST['review'] ) )
$post['post_status'] = 'pending';
else
$post['post_status'] = 'draft';
// error handling for media_sideload
if ( is_wp_error($upload) ) {
wp_delete_post($post_ID);
wp_die($upload);
} else {
// Post formats
if ( isset( $_POST['post_format'] ) ) {
if ( current_theme_supports( 'post-formats', $_POST['post_format'] ) )
set_post_format( $post_ID, $_POST['post_format'] );
elseif ( '0' == $_POST['post_format'] )
set_post_format( $post_ID, false );
}
$post_ID = wp_update_post($post);
}
return $post_ID;
}
示例4: save_post
/**
* AJAX handler for saving the post as draft or published.
*
* @since 4.2.0
* @access public
*/
public function save_post()
{
if (empty($_POST['post_ID']) || !($post_id = (int) $_POST['post_ID'])) {
wp_send_json_error(array('errorMessage' => __('Missing post ID.')));
}
if (empty($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'update-post_' . $post_id) || !current_user_can('edit_post', $post_id)) {
wp_send_json_error(array('errorMessage' => __('Invalid post.')));
}
$post = array('ID' => $post_id, 'post_title' => !empty($_POST['post_title']) ? sanitize_text_field(trim($_POST['post_title'])) : '', 'post_content' => !empty($_POST['post_content']) ? trim($_POST['post_content']) : '', 'post_type' => 'post', 'post_status' => 'draft', 'post_format' => !empty($_POST['post_format']) ? sanitize_text_field($_POST['post_format']) : '', 'tax_input' => !empty($_POST['tax_input']) ? $_POST['tax_input'] : array(), 'post_category' => !empty($_POST['post_category']) ? $_POST['post_category'] : array());
if (!empty($_POST['post_status']) && 'publish' === $_POST['post_status']) {
if (current_user_can('publish_posts')) {
$post['post_status'] = 'publish';
} else {
$post['post_status'] = 'pending';
}
}
$post['post_content'] = $this->side_load_images($post_id, $post['post_content']);
$updated = wp_update_post($post, true);
if (is_wp_error($updated)) {
wp_send_json_error(array('errorMessage' => $updated->get_error_message()));
} else {
if (isset($post['post_format'])) {
if (current_theme_supports('post-formats', $post['post_format'])) {
set_post_format($post_id, $post['post_format']);
} elseif ($post['post_format']) {
set_post_format($post_id, false);
}
}
$forceRedirect = false;
if ('publish' === get_post_status($post_id)) {
$redirect = get_post_permalink($post_id);
} elseif (isset($_POST['pt-force-redirect']) && $_POST['pt-force-redirect'] === 'true') {
$forceRedirect = true;
$redirect = get_edit_post_link($post_id, 'js');
} else {
$redirect = false;
}
/**
* Filter the URL to redirect to when Press This saves.
*
* @since 4.2.0
*
* @param string $url Redirect URL. If `$status` is 'publish', this will be the post permalink.
* Otherwise, the default is false resulting in no redirect.
* @param int $post_id Post ID.
* @param string $status Post status.
*/
$redirect = apply_filters('press_this_save_redirect', $redirect, $post_id, $post['post_status']);
if ($redirect) {
wp_send_json_success(array('redirect' => $redirect, 'force' => $forceRedirect));
} else {
wp_send_json_success(array('postSaved' => true));
}
}
}
示例5: press_it
/**
* Press It form handler.
*
* @package WordPress
* @subpackage Press_This
* @since 2.6.0
*
* @return int Post ID
*/
function press_it()
{
// define some basic variables
$quick = array();
$quick['post_status'] = 'draft';
// set as draft first
$quick['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : null;
$quick['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : null;
$quick['post_title'] = trim($_POST['title']) != '' ? $_POST['title'] : ' ';
$quick['post_content'] = isset($_POST['post_content']) ? $_POST['post_content'] : '';
// insert the post with nothing in it, to get an ID
$post_ID = wp_insert_post($quick, true);
if (is_wp_error($post_ID)) {
wp_die($post_ID);
}
$content = isset($_POST['content']) ? $_POST['content'] : '';
$upload = false;
if (!empty($_POST['photo_src']) && current_user_can('upload_files')) {
foreach ((array) $_POST['photo_src'] as $key => $image) {
// see if files exist in content - we don't want to upload non-used selected files.
if (strpos($_POST['content'], htmlspecialchars($image)) !== false) {
$desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : '';
$upload = media_sideload_image($image, $post_ID, $desc);
// Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes
if (!is_wp_error($upload)) {
$content = preg_replace('/<img ([^>]*)src=\\\\?(\\"|\')' . preg_quote(htmlspecialchars($image), '/') . '\\\\?(\\2)([^>\\/]*)\\/*>/is', $upload, $content);
}
}
}
}
// set the post_content and status
$quick['post_status'] = isset($_POST['publish']) ? 'publish' : 'draft';
$quick['post_content'] = $content;
// error handling for media_sideload
if (is_wp_error($upload)) {
wp_delete_post($post_ID);
wp_die($upload);
} else {
// Post formats
if (current_theme_supports('post-formats') && isset($_POST['post_format'])) {
$post_formats = get_theme_support('post-formats');
if (is_array($post_formats)) {
$post_formats = $post_formats[0];
if (in_array($_POST['post_format'], $post_formats)) {
set_post_format($post_ID, $_POST['post_format']);
} elseif ('0' == $_POST['post_format']) {
set_post_format($post_ID, false);
}
}
}
$quick['ID'] = $post_ID;
wp_update_post($quick);
}
return $post_ID;
}
示例6: create_post_type
function create_post_type()
{
$section_labels = array('name' => __('Page Sections'), 'singular_name' => __('Page Section'), 'add_new_item' => __('Add new Page Section'));
$section_args = array('labels' => $section_labels, 'public' => true, 'has_archive' => false, 'rewrite' => array('slug' => 'sections'), 'menu_position' => 9, 'menu_icon' => 'dashicons-editor-alignleft', 'supports' => ['title', 'editor']);
register_post_type('section', $section_args);
$sermon_labels = array('name' => __('Sermons'), 'singular_name' => __('Sermon'), 'add_new_item' => __('Upload New Sermon'));
$sermon_args = array('labels' => $sermon_labels, 'public' => true, 'has_archive' => true, 'rewrite' => array('slug' => 'sermons'), 'menu_position' => 5, 'menu_icon' => 'dashicons-megaphone', 'supports' => ['title', 'editor', 'thumbnail']);
register_post_type('sermon', $sermon_args);
set_post_format('sermon', 'audio');
$event_labels = array('name' => __('Events'), 'singular_name' => __('Event'), 'add_new_item' => __('Add New Event'));
$event_args = array('labels' => $event_labels, 'public' => true, 'has_archive' => true, 'rewrite' => array('slug' => 'events'), 'menu_position' => 5, 'menu_icon' => 'dashicons-location-alt', 'supports' => ['title', 'editor', 'thumbnail']);
register_post_type('event', $event_args);
}
示例7: save
public function save($item)
{
global $post;
$post = array();
$metas = array();
global $ph_migrate_field_handlers;
$field_handlers = array();
$class = get_class($this);
while (FALSE != $class) {
if (isset($ph_migrate_field_handlers[$class])) {
$field_handlers = array_merge($field_handlers, $ph_migrate_field_handlers[$class]);
}
$class = get_parent_class($class);
}
$postprocess = array();
foreach ($item as $property => $value) {
$handled = false;
foreach ($field_handlers as $key => $callback) {
if (0 === strpos($property, $key)) {
$handled = true;
if (!isset($postprocess[$key])) {
$postprocess[$key] = array('callback' => $callback, 'fields' => array());
}
$postprocess[$key]['fields'][$property] = $value;
}
}
if (!$handled) {
$post[$property] = $value;
}
}
if (isset($post['ID'])) {
wp_update_post($post);
if (isset($post['post_format'])) {
set_post_format($post['ID'], $post['post_format']);
}
$id = $post['ID'];
ph_migrate_statistics_increment("Posts (Type:" . $post['post_type'] . ") updated", 1);
} else {
$id = wp_insert_post($post);
$post['ID'] = $id;
if (isset($post['post_format'])) {
set_post_format($post['ID'], $post['post_format']);
}
ph_migrate_statistics_increment("Posts (Type:" . $post['post_type'] . ") created", 1);
}
foreach ($postprocess as $key => $dataset) {
$callback = $dataset['callback'];
$callback($post, $dataset['fields']);
}
return $id;
}
示例8: data_template_requests
public function data_template_requests()
{
$post = self::factory()->post->create_and_get(array('post_type' => 'post', 'post_name' => 'post-name'));
set_post_format($post, 'quote');
$page = self::factory()->post->create_and_get(array('post_type' => 'page', 'post_name' => 'page-name'));
add_post_meta($page->ID, '_wp_page_template', 'templates/page.php');
$data = array();
// Single post embed
$data[] = array(get_post_embed_url($post), array('embed-post-quote.php', 'embed-post.php', 'embed.php', 'single-post-post-name.php', 'single-post.php', 'single.php', 'singular.php'));
// Search
$data[] = array(add_query_arg('s', 'foo', home_url()), array('search.php'));
// Single page
$data[] = array(get_permalink($page), array('templates/page.php', 'page-page-name.php', "page-{$page->ID}.php", 'page.php', 'singular.php'));
// Single post
$data[] = array(get_permalink($post), array('single-post-post-name.php', 'single-post.php', 'single.php', 'singular.php'));
return $data;
}
示例9: test_has_format
function test_has_format()
{
$post_id = $this->factory->post->create();
$this->assertFalse(has_post_format('standard', $post_id));
$this->assertFalse(has_post_format('', $post_id));
$result = set_post_format($post_id, 'aside');
$this->assertNotInstanceOf('WP_Error', $result);
$this->assertInternalType('array', $result);
$this->assertEquals(1, count($result));
$this->assertTrue(has_post_format('aside', $post_id));
$result = set_post_format($post_id, 'standard');
$this->assertNotInstanceOf('WP_Error', $result);
$this->assertInternalType('array', $result);
$this->assertEquals(0, count($result));
// Standard is a special case. It shows as false when set.
$this->assertFalse(has_post_format('standard', $post_id));
// Dummy format type
$this->assertFalse(has_post_format('dummy', $post_id));
// Dummy post id
$this->assertFalse(has_post_format('aside', 12345));
}
示例10: apply
function apply($postid, $postdetails)
{
if ($this->PostFormat != 'standard') {
set_post_format($postid, $this->PostFormat);
}
}
示例11: save_post_actions
//.........这里部分代码省略.........
foreach ($translations as $t) {
if ($original_post_id != $t->element_id) {
$this->copy_custom_fields($original_post_id, $t->element_id);
}
}
}
}
//sync posts stickiness
if (isset($post_vars['post_type']) && $post_vars['post_type'] == 'post' && isset($post_vars['action']) && $post_vars['action'] != 'post-quickpress-publish' && $this->settings['sync_sticky_flag']) {
//not for quick press
remove_filter('option_sticky_posts', array($this, 'option_sticky_posts'));
// remove filter used to get language relevant stickies. get them all
$sticky_posts = get_option('sticky_posts');
add_filter('option_sticky_posts', array($this, 'option_sticky_posts'));
// add filter back
// get ids of the translations
if ($trid) {
$translations = $wpdb->get_col($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d", $trid));
} else {
$translations = array();
}
if (isset($post_vars['sticky']) && $post_vars['sticky'] == 'sticky') {
$sticky_posts = array_unique(array_merge($sticky_posts, $translations));
} else {
//makes sure translations are not set to sticky if this posts switched from sticky to not-sticky
$sticky_posts = array_diff($sticky_posts, $translations);
}
update_option('sticky_posts', $sticky_posts);
}
//sync private flag
if ($this->settings['sync_private_flag']) {
if ($post_status == 'private' && (empty($post_vars['original_post_status']) || $post_vars['original_post_status'] != 'private')) {
if ($translated_element_id && is_array($translated_element_id)) {
foreach ($translated_element_id as $tp) {
if ($tp != $post_id) {
$wpdb->update($wpdb->posts, array('post_status' => 'private'), array('ID' => $tp));
}
}
}
} elseif ($post_status != 'private' && isset($post_vars['original_post_status']) && $post_vars['original_post_status'] == 'private') {
if ($translated_element_id && is_array($translated_element_id)) {
foreach ($translated_element_id as $tp) {
if ($tp != $post_id) {
$wpdb->update($wpdb->posts, array('post_status' => $post_status), array('ID' => $tp));
}
}
}
}
}
//sync post format
if ($this->settings['sync_post_format'] && function_exists('set_post_format')) {
$format = get_post_format($post_id);
if ($translated_element_id && is_array($translated_element_id)) {
foreach ($translated_element_id as $tp) {
if ($tp != $post_id) {
set_post_format($tp, $format);
}
}
}
}
// sync post dates
if (!empty($this->settings['sync_post_date'])) {
if ($language_code == $default_language) {
if ($translated_element_id && is_array($translated_element_id)) {
$post_date = $wpdb->get_var($wpdb->prepare("SELECT post_date FROM {$wpdb->posts} WHERE ID=%d", $post_id));
foreach ($translated_element_id as $tp) {
if ($tp != $post_id) {
$wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => get_gmt_from_date($post_date)), array('ID' => $tp));
}
}
}
} else {
if (!is_null($trid)) {
$source_lang = isset($_GET['source_lang']) ? $_GET['source_lang'] : $default_language;
$original_id = $wpdb->get_var($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d AND language_code=%s", $trid, $source_lang));
if (!$original_id) {
global $post;
if (isset($post->ID)) {
$original_id = $post->ID;
}
}
if (isset($original_id)) {
$post_date = $wpdb->get_var($wpdb->prepare("SELECT post_date FROM {$wpdb->posts} WHERE ID=%d", $original_id));
$wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => get_gmt_from_date($post_date)), array('ID' => $post_id));
}
}
}
}
if (isset($post_vars['icl_tn_note'])) {
update_post_meta($post_id, '_icl_translator_note', $post_vars['icl_tn_note']);
}
//fix guid
if ($this->settings['language_negotiation_type'] == 2 && $this->get_current_language() != $default_language) {
$guid = $this->convert_url(get_post_field('guid', $post_id));
$wpdb->update($wpdb->posts, array('guid' => $guid), array('id' => $post_id));
}
require_once ICL_PLUGIN_PATH . '/inc/cache.php';
icl_cache_clear($post_vars['post_type'] . 's_per_language', true);
wp_defer_term_counting(false);
}
示例12: get_default_post_to_edit
/**
* Default post information to use when populating the "Write Post" form.
*
* @since 2.0.0
*
* @param string $post_type Optional. A post type string. Default 'post'.
* @param bool $create_in_db Optional. Whether to insert the post into database. Default false.
* @return WP_Post Post object containing all the default post data as attributes
*/
function get_default_post_to_edit($post_type = 'post', $create_in_db = false)
{
$post_title = '';
if (!empty($_REQUEST['post_title'])) {
$post_title = esc_html(wp_unslash($_REQUEST['post_title']));
}
$post_content = '';
if (!empty($_REQUEST['content'])) {
$post_content = esc_html(wp_unslash($_REQUEST['content']));
}
$post_excerpt = '';
if (!empty($_REQUEST['excerpt'])) {
$post_excerpt = esc_html(wp_unslash($_REQUEST['excerpt']));
}
if ($create_in_db) {
$post_id = wp_insert_post(array('post_title' => __('Auto Draft'), 'post_type' => $post_type, 'post_status' => 'auto-draft'));
$post = get_post($post_id);
if (current_theme_supports('post-formats') && post_type_supports($post->post_type, 'post-formats') && get_option('default_post_format')) {
set_post_format($post, get_option('default_post_format'));
}
} else {
$post = new stdClass();
$post->ID = 0;
$post->post_author = '';
$post->post_date = '';
$post->post_date_gmt = '';
$post->post_password = '';
$post->post_name = '';
$post->post_type = $post_type;
$post->post_status = 'draft';
$post->to_ping = '';
$post->pinged = '';
$post->comment_status = get_default_comment_status($post_type);
$post->ping_status = get_default_comment_status($post_type, 'pingback');
$post->post_pingback = get_option('default_pingback_flag');
$post->post_category = get_option('default_category');
$post->page_template = 'default';
$post->post_parent = 0;
$post->menu_order = 0;
$post = new WP_Post($post);
}
/**
* Filters the default post content initially used in the "Write Post" form.
*
* @since 1.5.0
*
* @param string $post_content Default post content.
* @param WP_Post $post Post object.
*/
$post->post_content = apply_filters('default_content', $post_content, $post);
/**
* Filters the default post title initially used in the "Write Post" form.
*
* @since 1.5.0
*
* @param string $post_title Default post title.
* @param WP_Post $post Post object.
*/
$post->post_title = apply_filters('default_title', $post_title, $post);
/**
* Filters the default post excerpt initially used in the "Write Post" form.
*
* @since 1.5.0
*
* @param string $post_excerpt Default post excerpt.
* @param WP_Post $post Post object.
*/
$post->post_excerpt = apply_filters('default_excerpt', $post_excerpt, $post);
return $post;
}
示例13: process
//.........这里部分代码省略.........
}
}
}
// insert article being imported
if ($this->options['is_fast_mode']) {
foreach (array('transition_post_status', 'save_post', 'pre_post_update', 'add_attachment', 'edit_attachment', 'edit_post', 'post_updated', 'wp_insert_post', 'save_post_' . $post_type[$i]) as $act) {
remove_all_actions($act);
}
}
if (!in_array($this->options['custom_type'], array('import_users'))) {
if (empty($articleData['ID'])) {
$logger and call_user_func($logger, sprintf(__('<b>CREATING</b> `%s` `%s`', 'wp_all_import_plugin'), $articleData['post_title'], $custom_type_details->labels->singular_name));
} else {
$logger and call_user_func($logger, sprintf(__('<b>UPDATING</b> `%s` `%s`', 'wp_all_import_plugin'), $articleData['post_title'], $custom_type_details->labels->singular_name));
}
$pid = wp_insert_post($articleData, true);
} else {
$pid = empty($articleData['ID']) ? wp_insert_user($articleData) : wp_update_user($articleData);
$articleData['post_title'] = $articleData['user_login'];
}
if (is_wp_error($pid)) {
$logger and call_user_func($logger, __('<b>ERROR</b>', 'wp_all_import_plugin') . ': ' . $pid->get_error_message());
$logger and !$is_cron and PMXI_Plugin::$session->errors++;
$skipped++;
} else {
if ("manual" != $this->options['duplicate_matching'] or empty($articleData['ID'])) {
// associate post with import
$postRecord->isEmpty() and $postRecord->set(array('post_id' => $pid, 'import_id' => $this->id, 'unique_key' => $unique_keys[$i], 'product_key' => ($post_type[$i] == "product" and PMXI_Admin_Addons::get_addon('PMWI_Plugin')) ? $addons_data['PMWI_Plugin']['single_product_ID'][$i] : ''))->insert();
$postRecord->set(array('iteration' => $this->iteration))->update();
$logger and call_user_func($logger, sprintf(__('Associate post `%s` with current import ...', 'wp_all_import_plugin'), $articleData['post_title']));
}
// [post format]
if (current_theme_supports('post-formats') && post_type_supports($post_type[$i], 'post-formats')) {
set_post_format($pid, "xpath" == $this->options['post_format'] ? $post_format[$i] : $this->options['post_format']);
$logger and call_user_func($logger, sprintf(__('Associate post `%s` with post format %s ...', 'wp_all_import_plugin'), $articleData['post_title'], "xpath" == $this->options['post_format'] ? $post_format[$i] : $this->options['post_format']));
}
// [/post format]
// [addons import]
// prepare data for import
$importData = array('pid' => $pid, 'i' => $i, 'import' => $this, 'articleData' => $articleData, 'xml' => $xml, 'is_cron' => $is_cron, 'logger' => $logger, 'xpath_prefix' => $xpath_prefix, 'post_type' => $post_type[$i]);
$import_functions = apply_filters('wp_all_import_addon_import', array());
// deligate operation to addons
foreach (PMXI_Admin_Addons::get_active_addons() as $class) {
if (class_exists($class)) {
if (method_exists($addons[$class], 'import')) {
$addons[$class]->import($importData);
}
} else {
if (!empty($import_functions[$class])) {
if (is_array($import_functions[$class]) and is_callable($import_functions[$class]) or !is_array($import_functions[$class]) and function_exists($import_functions[$class])) {
call_user_func($import_functions[$class], $importData, $addons_data[$class]);
}
}
}
}
// [/addons import]
// Page Template
if ('page' == $articleData['post_type'] and wp_all_import_is_update_cf('_wp_page_template', $this->options) and (!empty($this->options['page_template']) or "no" == $this->options['is_multiple_page_template'])) {
update_post_meta($pid, '_wp_page_template', "no" == $this->options['is_multiple_page_template'] ? $page_template[$i] : $this->options['page_template']);
}
// [featured image]
$is_allow_import_images = apply_filters('wp_all_import_is_allow_import_images', false, $articleData['post_type']);
if (!empty($uploads) and false === $uploads['error'] and ($articleData['post_type'] == "product" and class_exists('PMWI_Plugin') or $is_allow_import_images) and (empty($articleData['ID']) or $this->options['update_all_data'] == "yes" or $this->options['update_all_data'] == "no" and $this->options['is_update_images'])) {
if (!empty($images_bundle)) {
$is_show_add_new_images = apply_filters('wp_all_import_is_show_add_new_images', true, $post_type[$i]);
foreach ($images_bundle as $slug => $bundle_data) {
示例14: woo_tumblog_publish
function woo_tumblog_publish($type, $data)
{
global $current_user;
//Gets the current user's info
get_currentuserinfo();
$content_method = get_option('woo_tumblog_content_method');
//Set custom fields
$tumblog_custom_fields = array('video-embed' => 'video-embed', 'quote-copy' => 'quote-copy', 'quote-author' => 'quote-author', 'quote-url' => 'quote-url', 'link-url' => 'link-url', 'image-url' => 'image', 'audio-url' => 'audio');
//get term ids
$tumblog_items = array('articles' => get_option('woo_articles_term_id'), 'images' => get_option('woo_images_term_id'), 'audio' => get_option('woo_audio_term_id'), 'video' => get_option('woo_video_term_id'), 'quotes' => get_option('woo_quotes_term_id'), 'links' => get_option('woo_links_term_id'));
//Set date formatting
$php_formatting = "Y-m-d H:i:s";
//default post settings
$tumbl_note = array();
$tumbl_note['post_status'] = 'publish';
$browser = $_SERVER['HTTP_USER_AGENT'] . "\n\n";
$safari_check = substr_count(strtolower($browser), strtolower('safari'));
if ($safari_check > 0) {
$data['tumblog-content'] = str_ireplace(array('<div>', '</div>'), array('', '<br>'), $data['tumblog-content']);
$data['tumblog-content'] = str_ireplace(array('<br><br><br>'), array('<br><br>'), $data['tumblog-content']);
$data['tumblog-content'] = str_ireplace(array(' '), array(' '), $data['tumblog-content']);
}
//Handle Tumblog Types
switch ($type) {
case 'note':
//Create post object
$tumbl_note['post_title'] = $data['note-title'];
$tumbl_note['post_content'] = $data['tumblog-content'];
// DEPRECATED
// if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($data['tumblog-status'] != '') {
$tumbl_note['post_status'] = $data['tumblog-status'];
}
//Hours and Mins
$original_hours = (int) $data['original-tumblog-hours'];
$original_mins = (int) $data['original-tumblog-mins'];
$original_date = strtotime($data['original-tumblog-date']);
$posted_date = strtotime($data['tumblog-date']);
$note_hours = (int) $data['tumblog-hours'];
if ($note_hours == 0) {
$note_hours = 12;
} elseif ($note_hours >= 24) {
$note_hours = 0;
}
$note_mins = (int) $data['tumblog-mins'];
if ($note_mins == 0) {
$note_mins = 0;
} elseif ($note_mins >= 60) {
$note_mins = 0;
}
//Convert to Y-m-d H:i:s
//if everything is unchanged
if ($note_hours == $original_hours && $note_mins == $original_mins && $posted_date == $original_date) {
$time_now_hours = date_i18n("H");
$time_now_mins = date_i18n("i");
$date_raw = date("Y") . '-' . date("m") . '-' . date("d") . ' ' . $time_now_hours . ':' . $time_now_mins . ':00';
} else {
$date_raw = date("Y", strtotime($data['tumblog-date'])) . '-' . date("m", strtotime($data['tumblog-date'])) . '-' . date("d", strtotime($data['tumblog-date'])) . ' ' . $note_hours . ':' . $note_mins . ':00';
}
$date_formatted = date($php_formatting, strtotime($date_raw));
$tumbl_note['post_date'] = $date_formatted;
// DEPRECATED
// }
$tumbl_note['post_author'] = $current_user->ID;
$tumbl_note['tags_input'] = $data['tumblog-tags'];
// DEPRECATED
// Get Category from Theme Options
/*
if (get_option( 'tumblog_woo_tumblog_upgraded') != 'true') {
$category_id = get_cat_ID( get_option( 'woo_articles_category') );
$categories = array($category_id);
} else {
$categories = array();
}
*/
$categories = array();
$post_cat_array = $data['post_category'];
if (empty($post_cat_array)) {
//Do nothing
} else {
$N = count($post_cat_array);
for ($i = 0; $i < $N; $i++) {
array_push($categories, $post_cat_array[$i]);
}
}
$tumbl_note['post_category'] = $categories;
//Insert the note into the database
$post_id = wp_insert_post($tumbl_note);
// DEPRECATED
// if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
if ($content_method == 'post_format') {
set_post_format($post_id, 'aside');
} else {
//update posts taxonomies
$taxonomy_data = $data['tax_input'];
if (!empty($taxonomy_data)) {
foreach ($taxonomy_data as $taxonomy => $tags) {
$taxonomy_obj = get_taxonomy($taxonomy);
if (is_array($tags)) {
// array = hierarchical, string = non-hierarchical.
//.........这里部分代码省略.........
示例15: _insert_post
//.........这里部分代码省略.........
unset($content_struct['post_thumbnail']);
}
if (isset($post_data['custom_fields'])) {
$this->set_custom_fields($post_ID, $post_data['custom_fields']);
}
if (isset($post_data['terms']) || isset($post_data['terms_names'])) {
$post_type_taxonomies = get_object_taxonomies($post_data['post_type'], 'objects');
// accumulate term IDs from terms and terms_names
$terms = array();
// first validate the terms specified by ID
if (isset($post_data['terms']) && is_array($post_data['terms'])) {
$taxonomies = array_keys($post_data['terms']);
// validating term ids
foreach ($taxonomies as $taxonomy) {
if (!array_key_exists($taxonomy, $post_type_taxonomies)) {
return new IXR_Error(401, __('Sorry, one of the given taxonomies is not supported by the post type.'));
}
if (!current_user_can($post_type_taxonomies[$taxonomy]->cap->assign_terms)) {
return new IXR_Error(401, __('Sorry, you are not allowed to assign a term to one of the given taxonomies.'));
}
$term_ids = $post_data['terms'][$taxonomy];
foreach ($term_ids as $term_id) {
$term = get_term_by('id', $term_id, $taxonomy);
if (!$term) {
return new IXR_Error(403, __('Invalid term ID'));
}
$terms[$taxonomy][] = (int) $term_id;
}
}
}
// now validate terms specified by name
if (isset($post_data['terms_names']) && is_array($post_data['terms_names'])) {
$taxonomies = array_keys($post_data['terms_names']);
foreach ($taxonomies as $taxonomy) {
if (!array_key_exists($taxonomy, $post_type_taxonomies)) {
return new IXR_Error(401, __('Sorry, one of the given taxonomies is not supported by the post type.'));
}
if (!current_user_can($post_type_taxonomies[$taxonomy]->cap->assign_terms)) {
return new IXR_Error(401, __('Sorry, you are not allowed to assign a term to one of the given taxonomies.'));
}
// for hierarchical taxonomies, we can't assign a term when multiple terms in the hierarchy share the same name
$ambiguous_terms = array();
if (is_taxonomy_hierarchical($taxonomy)) {
$tax_term_names = get_terms($taxonomy, array('fields' => 'names', 'hide_empty' => false));
// count the number of terms with the same name
$tax_term_names_count = array_count_values($tax_term_names);
// filter out non-ambiguous term names
$ambiguous_tax_term_counts = array_filter($tax_term_names_count, array($this, '_is_greater_than_one'));
$ambiguous_terms = array_keys($ambiguous_tax_term_counts);
}
$term_names = $post_data['terms_names'][$taxonomy];
foreach ($term_names as $term_name) {
if (in_array($term_name, $ambiguous_terms)) {
return new IXR_Error(401, __('Ambiguous term name used in a hierarchical taxonomy. Please use term ID instead.'));
}
$term = get_term_by('name', $term_name, $taxonomy);
if (!$term) {
// term doesn't exist, so check that the user is allowed to create new terms
if (!current_user_can($post_type_taxonomies[$taxonomy]->cap->edit_terms)) {
return new IXR_Error(401, __('Sorry, you are not allowed to add a term to one of the given taxonomies.'));
}
// create the new term
$term_info = wp_insert_term($term_name, $taxonomy);
if (is_wp_error($term_info)) {
return new IXR_Error(500, $term_info->get_error_message());
}
$terms[$taxonomy][] = (int) $term_info['term_id'];
} else {
$terms[$taxonomy][] = (int) $term->term_id;
}
}
}
}
$post_data['tax_input'] = $terms;
unset($post_data['terms'], $post_data['terms_names']);
} else {
// do not allow direct submission of 'tax_input', clients must use 'terms' and/or 'terms_names'
unset($post_data['tax_input'], $post_data['post_category'], $post_data['tags_input']);
}
if (isset($post_data['post_format'])) {
$format = set_post_format($post_ID, $post_data['post_format']);
if (is_wp_error($format)) {
return new IXR_Error(500, $format->get_error_message());
}
unset($post_data['post_format']);
}
// Handle enclosures
$enclosure = isset($post_data['enclosure']) ? $post_data['enclosure'] : null;
$this->add_enclosure_if_new($post_ID, $enclosure);
$this->attach_uploads($post_ID, $post_data['post_content']);
$post_data = apply_filters('xmlrpc_wp_insert_post_data', $post_data, $content_struct);
$post_ID = wp_insert_post($post_data, true);
if (is_wp_error($post_ID)) {
return new IXR_Error(500, $post_ID->get_error_message());
}
if (!$post_ID) {
return new IXR_Error(401, __('Sorry, your entry could not be posted. Something wrong happened.'));
}
return strval($post_ID);
}