当前位置: 首页>>代码示例>>PHP>>正文


PHP _fix_attachment_links函数代码示例

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


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

示例1: wp_write_post

/**
 * Creates a new post from the "Write Post" form using $_POST information.
 *
 * @since 2.1.0
 *
 * @global WP_User $current_user
 *
 * @return int|WP_Error
 */
function wp_write_post()
{
    if (isset($_POST['post_type'])) {
        $ptype = get_post_type_object($_POST['post_type']);
    } else {
        $ptype = get_post_type_object('post');
    }
    if (!current_user_can($ptype->cap->edit_posts)) {
        if ('page' == $ptype->name) {
            return new WP_Error('edit_pages', __('Sorry, you are not allowed to create pages on this site.'));
        } else {
            return new WP_Error('edit_posts', __('Sorry, you are not allowed to create posts or drafts on this site.'));
        }
    }
    $_POST['post_mime_type'] = '';
    // Clear out any data in internal vars.
    unset($_POST['filter']);
    // Edit don't write if we have a post id.
    if (isset($_POST['post_ID'])) {
        return edit_post();
    }
    if (isset($_POST['visibility'])) {
        switch ($_POST['visibility']) {
            case 'public':
                $_POST['post_password'] = '';
                break;
            case 'password':
                unset($_POST['sticky']);
                break;
            case 'private':
                $_POST['post_status'] = 'private';
                $_POST['post_password'] = '';
                unset($_POST['sticky']);
                break;
        }
    }
    $translated = _wp_translate_postdata(false);
    if (is_wp_error($translated)) {
        return $translated;
    }
    // Create the post.
    $post_ID = wp_insert_post($_POST);
    if (is_wp_error($post_ID)) {
        return $post_ID;
    }
    if (empty($post_ID)) {
        return 0;
    }
    add_meta($post_ID);
    add_post_meta($post_ID, '_edit_last', $GLOBALS['current_user']->ID);
    // Now that we have an ID we can fix any attachment anchor hrefs
    _fix_attachment_links($post_ID);
    wp_set_post_lock($post_ID);
    return $post_ID;
}
开发者ID:nicholasgriffintn,项目名称:WordPress,代码行数:64,代码来源:post.php

示例2: wp_write_post

/**
 * Creates a new post from the "Write Post" form using $_POST information.
 *
 * @since unknown
 *
 * @return unknown
 */
function wp_write_post()
{
    global $user_ID;
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_pages')) {
            return new WP_Error('edit_pages', __('You are not allowed to create pages on this blog.'));
        }
    } else {
        if (!current_user_can('edit_posts')) {
            return new WP_Error('edit_posts', __('You are not allowed to create posts or drafts on this blog.'));
        }
    }
    // Check for autosave collisions
    $temp_id = false;
    if (isset($_POST['temp_ID'])) {
        $temp_id = (int) $_POST['temp_ID'];
        if (!($draft_ids = get_user_option('autosave_draft_ids'))) {
            $draft_ids = array();
        }
        foreach ($draft_ids as $temp => $real) {
            if (time() + $temp > 86400) {
                // 1 day: $temp is equal to -1 * time( then )
                unset($draft_ids[$temp]);
            }
        }
        if (isset($draft_ids[$temp_id])) {
            // Edit, don't write
            $_POST['post_ID'] = $draft_ids[$temp_id];
            unset($_POST['temp_ID']);
            update_user_option($user_ID, 'autosave_draft_ids', $draft_ids);
            return edit_post();
        }
    }
    $translated = _wp_translate_postdata(false);
    if (is_wp_error($translated)) {
        return $translated;
    }
    if (isset($_POST['visibility'])) {
        switch ($_POST['visibility']) {
            case 'public':
                $_POST['post_password'] = '';
                break;
            case 'password':
                unset($_POST['sticky']);
                break;
            case 'private':
                $_POST['post_status'] = 'private';
                $_POST['post_password'] = '';
                unset($_POST['sticky']);
                break;
        }
    }
    // Create the post.
    $post_ID = wp_insert_post($_POST);
    if (is_wp_error($post_ID)) {
        return $post_ID;
    }
    if (empty($post_ID)) {
        return 0;
    }
    add_meta($post_ID);
    // Reunite any orphaned attachments with their parent
    if (!($draft_ids = get_user_option('autosave_draft_ids'))) {
        $draft_ids = array();
    }
    if ($draft_temp_id = (int) array_search($post_ID, $draft_ids)) {
        _relocate_children($draft_temp_id, $post_ID);
    }
    if ($temp_id && $temp_id != $draft_temp_id) {
        _relocate_children($temp_id, $post_ID);
    }
    // Update autosave collision detection
    if ($temp_id) {
        $draft_ids[$temp_id] = $post_ID;
        update_user_option($user_ID, 'autosave_draft_ids', $draft_ids);
    }
    // Now that we have an ID we can fix any attachment anchor hrefs
    _fix_attachment_links($post_ID);
    wp_set_post_lock($post_ID, $GLOBALS['current_user']->ID);
    return $post_ID;
}
开发者ID:schr,项目名称:wordpress,代码行数:88,代码来源:post.php

