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


PHP WP_Import::process_attachment方法代码示例

本文整理汇总了PHP中WP_Import::process_attachment方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Import::process_attachment方法的具体用法?PHP WP_Import::process_attachment怎么用?PHP WP_Import::process_attachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_Import的用法示例。


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

示例1: process_attachment

 public function process_attachment($post, $url)
 {
     $post_id = $post["import_id"];
     $xml = simplexml_load_file($this->file);
     $result = $xml->xpath("channel/wg_custom_attachment_url/attachment[post_id='{$post_id}']/custom_url");
     $custom_url = $result != false ? $result[0] : '';
     if ($custom_url != '') {
         $url = THEME_CUSTOM_URI . "/demo/" . $custom_url;
     }
     $return = parent::process_attachment($post, $url);
     return $return;
 }
开发者ID:ahoymehearties,项目名称:responsiblegamer,代码行数:12,代码来源:base-importer.php

示例2: process_attachment

 public function process_attachment($postdata, $remote_url)
 {
     $this->updateStats();
     if (count($this->aImported) < 4) {
         if (!$this->origUploadUrl) {
             $tokens = pathinfo($postdata["guid"]);
             $this->origUploadUrl = preg_replace("#/\\d+/\\d+/?#", "", $tokens["dirname"]);
         }
         $current = $this->aCount + 1;
         $remote_url = PE_THEME_URL . "/demo/img{$current}.jpg";
         $postdata["post_name"] = $postdata["post_title"];
         $id = parent::process_attachment($postdata, $remote_url);
         if ($id) {
             $this->aImported[] = $id;
             $this->aCount++;
         }
         return $id;
     }
     return new WP_Error('broke', __("I've fallen and can't get up", 'Pixelentity Theme/Plugin'));
 }
开发者ID:JeffreyBue,项目名称:jb,代码行数:20,代码来源:PeThemeImporter.php

示例3: om_ajax_import_tool

function om_ajax_import_tool()
{
    if (!current_user_can('manage_options')) {
        die;
    }
    if (get_magic_quotes_gpc()) {
        $_POST = stripslashes_deep($_POST);
    }
    if (!isset($_POST['om_action'])) {
        die;
    }
    switch ($_POST['om_action']) {
        case 'start':
            $data = array('error' => 0);
            if (!file_exists($GLOBALS['omImportTool']['path'] . $GLOBALS['omImportTool']['wordpress_xml'])) {
                $data['error'] = 1;
                wp_send_json($data);
            }
            if (!class_exists('WXR_Parser')) {
                require $GLOBALS['omImportTool']['path'] . 'includes/parsers.php';
            }
            $parser = new WXR_Parser();
            $import_data = $parser->parse($GLOBALS['omImportTool']['path'] . $GLOBALS['omImportTool']['wordpress_xml']);
            unset($parser);
            if (is_wp_error($import_data)) {
                $data['error'] = 1;
                wp_send_json($data);
            }
            $data['common'] = array('base_url' => esc_url($import_data['base_url']));
            $data['attachments'] = array();
            $author = (int) get_current_user_id();
            foreach ($import_data['posts'] as $post) {
                if ('attachment' == $post['post_type']) {
                    $post_parent = (int) $post['post_parent'];
                    $postdata = array('import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']);
                    $remote_url = !empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
                    // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
                    // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
                    $postdata['upload_date'] = $post['post_date'];
                    if (isset($post['postmeta'])) {
                        foreach ($post['postmeta'] as $meta) {
                            if ($meta['key'] == '_wp_attached_file') {
                                if (preg_match('%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches)) {
                                    $postdata['upload_date'] = $matches[0];
                                }
                                break;
                            }
                        }
                    }
                    $postdata['postmeta'] = $post['postmeta'];
                    $data['attachments'][] = array('data' => $postdata, 'remote_url' => $remote_url);
                }
            }
            $data['last_attachment_index'] = -1;
            $variables_dump = get_option(OM_THEME_PREFIX . 'import_process_data');
            if (!empty($variables_dump) && is_array($variables_dump)) {
                if (isset($variables_dump['last_attachment_index'])) {
                    $data['last_attachment_index'] = $variables_dump['last_attachment_index'];
                }
            }
            wp_send_json($data);
            break;
        case 'process_attachments':
            $ret = array('error' => 0);
            if (isset($_POST['data']['attachments'])) {
                if (!defined('WP_LOAD_IMPORTERS')) {
                    define('WP_LOAD_IMPORTERS', true);
                }
                if (!class_exists('WP_Import')) {
                    // if WP importer doesn't exist
                    $wp_import = $GLOBALS['omImportTool']['path'] . 'includes/wordpress-importer.php';
                    include $wp_import;
                }
                if (class_exists('WP_Importer') && class_exists('WP_Import')) {
                    // check for main import class and wp import class
                    $importer = new WP_Import();
                    $importer->base_url = $_POST['data']['common']['base_url'];
                    $importer->fetch_attachments = true;
                    $variables_dump = get_option(OM_THEME_PREFIX . 'import_process_data');
                    if (!empty($variables_dump) && is_array($variables_dump)) {
                        $importer->post_orphans = $variables_dump['post_orphans'];
                        $importer->processed_posts = $variables_dump['processed_posts'];
                        $importer->url_remap = $variables_dump['url_remap'];
                    }
                    $last_attachment_index = $_POST['data']['first_attachment_index'];
                    foreach ($_POST['data']['attachments'] as $attachment) {
                        $post = $attachment['data'];
                        $importer->post_orphans[intval($post['import_id'])] = (int) $post['post_parent'];
                        $post['post_parent'] = 0;
                        $post_id = $importer->process_attachment($post, $attachment['remote_url']);
                        if (is_wp_error($post_id)) {
                            continue;
                        }
                        $importer->processed_posts[intval($post['import_id'])] = (int) $post_id;
                        // add/update post meta
                        if (!empty($post['postmeta'])) {
                            foreach ($post['postmeta'] as $meta) {
                                $key = $meta['key'];
                                $value = false;
                                if ('_edit_last' == $key) {
//.........这里部分代码省略.........
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:101,代码来源:om-import-tool.php


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