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


PHP wp_update_post函数代码示例

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


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

示例1: g1_simple_slider_add_new_slide

function g1_simple_slider_add_new_slide()
{
    $ajax_data = $_POST['ajax_data'];
    $post_parent = get_post($ajax_data['parent_id']);
    $slide = get_post($ajax_data['attachment_id']);
    $error_response = $success_response = new WP_Ajax_Response();
    $errors = new WP_Error();
    if (!$post_parent || !$slide) {
        $errors->add('incorrect_input_data', 'Slide or parent post does not exist!');
    }
    if (count($errors->get_error_codes()) > 0) {
        $error_response->add(array('what' => 'errors', 'id' => $errors));
        $error_response->send();
        exit;
    }
    // attach slide to simple_slider
    wp_update_post(array('ID' => $slide->ID, 'post_parent' => $post_parent->ID));
    $slider = G1_Slider_Factory::get_simple_slider($post_parent);
    $last_slide = $slider->get_last_slide();
    $new_slide = new G1_Simple_Slider_Slide($slide);
    $new_slide->set_order($last_slide->get_order() + 1);
    $new_slide->save();
    $view = new G1_Simple_Slider_Slide_Html_Renderer($new_slide, $slider->get_id());
    $success_response->add(array('what' => 'slide_html', 'id' => 1, 'data' => $view->capture()));
    $success_response->send();
    exit;
}
开发者ID:aragonc,项目名称:3clicks,代码行数:27,代码来源:slider-builder.php

示例2: process_ajax_request

 /**
  * Handle Post Customizer AJAX requests
  *
  * @access public
  * @since 0.1.0
  */
 public function process_ajax_request()
 {
     check_ajax_referer('post-customizer');
     if (empty($_POST['post_customizer_action'])) {
         return;
     }
     if ('get_sidebar' == $_POST['post_customizer_action']) {
         if (empty($_POST['post_id'])) {
             return;
         }
         $data = array('sidebarHTML' => $this->_render_sidebar_data($_POST['post_id']));
     } elseif ('save_field' == $_POST['post-customizer_action'] && !empty($_POST['field']) && !empty($_POST['post_id'])) {
         $data = array();
         switch ($_POST['field']) {
             case 'post_title':
             case 'post_content':
                 wp_update_post(array('ID' => $_POST['post_id'], $_POST['field'] => $_POST['data']));
                 $data['changed'] = $_POST['field'];
                 $data['value'] = $_POST['data'];
                 break;
         }
     } else {
         //Error!
     }
     wp_send_json($data);
 }
开发者ID:resarahman,项目名称:Post-Customizer,代码行数:32,代码来源:class-post-customizer.php

示例3: acfmod_simple_content_save_post

function acfmod_simple_content_save_post($post_id)
{
    // bail early if no ACF data
    if (empty($_POST['acf'])) {
        return;
    }
    // array of field values
    $fields = $_POST['acf'];
    if (!isset($fields['acf_modules_field']) && is_array($fields['acf_modules_field'])) {
        return;
    }
    // This may change in the future... yikes...
    $delete_content_key = 'field_55686c1d9d812';
    // assume we aren't deleting content
    $do_delete_content = false;
    // get modules values
    foreach ($fields['acf_modules_field'] as $module) {
        if (isset($module[$delete_content_key])) {
            if ($module[$delete_content_key]) {
                $do_delete_content = true;
            }
        }
    }
    // don't store the values for delete and load content fields
    # not sure how to do that just yet
    // bail early if we're not deleting the content
    if (!$do_delete_content) {
        return;
    }
    // clear the post content
    remove_action('acf/save_post', 'acfmod_simple_content_save_post', 20);
    $delete_content = array('ID' => $post_id, 'post_content' => '');
    wp_update_post($delete_content);
    add_action('acf/save_post', 'acfmod_simple_content_save_post', 20);
}
开发者ID:mmjaeger,项目名称:acf-modules,代码行数:35,代码来源:content.php