示例3: etwp_write_post

function etwp_write_post()
{
    global $user_ID;
    /*     if ( isset($_POST['post_type']) )
            $ptype = get_post_type_object($_POST['post_type']);
        else
            $ptype = get_post_type_object('post');
    
        if ( !current_user_can( $ptype->cap->edit_posts ) ) {
            if ( 'page' == $ptype->name )
                return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this site.' ) );
            else
                return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this site.' ) );
        }
    */
    $_POST['post_mime_type'] = '';
    // Clear out any data in internal vars.
    unset($_POST['filter']);
    /*    // Edit don't write if we have a post id.
        if ( isset( $_POST['post_ID'] ) )
            return edit_post();
    */
    if (!isset($_POST['publish'])) {
        $_POST['publish'] = 'publish';
    }
    if (!isset($_POST['visibility'])) {
        $_POST['visibility'] = 'public';
    }
    if (empty($_POST['post_status'])) {
        $_POST['post_status'] = 'publish';
    }
    if (!isset($_POST['comment_status'])) {
        $_POST['comment_status'] = 'open';
    }
    if (isset($_POST['visibility'])) {
        switch ($_POST['visibility']) {
            case 'public':
                $_POST['post_password'] = '';
                break;
            case 'password':
                unset($_POST['sticky']);
                break;
            case 'private':
                $_POST['post_status'] = 'private';
                $_POST['post_password'] = '';
                unset($_POST['sticky']);
                break;
        }
    }
    $translated = et_wp_translate_postdata(false);
    if (is_wp_error($translated)) {
        return $translated;
    }
    // Create the post.
    $post_ID = etwp_insert_post($_POST);
    if (is_wp_error($post_ID)) {
        return $post_ID;
    }
    if (empty($post_ID)) {
        return 0;
    }
    //add_meta( $post_ID );
    //zzcity add
    if (isset($_POST['meta']) && $_POST['meta']) {
        foreach ($_POST['meta'] as $key => $value) {
            add_post_meta($post_ID, $value['key'], $value['value']);
        }
    }
    add_post_meta($post_ID, '_edit_last', $GLOBALS['current_user']->ID);
    // Now that we have an ID we can fix any attachment anchor hrefs
    _fix_attachment_links($post_ID);
    wp_set_post_lock($post_ID);
    return $post_ID;
}
开发者ID:richhu,项目名称:stuqtest,代码行数:74,代码来源:etpost.php

示例4: wp_write_post


