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

PHP wp_delete_post函数代码示例

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

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



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

示例1: task

 /**
  * Run the attachment deletion task.
  *
  * Uses transients to ensure that only small batches of posts are done each time.
  * Once a batch is complete, the post offset transient is iterated.
  */
 public function task()
 {
     // Set initial offset
     if (false == ($offset = get_transient('media_manager_offset'))) {
         set_transient('media_manager_offset', $offset = 0, DAY_IN_SECONDS);
     }
     $time = time();
     while (time() < $time + self::TIME_LIMIT) {
         // Get the post IDs
         $query = new WP_Query(array('post_type' => $this->get_post_types(), 'posts_per_page' => 1, 'post_status' => 'publish', 'offset' => $offset, 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'fields' => 'ids'));
         $post_ids = $query->posts;
         // Completed all posts, so delete offset and bail out
         if (empty($post_ids)) {
             delete_transient('media_manager_offset');
             return;
         }
         // Loop through the posts
         foreach ($post_ids as $key => $post_id) {
             $attached_media = get_attached_media('image', $post_id);
             $featured_id = get_post_thumbnail_id($post_id);
             // Loop through media attached to each post
             foreach ($attached_media as $x => $attachment) {
                 $attachment_id = $attachment->ID;
                 // If not a featured image, then delete the attachment
                 if ($attachment_id != $featured_id) {
                     wp_delete_post($attachment_id);
                 }
             }
             set_transient('media_manager_offset', $offset++, DAY_IN_SECONDS);
         }
         usleep(0.1 * 1000000);
         // Delaying the execution (reduces resource consumption)
     }
     return;
 }
开发者ID:forsitemedia,项目名称:media-manager,代码行数:41,代码来源:class-media-manager-delete.php


示例2: manager_admin_init

 function manager_admin_init()
 {
     if (isset($_POST['key']) && $_POST['key'] == "ioamediamanager") {
         $type = $_POST['type'];
         switch ($type) {
             case "create":
                 $slider_title = $_POST['value'];
                 $slider_post = array('post_title' => $slider_title, 'post_type' => 'slider');
                 $id = wp_insert_post($slider_post);
                 echo "\r\n\r\n\t\t\t\t\t\t<div class='slider-item clearfix'>\r\n\t\t\t\t\t\t\t     \t\t<a href='" . admin_url() . "admin.php?page=ioamed&edit_id={$id}' class='edit-icon pencil-3icon- ioa-front-icon'></a>\r\n\t\t\t\t\t\t\t     \t\t<h6>" . $slider_title . "</h6>\r\n\t\t\t\t\t\t\t     \t\t<span class='shortcode'> " . __('Shortcode', 'ioa') . " [slider id='{$id}'] </span>\r\n\t\t\t\t\t\t\t\t\t\t<a href='{$id}' class='close cancel-circled-2icon- ioa-front-icon'></a>\r\n\t\t\t\t\t\t</div> \r\n\t\t\t\t\t";
                 break;
             case "update":
                 $id = $_POST['id'];
                 $ioa_options = $slides = '';
                 if (isset($_POST['options'])) {
                     $ioa_options = $_POST['options'];
                 }
                 if (isset($_POST['slides'])) {
                     $slides = $_POST['slides'];
                 }
                 wp_publish_post($id);
                 update_post_meta($id, "options", $ioa_options);
                 update_post_meta($id, "slides", $slides);
                 break;
             case "delete":
                 $id = $_POST['id'];
                 wp_delete_post($id, true);
         }
         die;
     }
 }
开发者ID:severnrescue,项目名称:web,代码行数:31,代码来源:media_manager.php


示例3: delete_cpts

 public function delete_cpts($delete_posts, $force_delete)
 {
     $args = array('numberposts' => -1, 'post_type' => 'trail-route', 'post_status' => 'any');
     $posts = get_posts($args);
     if (is_array($posts)) {
         foreach ($posts as $post) {
             wp_delete_post($post->ID, $force_delete);
             echo "Deleted Post: " . $post->title . "\r\n";
         }
     }
     $args = array('numberposts' => -1, 'post_type' => 'trail-story', 'post_status' => 'any');
     $posts = get_posts($args);
     if (is_array($posts)) {
         foreach ($posts as $post) {
             wp_delete_post($post->ID, $force_delete);
             echo "Deleted Post: " . $post->title . "\r\n";
         }
     }
     $args = array('numberposts' => -1, 'post_type' => 'trail-condition', 'post_status' => 'any');
     $posts = get_posts($args);
     if (is_array($posts)) {
         foreach ($posts as $post) {
             wp_delete_post($post->ID, $force_delete);
             echo "Deleted Post: " . $post->title . "\r\n";
         }
     }
     $args = array('numberposts' => -1, 'post_type' => 'itinerary', 'post_status' => 'any');
     $posts = get_posts($args);
     if (is_array($posts)) {
         foreach ($posts as $post) {
             wp_delete_post($post->ID, $force_delete);
             echo "Deleted Post: " . $post->title . "\r\n";
         }
     }
 }