示例4: generate_from_content

 /**
  * Generate modular layout data from standard post content.
  *
  * @subcommand generate-from-content
  * @synopsis [--post_type=<post>] [--dry_run]
  */
 public function generate_from_content($args, $assoc_args)
 {
     $plugin = Plugin::get_instance();
     $builder = $plugin->get_builder('ustwo-page-builder');
     $assoc_args = wp_parse_args($assoc_args, array('post_type' => 'post', 'dry_run' => false));
     $query_args = array('post_type' => $assoc_args['post_type'], 'post_status' => 'any', 'posts_per_page' => 50);
     $page = 1;
     $more_posts = true;
     while ($more_posts) {
         $query_args['paged'] = $page;
         $query = new WP_Query($query_args);
         foreach ($query->posts as $post) {
             if (empty($post->post_content)) {
                 continue;
             }
             WP_CLI::line("Migrating data for {$post->ID}");
             $module = array('name' => 'text', 'attr' => array(array('name' => 'body', 'type' => 'wysiwyg', 'value' => $post->post_content)));
             $modules = $builder->get_raw_data($post->ID);
             $modules[] = $module;
             $modules = $builder->validate_data($modules);
             if (!$assoc_args['dry_run']) {
                 $modules = $builder->save_data($post->ID, $modules);
                 wp_update_post(array('ID' => $post->ID, 'post_content' => ''));
             }
         }
         $more_posts = $page < absint($query->max_num_pages);
         $page++;
     }
 }
开发者ID:roborourke,项目名称:modular-page-builder,代码行数:35,代码来源:class-wp-cli.php

示例5: callback

 function callback($path = '', $blog_id = 0, $media_id = 0)
 {
     $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
     if (is_wp_error($blog_id)) {
         return $blog_id;
     }
     if (!current_user_can('upload_files', $media_id)) {
         return new WP_Error('unauthorized', 'User cannot view media', 403);
     }
     $item = $this->get_media_item($media_id);
     if (is_wp_error($item)) {
         return new WP_Error('unknown_media', 'Unknown Media', 404);
     }
     $input = $this->input(true);
     $insert = array();
     if (!empty($input['title'])) {
         $insert['post_title'] = $input['title'];
     }
     if (!empty($input['caption'])) {
         $insert['post_excerpt'] = $input['caption'];
     }
     if (!empty($input['description'])) {
         $insert['post_content'] = $input['description'];
     }
     $insert['ID'] = $media_id;
     wp_update_post((object) $insert);
     $item = $this->get_media_item($media_id);
     return $item;
 }
开发者ID:StefanBonilla,项目名称:CoupSoup,代码行数:29,代码来源:class.wpcom-json-api-update-media-endpoint.php

示例6: ep_create_and_sync_post

/**
 * Create a WP post and "sync" it to Elasticsearch. We are mocking the sync
 *
 * @param array $post_args
 * @param array $post_meta
 * @param int $site_id
 * @since 0.9
 * @return int|WP_Error
 */
function ep_create_and_sync_post($post_args = array(), $post_meta = array(), $site_id = null)
{
    if ($site_id != null) {
        switch_to_blog($site_id);
    }
    $post_types = ep_get_indexable_post_types();
    $post_type_values = array_values($post_types);
    $args = array('post_status' => 'publish', 'post_title' => 'Test Post ' . time());
    if (!empty($post_type_values)) {
        $args['post_type'] = $post_type_values[0];
    }
    $args = wp_parse_args($post_args, $args);
    $post_id = wp_insert_post($args);
    // Quit if we have a WP_Error object
    if (is_wp_error($post_id)) {
        return $post_id;
    }
    if (!empty($post_meta)) {
        foreach ($post_meta as $key => $value) {
            // No need for sanitization here
            update_post_meta($post_id, $key, $value);
        }
    }
    // Force a re-sync
    wp_update_post(array('ID' => $post_id));
    if ($site_id != null) {
        restore_current_blog();
    }
    return $post_id;
}
开发者ID:rossluebe,项目名称:ElasticPress,代码行数:39,代码来源:functions.php