//.........这里部分代码省略.........

	if (!empty ( $_POST['post_author_override'] ) ) {
		$_POST['post_author'] = (int) $_POST['post_author_override'];
	} else {
		if (!empty ( $_POST['post_author'] ) ) {
			$_POST['post_author'] = (int) $_POST['post_author'];
		} else {
			$_POST['post_author'] = (int) $_POST['user_ID'];
		}

	}

	if ( $_POST['post_author'] != $_POST['user_ID'] ) {
		if ( 'page' == $_POST['post_type'] ) {
			if ( !current_user_can( 'edit_others_pages' ) )
				return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) );
		} else {
			if ( !current_user_can( 'edit_others_posts' ) )
				return new WP_Error( 'edit_others_posts', __( 'You are not allowed to post as this user.' ) );

		}
	}

	// What to do based on which button they pressed
	if ( isset($_POST['saveasdraft']) && '' != $_POST['saveasdraft'] )
		$_POST['post_status'] = 'draft';
	if ( isset($_POST['saveasprivate']) && '' != $_POST['saveasprivate'] )
		$_POST['post_status'] = 'private';
	if ( isset($_POST['publish']) && ( '' != $_POST['publish'] ) && ( $_POST['post_status'] != 'private' ) )
		$_POST['post_status'] = 'publish';
	if ( isset($_POST['advanced']) && '' != $_POST['advanced'] )
		$_POST['post_status'] = 'draft';

	if ( 'page' == $_POST['post_type'] ) {
		if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) )
			$_POST['post_status'] = 'pending';
	} else {
		if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ) )
			$_POST['post_status'] = 'pending';
	}

	if (!isset( $_POST['comment_status'] ))
		$_POST['comment_status'] = 'closed';

	if (!isset( $_POST['ping_status'] ))
		$_POST['ping_status'] = 'closed';

	foreach ( array ('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
		if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
			$_POST['edit_date'] = '1';
			break;
		}
	}

	if (!empty ( $_POST['edit_date'] ) ) {
		$aa = $_POST['aa'];
		$mm = $_POST['mm'];
		$jj = $_POST['jj'];
		$hh = $_POST['hh'];
		$mn = $_POST['mn'];
		$ss = $_POST['ss'];
		$jj = ($jj > 31 ) ? 31 : $jj;
		$hh = ($hh > 23 ) ? $hh -24 : $hh;
		$mn = ($mn > 59 ) ? $mn -60 : $mn;
		$ss = ($ss > 59 ) ? $ss -60 : $ss;
		$_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
		$_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );
	}

	// Create the post.
	$post_ID = wp_insert_post( $_POST );
	if ( is_wp_error( $post_ID ) )
		return $post_ID;

	if ( empty($post_ID) )
		return 0;

	add_meta( $post_ID );

	// Reunite any orphaned attachments with their parent
	if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
		$draft_ids = array();
	if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )
		_relocate_children( $draft_temp_id, $post_ID );
	if ( $temp_id && $temp_id != $draft_temp_id )
		_relocate_children( $temp_id, $post_ID );

	// Update autosave collision detection
	if ( $temp_id ) {
		$draft_ids[$temp_id] = $post_ID;
		update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
	}

	// Now that we have an ID we can fix any attachment anchor hrefs
	_fix_attachment_links( $post_ID );

	wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID );

	return $post_ID;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:101,代码来源:post.php

示例5: external_image_import_images

function external_image_import_images($post_id, $force = false)
{
    global $pagenow;
    if (get_transient('saving_imported_images_' . $post_id)) {
        return;
    }
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if ($force == false && !wp_verify_nonce($_REQUEST['import_external_images_nonce'], 'import_external_images_nonce')) {
        return;
    }
    if ($force == false && $pagenow != 'post.php') {
        return;
    }
    if ($force == false && $pagenow == 'post.php' && !isset($_POST['import_external_images'])) {
        return;
    }
    if (wp_is_post_revision($post_id)) {
        return;
    }
    $post = get_post($post_id);
    $replaced = false;
    $content = $post->post_content;
    $imgs = external_image_get_img_tags($post_id);
    $count = 0;
    for ($i = 0; $i < EXTERNAL_IMAGES_MAX_COUNT; $i++) {
        if (isset($imgs[$i]) && is_external_file($imgs[$i])) {
            $new_img = external_image_sideload($imgs[$i], $post_id);
            if ($new_img && is_external_file($new_img)) {
                $content = str_replace($imgs[$i], $new_img, $content);
                $replaced = true;
                $count++;
            }
        }
    }
    if ($replaced) {
        set_transient('saving_imported_images_' . $post_id, 'true', 20);
        $update_post = array();
        $update_post['ID'] = $post_id;
        $update_post['post_content'] = $content;
        wp_update_post($update_post);
        _fix_attachment_links($post_id);
        $response = $count;
    } else {
        $response = false;
    }
    return $response;
}
开发者ID:yszar,项目名称:linuxwp,代码行数:49,代码来源:import-external-images.php


注:本文中的_fix_attachment_links函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。