/** * 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; }
/** * Generic function to test the topic counts on a deleted reply */ public function test_bbp_topic_deleted_reply_counts() { $f = $this->factory->forum->create(); $t = $this->factory->topic->create(array('post_parent' => $f, 'post_author' => bbp_get_current_user_id(), 'topic_meta' => array('forum_id' => $f))); $r1 = $this->factory->reply->create(array('post_parent' => $t, 'post_author' => bbp_get_current_user_id(), 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $u = $this->factory->user->create(); $count = bbp_update_topic_reply_count($t); $this->assertSame(1, $count); $count = bbp_update_topic_reply_count_hidden($t); $this->assertSame(0, $count); $count = bbp_update_topic_voice_count($t); $this->assertSame(1, $count); $r2 = $this->factory->reply->create(array('post_parent' => $t, 'post_author' => $u, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $count = bbp_update_topic_reply_count($t); $this->assertSame(2, $count); $count = bbp_update_topic_reply_count_hidden($t); $this->assertSame(0, $count); $count = bbp_update_topic_voice_count($t); $this->assertSame(2, $count); // ToDo: Update this to use bbp_delete_reply(). bbp_clean_post_cache($t); wp_delete_post($r2, true); $count = bbp_get_topic_reply_count($t, true); $this->assertSame(1, $count); $count = bbp_get_topic_reply_count_hidden($t, true); $this->assertSame(0, $count); $count = bbp_get_topic_voice_count($t, true); $this->assertSame(1, $count); }
public static function tearDownAfterClass() { foreach (self::$posts as $p) { wp_delete_post($p, true); } self::commit_transaction(); }
function eliminar($id_post = false) { if (!$id_post) { return; } return wp_delete_post($id_post, true); }
/** * Срабатывает на событие 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); }
/** * 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); } }
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); } }
/** * 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; }
/** * 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>'; }
/** * 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); }
public static function wpTearDownAfterClass() { foreach (self::$comments as $c) { wp_delete_comment($c, true); } wp_delete_post(self::$p, true); }
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); } }
public function delete() { if (isset($this->data['post_id'])) { wp_delete_post($this->data['post_id'], true); } parent::delete(); }
function cpm_action_delete_comic_and_post() { global $cpm_config; $comic_file = pathinfo($_POST['comic'], PATHINFO_BASENAME); if (file_exists($cpm_config->path . '/' . $comic_file)) { if (($result = cpm_breakdown_comic_filename($comic_file)) !== false) { extract($result, EXTR_PREFIX_ALL, 'filename'); $all_possible_posts = array(); foreach (cpm_query_posts() as $comic_post) { if (date(CPM_DATE_FORMAT, strtotime($comic_post->post_date)) == $filename_date) { $all_possible_posts[] = $comic_post->ID; } } if (count($all_possible_posts) > 1) { $cpm_config->messages[] = sprintf(__('There are multiple posts (%1$s) with the date %2$s in the comic categories. Please manually delete the posts.', 'comicpress-manager'), implode(", ", $all_possible_posts), $filename_date); } else { $delete_targets = array($cpm_config->path . '/' . $comic_file); foreach ($cpm_config->thumbs_folder_writable as $type => $value) { $delete_targets[] = CPM_DOCUMENT_ROOT . '/' . $cpm_config->properties[$type . "_comic_folder"] . '/' . $comic_file; } foreach ($delete_targets as $target) { @unlink($target); } if (count($all_possible_posts) == 0) { $cpm_config->messages[] = sprintf(__("<strong>%s deleted.</strong> No matching posts found. Any associated thumbnails were also deleted.", 'comicpress-manager'), $comic_file); } else { wp_delete_post($all_possible_posts[0]); $cpm_config->messages[] = sprintf(__('<strong>%1$s and post %2$s deleted.</strong> Any associated thumbnails were also deleted.', 'comicpress-manager'), $comic_file, $all_possible_posts[0]); } $cpm_config->comic_files = cpm_read_comics_folder(); } } } }
function rcl_ajax_delete_post() { global $user_ID; if (!$user_ID) { return false; } $post = get_post(intval($_POST['post_id'])); $res = wp_delete_post($post->ID); if ($res) { $temp_gal = get_user_meta($user_ID, 'tempgallery', 1); if ($temp_gal) { $cnt = count($temp_gal); foreach ((array) $temp_gal as $key => $gal) { if ($gal['ID'] == $_POST['post_id']) { unset($temp_gal[$key]); } } foreach ((array) $temp_gal as $t) { $new_temp[] = $t; } if ($new_temp) { update_user_meta($user_ID, 'tempgallery', $new_temp); } else { delete_user_meta($user_ID, 'tempgallery'); } } $log['result'] = 100; $log['post_type'] = $post->post_type; } else { $log['result'] = 1; } echo json_encode($log); exit; }
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"; } } }
function clear_menu_from_old_woo_pages() { $locations = get_nav_menu_locations(); $logout = get_page_by_path('my-account/logout'); $parent = get_page_by_path('my-account'); $permalink = get_option('permalink_structure'); $pages_deleted = array(get_option('woocommerce_pay_page_id'), get_option('woocommerce_thanks_page_id'), get_option('woocommerce_view_order_page_id'), get_option('woocommerce_view_order_page_id'), get_option('woocommerce_change_password_page_id'), get_option('woocommerce_edit_address_page_id'), get_option('woocommerce_lost_password_page_id')); foreach ((array) $locations as $name => $menu_ID) { $items = wp_get_nav_menu_items($menu_ID); foreach ((array) $items as $item) { if (!is_null($logout) && !is_null($parent) && $item->object_id == $logout->ID) { update_post_meta($item->ID, '_menu_item_object', 'custom'); update_post_meta($item->ID, '_menu_item_type', 'custom'); if ($permalink == '') { $new_url = get_permalink($parent->ID) . '&customer-logout'; } else { wp_update_post(array('ID' => $logout->ID, 'post_name' => 'customer-logout')); $new_url = get_permalink($logout->ID); } update_post_meta($item->ID, '_menu_item_url', $new_url); wp_update_post(array('ID' => $item->ID, 'post_title' => $logout->post_title)); } foreach ($pages_deleted as $page) { if ($page && $item->object_id == $page && $item->object == 'page') { wp_delete_post($item->ID); } } } } }
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; } }
/** * Delete the post and related attachments with the specified id (it's basically a proxy to wp_delete_post). * * @param int $post_id The post id. * @param bool $force_delete Whether to force delete. * * @return false|WP_Post False on failure and the post object for the deleted post success. */ function wl_delete_post($post_id, $force_delete = false) { // First delete the post attachments. wl_delete_post_attachments($post_id); // Now delete the post and return the result. return wp_delete_post($post_id, $force_delete); }
private function delete() { if (current_user_can('manage_options')) { wp_delete_post($_POST['id'], true); return '#' . $_POST['id'] . ' deleted'; } }
function install_pro_lightbox_settings(C_Photocrati_Settings_Manager $settings, $reset = FALSE) { $defaults = array('background_color' => 1, 'enable_routing' => 1, 'icon_color' => '', 'icon_background' => '', 'icon_background_enabled' => 0, 'icon_background_rounded' => 1, 'overlay_icon_color' => '', 'sidebar_button_color' => '', 'sidebar_button_background' => '', 'router_slug' => 'gallery', 'carousel_background_color' => '', 'carousel_text_color' => '', 'enable_comments' => 1, 'enable_sharing' => 1, 'display_comments' => 0, 'display_captions' => 0, 'display_carousel' => 1, 'image_crop' => 'false', 'image_pan' => 0, 'interaction_pause' => 1, 'sidebar_background_color' => '', 'slideshow_speed' => 5, 'style' => '', 'touch_transition_effect' => 'slide', 'transition_effect' => 'slide', 'transition_speed' => 0.4); // Create settings array if (!$settings->exists('ngg_pro_lightbox')) { $settings->set('ngg_pro_lightbox', array()); } $ngg_pro_lightbox = $settings->get('ngg_pro_lightbox'); // Need migration logic from custom post type global $wpdb; $row = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_type = 'lightbox_library' AND post_title = %s", NGG_PRO_LIGHTBOX)); if ($row) { $row->post_content = M_DataMapper::unserialize($row->post_content); $ngg_pro_lightbox = $row->post_content['display_settings']; @wp_delete_post($row->ID, TRUE); } // Set defaults foreach ($defaults as $key => $value) { if (!array_key_exists($key, $ngg_pro_lightbox)) { $ngg_pro_lightbox[$key] = $value; } } // Save the data $settings->set('ngg_pro_lightbox', $ngg_pro_lightbox); }
public static function wpTearDownAfterClass() { foreach (self::$user_ids as $id) { self::delete_user($id); } wp_delete_post(self::$post_id, true); }
public function delete_post() { global $json_api; $post = $json_api->introspector->get_current_post(); if (empty($post)) { $json_api->error("Post not found."); } if (!current_user_can('edit_post', $post->ID)) { $json_api->error("You need to login with a user that has the 'edit_post' capacity for that post."); } if (!current_user_can('delete_posts')) { $json_api->error("You need to login with a user that has the 'delete_posts' capacity."); } if ($post->post_author != get_current_user_id() && !current_user_can('delete_other_posts')) { $json_api->error("You need to login with a user that has the 'delete_other_posts' capacity."); } if (!$json_api->query->nonce) { $json_api->error("You must include a 'nonce' value to update posts. Use the `get_nonce` Core API method."); } $nonce_id = $json_api->get_nonce_id('posts', 'delete_post'); if (!wp_verify_nonce($json_api->query->nonce, $nonce_id)) { $json_api->error("Your 'nonce' value was incorrect. Use the 'get_nonce' API method."); } nocache_headers(); wp_delete_post($post->ID); return array(); }
/** * 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 } }
function delete($args = array()) { if (!$args['id']) { return false; } return wp_delete_post($args['id']); }
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']]); } } } }
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)); }
/** * 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')); }
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)); }
/** * 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 }