示例7: githubHook

 public function githubHook($route)
 {
     $github = new Github();
     $http = herbert('http');
     $fd = get_option('gitcontent_settings');
     if ($route != $fd['route']) {
         return;
     }
     $args = ['meta_query' => [['key' => '_gitcontent_file', 'value' => '', 'compare' => '!=']]];
     $posts = get_posts($args);
     foreach ($posts as $post) {
         $file = get_post_meta($post->ID, '_gitcontent_file', true);
         $inputs = get_option('gitcontent_settings');
         $response = $github->checkFile($inputs, $file);
         $markdownFile = Helper::storagePath($post->ID);
         if ($response === false) {
             return;
         }
         if ($github->downloadFile($inputs, $response, $markdownFile) === false) {
             return;
         }
         wp_update_post(['ID' => $post->ID, 'post_content' => (new ParsedownExtra())->text(file_get_contents($markdownFile))], false);
     }
     echo 'Done';
 }
开发者ID:bigbitecreative,项目名称:wordpress-git-content,代码行数:25,代码来源:RouteController.php

示例8: tdomf_auto_fix_authors

function tdomf_auto_fix_authors()
{
    global $wpdb;
    if (get_option(TDOMF_AUTO_FIX_AUTHOR)) {
        // grab posts
        $query = "SELECT ID, post_author, meta_value ";
        $query .= "FROM {$wpdb->posts} ";
        $query .= "LEFT JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id) ";
        $query .= "WHERE meta_key = '" . TDOMF_KEY_USER_ID . "' ";
        $query .= "AND meta_value != post_author ";
        $query .= "ORDER BY ID DESC";
        $posts = $wpdb->get_results($query);
        if (!empty($posts)) {
            $count = 0;
            foreach ($posts as $post) {
                if ($post->meta_value != $post->post_author && !empty($post->meta_value) && $post->meta_value > 0) {
                    $count++;
                    tdomf_log_message("Changing author (currently {$post->post_author}) on post {$post->ID} to submitter setting {$post->meta_value}.");
                    echo $post->ID . ", ";
                    $postargs = array("ID" => $post->ID, "post_author" => $post->meta_value);
                    wp_update_post($postargs);
                }
            }
            return $count;
        } else {
            return 0;
        }
    }
    return false;
}
开发者ID:TheReaCompany,项目名称:pooplog,代码行数:30,代码来源:tdomf-hacks.php

示例9: job_manager_alert

 /**
  * Send an alert
  */
 public function job_manager_alert($alert_id, $force = false)
 {
     $alert = get_post($alert_id);
     if (!$alert || $alert->post_type !== 'job_alert') {
         return;
     }
     if ($alert->post_status !== 'publish' && !$force) {
         return;
     }
     $user = get_user_by('id', $alert->post_author);
     $jobs = $this->get_matching_jobs($alert, $force);
     if ($jobs->found_posts || !get_option('job_manager_alerts_matches_only')) {
         $email = $this->format_email($alert, $user, $jobs);
         add_filter('wp_mail_from_name', array($this, 'mail_from_name'));
         add_filter('wp_mail_from', array($this, 'mail_from_email'));
         if ($email) {
             wp_mail($user->user_email, apply_filters('job_manager_alerts_subject', sprintf(__('Job Alert Results Matching "%s"', 'wp-job-manager-alerts'), $alert->post_title), $alert), $email);
         }
         remove_filter('wp_mail_from_name', array($this, 'mail_from_name'));
         remove_filter('wp_mail_from', array($this, 'mail_from_email'));
     }
     if (($days_to_disable = get_option('job_manager_alerts_auto_disable')) > 0) {
         $days = (strtotime('NOW') - strtotime($alert->post_modified)) / (60 * 60 * 24);
         if ($days > $days_to_disable) {
             $update_alert = array();
             $update_alert['ID'] = $alert->ID;
             $update_alert['post_status'] = 'draft';
             wp_update_post($update_alert);
             wp_clear_scheduled_hook('job-manager-alert', array($alert->ID));
             return;
         }
     }
     // Inc sent count
     update_post_meta($alert->ID, 'send_count', 1 + absint(get_post_meta($alert->ID, 'send_count', true)));
 }
开发者ID:sabdev1,项目名称:sabstaff,代码行数:38,代码来源:class-wp-job-manager-alerts-notifier.php

示例10: piskotki_create_page