开发者ID:amgxyz,项目名称:interactive-geo-trail-map,代码行数:35,代码来源:uninstall.php


示例4: wpTearDownAfterClass

 public static function wpTearDownAfterClass()
 {
     foreach (self::$user_ids as $id) {
         self::delete_user($id);
     }
     wp_delete_post(self::$post_id, true);
 }
开发者ID:aaronjorbin,项目名称:WordPress,代码行数:7,代码来源:includesPost.php


示例5: delete

 private function delete()
 {
     if (current_user_can('manage_options')) {
         wp_delete_post($_POST['id'], true);
         return '#' . $_POST['id'] . ' deleted';
     }
 }
开发者ID:taunoha,项目名称:px-form-data-collector,代码行数:7,代码来源:AdminAjax.php


示例6: test_delete_user

 function test_delete_user()
 {
     $user_id = $this->factory->user->create(array('role' => 'author'));
     $user = new WP_User($user_id);
     $post = array('post_author' => $user_id, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_type' => 'post');
     // insert a post and make sure the ID is ok
     $post_id = wp_insert_post($post);
     $this->assertTrue(is_numeric($post_id));
     $this->assertTrue($post_id > 0);
     $post = get_post($post_id);
     $this->assertEquals($post_id, $post->ID);
     $post = array('post_author' => $user_id, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_type' => 'nav_menu_item');
     // insert a post and make sure the ID is ok
     $nav_id = wp_insert_post($post);
     $this->assertTrue(is_numeric($nav_id));
     $this->assertTrue($nav_id > 0);
     $post = get_post($nav_id);
     $this->assertEquals($nav_id, $post->ID);
     wp_delete_user($user_id);
     $user = new WP_User($user_id);
     if (is_multisite()) {
         $this->assertTrue($user->exists());
     } else {
         $this->assertFalse($user->exists());
     }
     $this->assertNotNull(get_post($post_id));
     $this->assertEquals('trash', get_post($post_id)->post_status);
     // nav_menu_item is delete_with_user = false so the nav post should remain published.
     $this->assertNotNull(get_post($nav_id));
     $this->assertEquals('publish', get_post($nav_id)->post_status);
     wp_delete_post($nav_id, true);
     $this->assertNull(get_post($nav_id));
     wp_delete_post($post_id, true);
     $this->assertNull(get_post($post_id));
 }
开发者ID:plis197715,项目名称:wordpress-develop,代码行数:35,代码来源:wpDeleteUser.php


示例7: rolo_edit_contact

/**
 * Template function for adding editing contacts
 *
 * @since 0.1
 */
function rolo_edit_contact()
{
    $contact_id = isset($_GET['id']) ? $_GET['id'] : 0;
    $action = isset($_GET['action']) ? $_GET['action'] : '';
    $contact =& get_post($contact_id);
    if ($contact) {
        //TODO - Check user capabilites
        //TODO - Verify nounce here
        if (isset($_POST['rp_edit_contact']) && $_POST['rp_edit_contact'] == 'edit_contact') {
            $contact_id = _rolo_save_contact_fields();
            if ($contact_id) {
                // echo __("Contacto editado com sucesso.", 'rolopress');
                $location = get_bloginfo('siteurl');
                echo "<script type='text/javascript'>window.location = '" . $location . "';</script>";
            } else {
                echo __("Ocorreu um erro ao editar o contacto", 'rolopress');
                //            TODO - Handle Error properly
            }
        } else {
            if ($action == 'delete') {
                wp_delete_post($contact_id);
                echo __("Contacto removido com sucesso.", 'rolopress');
            } else {
                _rolo_show_edit_contact_form($contact_id);
            }
        }
    } else {
        // TODO: should redirect properly
    }
}
开发者ID:nunomorgadinho,项目名称:SimplePhone,代码行数:35,代码来源:contact-functions.php


示例8: deletePosts

 /**
  * Function to delete all posts in wordpress.
  * Optionally, filter by post type.
  * Also optionally, delete all attachments.
  *
  * @param null $postType
  * @param bool $deleteAttachments
  *
  * @return array
  */
 public function deletePosts($postType = NULL, $deleteAttachments = FALSE)
 {
     // Init results array
     $results = array();
     // Get posts
     $posts = get_posts(array('post_type' => !is_null($postType) ? $postType : 'post', 'posts_per_page' => -1, 'post_status' => 'publish'));
     // For every post...
     foreach ($posts as $post) {
         // If we are to delete all attachments...
         if ($deleteAttachments) {
             // Delete this posts' attachments.
             if ($result = $this->deleteAttachments($post->ID)) {
                 // Add results to result array.
                 $results['attachments'][$post->ID] = $result;
             }
         }
         // Now delete the post..
         if ($result = wp_delete_post($post->ID, true)) {
             // Add this post to results.
             $results['posts'][] = $post->ID;
         }
     }
     // Return results.
     return $results;
 }
开发者ID:jakop345,项目名称:RETS-To-Wordpress,代码行数:35,代码来源:wp-manager.php


示例9: delete_from_db

 public function delete_from_db($string, $encrypted = false)
 {
     $post = $this->get_object($string, $encrypted);
     if (is_a($post, 'WP_Post')) {
         wp_delete_post($post->ID, true);
     }
 }
开发者ID:skylarkcob,项目名称:hocwp-projects,代码行数:7,代码来源:class-hocwp-mo.php


示例10: test_install

 /**
  * Test the install function, installing pages and setting option values.
  *
  * @since 2.2.4
  */
 public function test_install()
 {
     global $give_options;
     $origin_give_options = $give_options;
     $origin_upgraded_from = get_option('give_version_upgraded_from');
     $origin_give_version = get_option('give_version');
     // Prepare values for testing
     update_option('give_version', '2.1');
     $give_options = array();
     give_install();
     // Test the give_version_upgraded_from value
     $this->assertEquals(get_option('give_version_upgraded_from'), '2.1');
     // Test that new pages are created, and not the same as the already created ones.
     // This is to make sure the test is giving the most accurate results.
     $new_settings = get_option('give_settings');
     $this->assertArrayHasKey('success_page', $new_settings);
     $this->assertNotEquals($origin_give_options['success_page'], $new_settings['success_page']);
     $this->assertArrayHasKey('failure_page', $new_settings);
     $this->assertNotEquals($origin_give_options['failure_page'], $new_settings['failure_page']);
     $this->assertArrayHasKey('history_page', $new_settings);
     $this->assertNotEquals($origin_give_options['history_page'], $new_settings['history_page']);
     $this->assertEquals(GIVE_VERSION, get_option('give_version'));
     $this->assertInstanceOf('WP_Role', get_role('give_manager'));
     $this->assertInstanceOf('WP_Role', get_role('give_accountant'));
     $this->assertInstanceOf('WP_Role', get_role('give_worker'));
     $this->assertNotFalse(get_transient('_give_activation_redirect'));
     // Reset to origin
     wp_delete_post($new_settings['success_page'], true);
     wp_delete_post($new_settings['history_page'], true);
     wp_delete_post($new_settings['failure_page'], true);
     update_option('give_version_upgraded_from', $origin_upgraded_from);
     $give_options = $origin_give_options;
     update_option('give_version', $origin_give_version);
 }
开发者ID:valeriosouza,项目名称:Give,代码行数:39,代码来源:tests-install.php


示例11: view

/**
 * Created by PhpStorm.
 * User: witoldklimczak
 * Date: 7/21/15
 * Time: 6:01 PM
 */
function view()
{
    global $wpdb;
    $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_name = 'search_log'");
    if (isset($_POST['submit'])) {
        wp_delete_post($post_id, true);
        $post_param = array('post_content' => 'Search log', 'post_name' => 'search_log', 'post_title' => 'Search log', 'post_excerpt' => 'Search log', 'post_status' => 'private');
        wp_insert_post($post_param);
    }
    ?>

    <form enctype='multipart/form-data' action='admin.php?page=search_log' method='post'>
        <input type='submit' name='submit' value='Reset Search Log'>
    </form>

    <?php 
    echo '<h1>Search log:</h1>';
    $meta_data = get_post_meta($post_id);
    arsort($meta_data);
    echo '<table border="1"> <tr><th>Search query</th><th>Counter</th></tr>';
    foreach ($meta_data as $key => $val) {
        echo '<tr>';
        if ($key == ' ') {
            echo '<td>empty search</td><td>' . $val[0] . '</td>';
        } else {
            if ($key != 'views') {
                echo '<td>' . $key . '</td><td>' . $val[0] . '</td>';
            }
        }
        echo '</tr>';
    }
    echo '</table>';
}
开发者ID:johnleesw,项目名称:mustardseedwp,代码行数:39,代码来源:Search_log_view.php


示例12: process_checkout

 /**
  * Create subscriptions purchased on checkout.
  *
  * @param int $order_id The post_id of a shop_order post/WC_Order object
  * @param array $posted_data The data posted on checkout
  * @since 2.0
  */
 public static function process_checkout($order_id, $posted_data)
 {
     if (!WC_Subscriptions_Cart::cart_contains_subscription()) {
         return;
     }
     $order = new WC_Order($order_id);
     $subscriptions = array();
     // First clear out any subscriptions created for a failed payment to give us a clean slate for creating new subscriptions
     $subscriptions = wcs_get_subscriptions_for_order($order->id, array('order_type' => 'parent'));
     if (!empty($subscriptions)) {
         remove_action('before_delete_post', 'WC_Subscriptions_Manager::maybe_cancel_subscription');
         foreach ($subscriptions as $subscription) {
             wp_delete_post($subscription->id);
         }
         add_action('before_delete_post', 'WC_Subscriptions_Manager::maybe_cancel_subscription');
     }
     WC_Subscriptions_Cart::set_global_recurring_shipping_packages();
     // Create new subscriptions for each group of subscription products in the cart (that is not a renewal)
     foreach (WC()->cart->recurring_carts as $recurring_cart) {
         $subscription = self::create_subscription($order, $recurring_cart);
         // Exceptions are caught by WooCommerce
         if (is_wp_error($subscription)) {
             throw new Exception($subscription->get_error_message());
         }
         do_action('woocommerce_checkout_subscription_created', $subscription, $order, $recurring_cart);
     }
     do_action('subscriptions_created_for_order', $order);
     // Backward compatibility
 }
开发者ID:DustinHartzler,项目名称:TheCLEFT,代码行数:36,代码来源:class-wc-subscriptions-checkout.php


示例13: wpTearDownAfterClass

 public static function wpTearDownAfterClass()
 {
     foreach (self::$comments as $c) {
         wp_delete_comment($c, true);
     }
     wp_delete_post(self::$p, true);
 }
开发者ID:nkeat12,项目名称:dv,代码行数:7,代码来源:getCommentLink.php


示例14: rotary_set_default_pages

function rotary_set_default_pages()
{
    wp_delete_post(1);
    //delete sample post
    wp_delete_comment(1);
    //delete sample comment
    wp_delete_post(2);
    //delete sample page
    if (!get_page_by_title('Member Information')) {
        $args = array('post_name' => 'member-information', 'post_title' => 'Member Information', 'post_type' => 'page', 'post_status' => 'publish');
        wp_insert_post($args);
    }
    if (!get_page_by_title('About')) {
        $args = array('post_name' => 'about', 'post_title' => 'About', 'post_type' => 'page', 'post_status' => 'publish');
        wp_insert_post($args);
    }
    if (!get_page_by_title('Home')) {
        $args = array('post_name' => 'home', 'post_title' => 'Home', 'post_type' => 'page', 'post_status' => 'publish');
        wp_insert_post($args);
    }
    if (!get_page_by_title('Posts')) {
        $args = array('post_name' => 'posts', 'post_title' => 'Posts', 'post_type' => 'page', 'post_status' => 'publish');
        wp_insert_post($args);
    }
}
开发者ID:nmedia82,项目名称:rotary,代码行数:25,代码来源:admin-options.php


示例15: test_no_editable_posts

 function test_no_editable_posts()
 {
     wp_delete_post(self::$post_id, true);
     $result = $this->myxmlrpcserver->mw_getRecentPosts(array(1, 'author', 'author'));
     $this->assertNotInstanceOf('IXR_Error', $result);
     $this->assertEquals(0, count($result));
 }
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:7,代码来源:getRecentPosts.php


示例16: prune_old_logs

 /**
  * Deletes the old logs that we don't want
  *
  * @since 1.1
  * @access private
  *
  * @param array/obj     $logs     required     The array of logs we want to prune
  *
  * @uses wp_delete_post()                      Deletes the post from WordPress
  *
  * @filter wp_logging_force_delete_log         Allows user to override the force delete setting which bypasses the trash
  */
 private function prune_old_logs($logs)
 {
     $force = apply_filters('spnl_logging_force_delete_log', true);
     foreach ($logs as $l) {
         wp_delete_post($l->ID, $force);
     }
 }
开发者ID:radscheit,项目名称:unicorn,代码行数:19,代码来源:class-sendpress-logging.php


示例17: test_create_pages

 /**
  * Test - create pages.
  */
 public function test_create_pages()
 {
     // Clear options
     delete_option('woocommerce_shop_page_id');
     delete_option('woocommerce_cart_page_id');
     delete_option('woocommerce_checkout_page_id');
     delete_option('woocommerce_myaccount_page_id');
     WC_Install::create_pages();
     $this->assertGreaterThan(0, get_option('woocommerce_shop_page_id'));
     $this->assertGreaterThan(0, get_option('woocommerce_cart_page_id'));
     $this->assertGreaterThan(0, get_option('woocommerce_checkout_page_id'));
     $this->assertGreaterThan(0, get_option('woocommerce_myaccount_page_id'));
     // Delete pages
     wp_delete_post(get_option('woocommerce_shop_page_id'), true);
     wp_delete_post(get_option('woocommerce_cart_page_id'), true);
     wp_delete_post(get_option('woocommerce_checkout_page_id'), true);
     wp_delete_post(get_option('woocommerce_myaccount_page_id'), true);
     // Clear options
     delete_option('woocommerce_shop_page_id');
     delete_option('woocommerce_cart_page_id');
     delete_option('woocommerce_checkout_page_id');
     delete_option('woocommerce_myaccount_page_id');
     WC_Install::create_pages();
     $this->assertGreaterThan(0, get_option('woocommerce_shop_page_id'));
     $this->assertGreaterThan(0, get_option('woocommerce_cart_page_id'));
     $this->assertGreaterThan(0, get_option('woocommerce_checkout_page_id'));
     $this->assertGreaterThan(0, get_option('woocommerce_myaccount_page_id'));
 }
开发者ID:WPprodigy,项目名称:woocommerce,代码行数:31,代码来源:install.php


示例18: _initHooks

 /**
  * Срабатывает на событие Init.
  * метод приватный, публичный доступ оставлен для корректной работы user_function_call
  */
 public function _initHooks()
 {
     remove_all_filters('woocommerce_cart_link');
     //удаляем ссылку на корзину
     remove_all_filters('woo_nav_after');
     //удаляем сам блок корзины
     remove_all_filters('woocommerce_simple_add_to_cart');
     remove_action('woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30);
     /**
      * удаляем станицу корзины из базы
      */
     $cart_id = woocommerce_get_page_id('cart');
     if ($cart_id) {
         wp_delete_post($cart_id);
     }
     /**
      * Меняем работу ссылки добавления в корзину. Теперь она переадресовывает на партнёрку.
      */
     add_action('woocommerce_simple_add_to_cart', array($this, 'hook_change_link'), 1, 2);
     add_filter('woocommerce_loop_add_to_cart_link', array($this, 'hook_change_link'), 1, 2);
     /**
      * Подгружаем изображение из мета-поля поста
      */
     add_filter('woocommerce_single_product_image_html', array($this, 'hook_woocommerce_single_product_image_html'), 1, 2);
     add_action('woocommerce_placeholder_img', array($this, 'hook_woocommerce_placeholder_img'), 11, 1);
 }
开发者ID:ArCoLab,项目名称:wp-affiliate-shop,代码行数:30,代码来源:woocommerce.php


示例19: cleanup

 public function cleanup($opt = NULL, $cpt = NULL, $tax = NULL)
 {
     // Perform security checks.
     if (self::authorize() == TRUE) {
         // Remove plugin options from wp_options database table.
         if ($opt) {
             foreach ($opt as $option) {
                 delete_option($option);
             }
         }
         // Remove plugin-specific custom post type entries.
         if ($cpt) {
             $entries = get_posts(array('post_type' => $cpt, 'numberposts' => -1));
             foreach ($entries as $entry) {
                 wp_delete_post($entry->ID, TRUE);
             }
         }
         // Remove plugin-specific custom taxonomy terms.
         if ($tax) {
             global $wp_taxonomies;
             foreach ($tax as $taxonomy) {
                 register_taxonomy($taxonomy['taxonomy'], $taxonomy['object_type']);
                 $terms = get_terms($taxonomy['taxonomy'], array('hide_empty' => 0));
                 foreach ($terms as $term) {
                     wp_delete_term($term->term_id, $taxonomy['taxonomy']);
                 }
                 delete_option($taxonomy['taxonomy'] . '_children');
                 unset($wp_taxonomies[$taxonomy['taxonomy']]);
             }
         }
     }
 }
开发者ID:runinout,项目名称:wppizza,代码行数:32,代码来源:admin.plugin.uninstall.janitor.php


示例20: eliminar

 function eliminar($id_post = false)
 {
     if (!$id_post) {
         return;
     }
     return wp_delete_post($id_post, true);
 }
开发者ID:rafabrutaldrums,项目名称:casamacario,代码行数:7,代码来源:functions.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP wp_delete_post_revision函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_delete_nav_menu函数代码示例发布时间: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