/** * Handle the bulk creation of links */ private function handle_bulk_link() { if (isset($_POST['rp4wp_bulk']) && isset($_GET['rp4wp_parent'])) { // Get parent $parent = $_GET['rp4wp_parent']; // Check if user is allowed to do this $this->check_if_allowed(); // Post Link Manager $post_link_manager = new RP4WP_Post_Link_Manager(); if (count($_POST['rp4wp_bulk']) > 0) { foreach ($_POST['rp4wp_bulk'] as $bulk_post) { // Create link $post_link_manager->add($parent, $bulk_post); } } // Send back $redirect_url = get_admin_url() . "post.php?post={$parent}&action=edit"; // WPML check if (isset($_GET['lang'])) { $redirect_url .= "&lang=" . $_GET['lang']; } wp_redirect($redirect_url); exit; } }
/** * Link x related posts to post * * @param $post_id * @param $amount * * @return boolean */ public function link_related_post($post_id, $amount) { $related_posts = $this->get_related_posts($post_id, $amount); if (count($related_posts) > 0) { $post_link_manager = new RP4WP_Post_Link_Manager(); foreach ($related_posts as $related_post) { $post_link_manager->add($post_id, $related_post->ID); } } update_post_meta($post_id, RP4WP_Constants::PM_POST_AUTO_LINKED, 1); return true; }
/** * Link x related posts to post * * @param $post_id * @param $amount * * @return boolean */ public function link_related_post($post_id, $amount) { $related_posts = $this->get_related_posts($post_id, $amount); if (count($related_posts) > 0) { global $wpdb; $post_link_manager = new RP4WP_Post_Link_Manager(); $batch_data = array(); foreach ($related_posts as $related_post) { $batch_data[] = $post_link_manager->add($post_id, $related_post->ID, true); } // Do batch insert $wpdb->query("INSERT INTO `{$wpdb->posts}`\n\t\t\t\t\t\t(`post_date`,`post_date_gmt`,`post_content`,`post_title`,`post_type`,`post_status`)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t" . implode(',', array_map(array($this, 'batch_data_get_post'), $batch_data)) . "\n\t\t\t\t\t\t"); // Get the first post link insert ID $pid = $wpdb->insert_id; // Set the correct ID's for batch meta insert foreach ($batch_data as $bk => $bd) { $batch_data[$bk]['meta'] = array_map(array($this, 'batch_data_set_pid'), $bd['meta'], array_fill(0, count($bd['meta']), $pid)); $pid++; } // Insert all the meta $wpdb->query("INSERT INTO `{$wpdb->postmeta}`\n\t\t\t\t(`post_id`,`meta_key`,`meta_value`)\n\t\t\t\tVALUES\n\t\t\t\t" . implode(',', array_map(array($this, 'batch_data_get_meta'), $batch_data)) . "\n\t\t\t\t"); } update_post_meta($post_id, RP4WP_Constants::PM_POST_AUTO_LINKED, 1); return true; }