function piskotki_create_page()
{
    global $wpdb;
    $page_title = 'Piškotki';
    $page_name = 'piskotki';
    delete_option('piskotki_page_title');
    add_option('piskotki_page_title', $page_title, '', 'yes');
    delete_option('piskotki_page_name');
    add_option('piskotki_page_name', $page_name, '', 'yes');
    delete_option('piskotki_page_id');
    add_option('piskotki_page_id', '0', '', 'yes');
    $page = get_page_by_title($page_title);
    if (!$page) {
        $_p = array();
        $_p['post_title'] = $page_title;
        $_p['post_content'] = "To besedilo se lahko prepiše preko vtičnika. Ne urejajte ga tukaj!";
        $_p['post_status'] = 'publish';
        $_p['post_type'] = 'page';
        $_p['comment_status'] = 'closed';
        $_p['ping_status'] = 'closed';
        $page_id = wp_insert_post($_p);
    } else {
        $page_id = $page->ID;
        $page->post_status = 'publish';
        $page_id = wp_update_post($page);
        delete_option('piskotki_page_id');
        add_option('piskotki_page_id', $page_id);
    }
}
开发者ID:jelenaljaz,项目名称:piskotki,代码行数:29,代码来源:piskotki.php

示例11: save

 /**
  * @return int|bool Integer on success, false on failure.
  */
 public function save()
 {
     $args = array('post_type' => $this->post_type, 'post_status' => 'publish');
     if ($this->c->exists()) {
         $args['ID'] = $this->c->get_id();
     }
     // WP will gobble up LaTeX escape characters.
     $content = $this->c->get_content();
     $content = $this->pf->convert_delims($content);
     $content = $this->pf->swap_latex_escape_characters($content);
     $args['post_content'] = $content;
     $args['post_author'] = $this->c->get_author_id();
     if (null !== $this->c->get_post_date()) {
         // todo gmt
         $args['post_date'] = $this->c->get_post_date();
     }
     if ($this->c->exists()) {
         $saved = wp_update_post($args);
     } else {
         $saved = wp_insert_post($args);
         if ($saved && !is_wp_error($saved)) {
             $this->c->set_id($saved);
         }
     }
     return $saved;
 }
开发者ID:livinglab,项目名称:webwork-for-wordpress,代码行数:29,代码来源:WPPost.php

示例12: update_attachments

 /**
  * Run the converter now
  *
  * @since 1.0
  *
  * @param array $args can be extension
  * @param array $vars
  */
 function update_attachments($args = array(), $vars = array())
 {
     $images = Tiff_Converter::get_images();
     $mime_type = 'image/jpg';
     // Maybe $args[0] for changing it
     if ($images) {
         $succeed = $failed = 0;
         foreach ($images as $image) {
             $file = get_attached_file($image->ID);
             $result = Tiff_Converter_Handle::convert_image($file, $mime_type);
             if (!is_wp_error($result)) {
                 $update_args = array('ID' => $image->ID, 'post_mime_type' => $result['mime-type']);
                 $result2 = wp_update_post($update_args, true);
                 if ($result2 && !is_wp_error($result2)) {
                     unlink($file);
                     update_attached_file($image->ID, $result['path']);
                     wp_update_attachment_metadata($image->ID, wp_generate_attachment_metadata($image->ID, $result['path']));
                     $succeed++;
                 } else {
                     unlink($result['path']);
                     $failed++;
                 }
             } else {
                 $failed++;
             }
         }
         WP_CLI::success(sprintf('%d images are converted and %s failed', $succeed, $failed));
     } else {
         WP_CLI::success('No images to convert');
     }
 }
开发者ID:markoheijnen,项目名称:WordPress-Tiff-Converter,代码行数:39,代码来源:wp-cli.php

示例13: __construct

 public function __construct()
 {
     global $WCMp;
     if (get_option("dc_product_vendor_plugin_page_install") == 1) {
         $wcmp_pages = get_option('wcmp_pages_settings_name');
         if (isset($wcmp_pages['vendor_dashboard'])) {
             wp_update_post(array('ID' => $wcmp_pages['vendor_dashboard'], 'post_content' => '[vendor_dashboard]'));
         }
         if (isset($wcmp_pages['vendor_messages'])) {
             wp_update_post(array('ID' => $wcmp_pages['vendor_messages'], 'post_content' => '[vendor_announcements]', 'post_name' => 'vendor_announcements', 'post_title' => 'Vendor Announcements'));
             $page_id = $wcmp_pages['vendor_messages'];
             unset($wcmp_pages['vendor_messages']);
             $wcmp_pages['vendor_announcements'] = $page_id;
             update_option('wcmp_pages_settings_name', $wcmp_pages);
         }
     }
     if (!get_option("dc_product_vendor_plugin_page_install")) {
         $this->wcmp_product_vendor_plugin_create_pages();
     }
     update_option("dc_product_vendor_plugin_db_version", $WCMp->version);
     update_option("dc_product_vendor_plugin_page_install", 1);
     $this->save_default_plugin_settings();
     $this->wcmp_plugin_tables_install();
     $this->remove_other_vendors_plugin_role();
 }
开发者ID:qhuit,项目名称:UrbanPekor,代码行数:25,代码来源:class-wcmp-install.php

示例14: posts

 /**
  * @param array $property
  */
 public function posts(array $property)
 {
     //get post data
     $property_formatted = array();
     //reassign fields to ones that look good
     $property_formatted['price'] = $property['Lp_dol'];
     $property_formatted['mls'] = $property['Ml_num'];
     $property_formatted['address'] = $property['Addr'];
     $property_formatted['bathrooms'] = $property['Bath_tot'];
     $property_formatted['bedrooms'] = $property['Br'];
     $property_formatted['province'] = $property['County'];
     $property_formatted['broker'] = $property['Rltr'];
     $property_formatted['rooms'] = $property['Rms'];
     $property_formatted['rentorsale'] = $property['S_r'];
     $property_formatted['status'] = $property['Status'];
     $property_formatted['postal_code'] = $property['Zip'];
     $property_formatted['city'] = $property['Area'];
     $property_formatted['last_updated_text'] = $property['Timestamp_sql'];
     $property_formatted['last_updated_photos'] = $property['Pix_updt'];
     $property_formatted['description'] = $property['Ad_text'];
     $property_formatted['full_dump'] = $property;
     //set up arguments before entering post to wp
     $post_args = array('post_content' => $property_formatted['description'], 'ID' => $this->id, 'post_type' => 'property');
     //insert post and return new post id
     $posted = wp_update_post($post_args, true);
     //add post meta using the new post id and good looking array
     foreach ($property_formatted as $key => $value) {
         if (!empty($value)) {
             add_post_meta($this->id, 'wptrebs_' . $key, $value, true) || update_post_meta($this->id, 'wptrebs_' . $key, $value);
         }
     }
 }
开发者ID:LeapXD,项目名称:wptrebrets,代码行数:35,代码来源:Update.php

示例15: setUp

    /**
     * Setup the tests object.
     */
    public function setUp()
    {
        parent::setUp();
        $this->basicSetUp();
        // Lesson with more tag only.
        $lesson1 = get_post($this->lessons[0]);
        $lesson1->post_excerpt = '';
        $lesson1->post_content = <<<EOT
This text can be visible to anyone.<!--more-->
This text must be visible to the students who registered for this course.
EOT;
        wp_update_post($lesson1);
        // Lesson without more tag and excerpt.
        $lesson2 = get_post($this->lessons[1]);
        $lesson2->post_excerpt = '';
        $lesson2->post_content = <<<EOT
This text must be visible to the students who registered for this course.
EOT;
        wp_update_post($lesson2);
        // Lesson with excerpt only.
        $this->lesson3 = $this->addLesson(array('course_id' => $this->courses[0], 'author_id' => $this->users['lecturer1'], 'slug' => 'course-1-lesson-3', 'title' => 'course 1 lesson 3'));
        $lesson3 = get_post($this->lesson3);
        $lesson3->post_excerpt = 'This excerpt is visible to everyone.';
        $lesson3->post_content = <<<EOT
This text must be visible to the students who registered for this course.
EOT;
        wp_update_post($lesson3);
        $this->open_lesson = $this->addLesson(array('course_id' => $this->courses[0], 'author_id' => $this->users['lecturer1'], 'slug' => 'course-1-open-lesson', 'title' => 'course 1 open lesson'));
        $open_lesson = get_post($this->open_lesson);
        $open_lesson->post_excerpt = 'Post excerpt.';
        $open_lesson->post_content = 'Hidden content.';
        wp_update_post($open_lesson);
    }
开发者ID:rcnascimento,项目名称:ibeducator,代码行数:36,代码来源:test-lessons-permissions.php


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