public function process_async_upload() { header('Content-Type: text/html; charset=' . get_option('blog_charset')); if (!current_user_can('upload_files')) { wp_die(__('You do not have permission to upload files.')); } check_admin_referer($this->nonce_name); try { $attachment_id = media_handle_upload('async-upload', 0, [], ['mimes' => ['mp3|m4a' => 'audio/mpeg'], 'action' => $this->action]); $this->exception_if_error($attachment_id); require_once WPPPT_PLUGIN_PATH . '/migrations/functions.php'; $post_id = \WPPPT\create_new_post(get_post($attachment_id)); $this->exception_if_error($post_id); $podcast_id = intval($_REQUEST['podcast_id']); if (!empty($podcast_id)) { p2p_create_connection('podcast_clip_to_podcast', array('from' => $post_id, 'to' => $podcast_id)); } echo apply_filters('wpppt_async_upload', $attachment_id); } catch (\Exception $e) { echo '<div class="error-div error"> <a class="dismiss" href="#" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">' . __('Dismiss') . '</a> <strong>' . sprintf(__('“%s” has failed to upload.'), esc_html($_FILES['async-upload']['name'])) . '</strong><br />' . esc_html($e->getMessage()) . '</div>'; exit; } }
function connect_new_post_to_connected($post_id, $connect_to) { foreach ($connect_to as $post) { $type = str_replace('attachment', 'podcast_clip', $post['type']); p2p_create_connection($type, array('from' => $post_id, 'to' => $post['id'])); } }
function test_storage_user() { $post_id = $this->generate_post('post')->ID; $user_id = $this->generate_user()->ID; p2p_create_connection('posts_to_users', array('from' => $post_id, 'to' => $user_id)); wp_delete_user($user_id, true); $this->assertConnectionDoesntExist('posts_to_users', array('from' => $post_id)); }
function sfhiv_create_or_update_service_hours($post_ID = false, $post_data, $parent_ID = false) { if (!$post_ID) { if (isset($post_data['day_of_week']) && (isset($post_data['start']) && $post_data['start'] != '') && (isset($post_data['end']) && $post_data['end'] != '')) { $post_ID = wp_insert_post(array('post_type' => 'sfhiv_service_hour', 'post_title' => "will", 'post_content' => "get", 'post_excerpt' => "overwritten"), true); } } if (!$post_ID) { return false; } if ($parent_ID) { $parents = new WP_Query(array('connected_type' => 'service_time', 'connected_items' => $post_ID)); $found = false; foreach ($parents as $parent) { if ($parent->ID == $parent_ID) { $found = true; } } if (!$found) { p2p_create_connection('service_time', array('from' => $parent_ID, 'to' => $post_ID)); } $tax_terms = array('sfhiv_service_category', 'sfhiv_population_category'); foreach ($tax_terms as $tax) { $parent_terms = wp_get_object_terms($parent_ID, $tax, array('fields' => 'slugs')); wp_set_object_terms($post_ID, $parent_terms, $tax); } $parent = get_post($parent_ID); $parent_status = get_post_status($parent_ID); wp_update_post(array('ID' => $post_ID, 'post_status' => $parent_status, 'post_title' => $parent->post_title, 'post_content' => $parent->post_content, 'post_excerpt' => $parent->post_excerpt)); $parent_custom = get_post_custom($parent_ID); foreach ($parent_custom as $custom_key => $custom_value) { delete_post_meta($post_ID, $custom_key); foreach ($custom_value as $meta_value) { add_post_meta($post_ID, $custom_key, $meta_value); } } } // update time sfhiv_service_time_of_day_save_post_update($post_ID); if (isset($post_data['start'])) { $seconds = sfhiv_service_hours_string_to_time($post_data['start']); update_post_meta($post_ID, 'sfhiv_service_start', $seconds); } if (isset($post_data['end'])) { $seconds = sfhiv_service_hours_string_to_time($post_data['end']); update_post_meta($post_ID, 'sfhiv_service_end', $seconds); } if (isset($post_data['sfhiv_location'])) { sfhiv_location_relation_save($post_ID, $post_data['sfhiv_location']); } if (isset($post_data['day_of_week'])) { wp_set_object_terms($post_ID, $post_data['day_of_week'], 'sfhiv_day_of_week_taxonomy', false); if ($parent_ID) { wp_set_object_terms($parent_ID, $post_data['day_of_week'], 'sfhiv_day_of_week_taxonomy', true); } } }
public function connect_post_to_entity($from_post_type, $to_post_type, $from = '', $to = '') { if (!p2p_connection_exists($from_post_type . '_to_' . $to_post_type, array('from' => $from, 'to' => $to))) { p2p_create_connection($from_post_type . '_to_' . $to_post_type, array('from' => $from, 'to' => $to, 'meta' => array('date' => current_time('mysql')))); } }
/** * Connect two items. * * @param int The first end of the connection. * @param int The second end of the connection. * @param array Additional information about the connection. * * @return int p2p_id */ public function connect($from, $to, $meta = array()) { if (!$this->get_current('side')->item_exists($from)) { return false; } if (!$this->get_opposite('side')->item_exists($to)) { return false; } $args = array($from, $to); if ('to' == $this->direction) { $args = array_reverse($args); } if ($this->accepts_single_connection()) { $to_check = 'any'; } elseif ($this->prevent_duplicates) { $to_check = $to; } else { $to_check = false; } if ($to_check && p2p_connection_exists($this->name, array('direction' => $this->direction, 'from' => $args[0], 'to' => $to_check))) { return false; } return p2p_create_connection($this->name, array('from' => $args[0], 'to' => $args[1], 'meta' => array_merge($meta, $this->data))); }
function gdlist_create_connection_for_each_post($cur_post_id, $post_ids) { $listed_posts = gdlist_get_all_listed_posts($cur_post_id); $listed_post_ids = array(); foreach ($listed_posts as $key => $title) { $listed_post_ids[] = (string) $key; } $removed_ids = array_diff($listed_post_ids, $post_ids); $added_ids = array_diff($post_ids, $listed_post_ids); if (current_user_can('edit_post', $cur_post_id)) { foreach ($added_ids as $pid) { $con_type = get_post_type($pid) . '_to_gd_list'; $args = array('from' => $pid, 'to' => $cur_post_id); //$exists = p2p_connection_exists($con_type, $args); //if(!$exists) { p2p_create_connection($con_type, $args); //} } foreach ($removed_ids as $pid) { $con_type = get_post_type($pid) . '_to_gd_list'; $args = array('from' => $pid, 'to' => $cur_post_id); //$exists = p2p_connection_exists($con_type, $args); //if($exists) { p2p_delete_connections($con_type, $args); //} } } }
/** * Update a gig's venue and the gig count for any modified venues. * * @since 1.0.0 */ function set_audiotheme_gig_venue($gig_id, $venue_name) { $gig = get_audiotheme_gig($gig_id); // Retrieve current venue info. $venue_name = trim(stripslashes($venue_name)); if (empty($venue_name)) { p2p_delete_connections('audiotheme_venue_to_gig', array('to' => $gig_id)); } elseif (!isset($gig->venue->name) || $venue_name !== $gig->venue->name) { p2p_delete_connections('audiotheme_venue_to_gig', array('to' => $gig_id)); $new_venue = get_audiotheme_venue_by('name', $venue_name); if (!$new_venue) { $new_venue = array('name' => $venue_name, 'gig_count' => 1); // Timezone is important, so retrieve it from the global $_POST array if it exists. if (!empty($_POST['audiotheme_venue']['timezone_string'])) { $new_venue['timezone_string'] = $_POST['audiotheme_venue']['timezone_string']; } $venue_id = save_audiotheme_venue($new_venue); if ($venue_id) { p2p_create_connection('audiotheme_venue_to_gig', array('from' => $venue_id, 'to' => $gig_id)); } } else { $venue_id = $new_venue->ID; p2p_create_connection('audiotheme_venue_to_gig', array('from' => $new_venue->ID, 'to' => $gig_id)); update_audiotheme_venue_gig_count($new_venue->ID); } } if (isset($gig->venue->ID)) { $venue_id = $gig->venue->ID; update_audiotheme_venue_gig_count($venue_id); } return empty($venue_id) ? false : get_audiotheme_venue($venue_id); }
protected function process_request() { // check if someone entered an email that's already been registered // if so, first step is to make them log in if (!is_user_logged_in() && email_exists($_REQUEST['email'])) { $this->login_required(); return; } // prepare & create the submission if (!is_user_logged_in()) { wp_set_current_user(1); $log_user_out = true; } $submission = $this->prepare_submission(); $new_post = $this->create_submission_post($submission); if (!empty($log_user_out)) { wp_set_current_user(0); } // if that failed, bail if (is_wp_error($new_post)) { $this->errors[] = $new_post->get_error_message(); return; } // connect the submission to the question they were answering $question_id = $_REQUEST['question']; if ($question_id) { p2p_create_connection('submission_to_question', array('from' => $new_post, 'to' => $question_id)); } $this->response['new_user_created'] = false; // if the submitter is not logged in, we need to create a user for them if (!is_user_logged_in()) { $new_user = $this->create_submission_author(); // for some reason we couldn't create the user, delete the submission because // the whole process should fail, then bail if (is_wp_error($new_user)) { $this->errors[] = $new_user->get_error_message(); wp_delete_post($new_post); return; } // the user was successfully created, set them as the submission author $this->set_submission_author($new_post, $new_user); // let the upload page know we created a new user $this->response['new_user_created'] = true; } // we got this far, ok to save uploads to the media library if ($_REQUEST['submissionType'] == 'image') { $image = $this->save_media('image', $new_post); } if (in_array($_REQUEST['submissionType'], array('audio', 'text'))) { $thumbnail = $this->save_media('thumbnail', $new_post); } if ($_REQUEST['submissionType'] == 'audio') { $audio = $this->save_media('audio', $new_post); update_post_meta($new_post, 'audio_url', wp_get_attachment_url($audio)); } if ($_REQUEST['submissionType'] == 'video') { $video_metadata = wp_read_video_metadata($_FILES['video']['tmp_name']); if ($video_metadata['dataformat'] == 'quicktime' && $video_metadata['fileformat'] == 'mp4') { $_FILES['video']['name'] = str_ireplace('.mov', '.mp4', $_FILES['video']['name']); } $video = $this->save_media('video', $new_post); update_post_meta($new_post, 'video_url', wp_get_attachment_url($video)); } // set the featured image if (!empty($image)) { set_post_thumbnail($new_post, $image); update_post_meta($new_post, 'image', $image); } elseif (!empty($thumbnail)) { set_post_thumbnail($new_post, $thumbnail); } $this->response['next'] = 'success'; $this->response['submission'] = get_permalink($new_post); }
/** * AJAX Handler for saving all steps * * @since 1.0.0 * @return void */ function badgeos_update_steps_ajax_handler() { // Only continue if we have any steps if (isset($_POST['steps'])) { // Grab our $wpdb global global $wpdb; // Setup an array for storing all our step titles // This lets us dynamically update the Label field when steps are saved $new_titles = array(); // Loop through each of the created steps foreach ($_POST['steps'] as $key => $step) { // Grab all of the relevant values of that step $step_id = $step['step_id']; $required_count = !empty($step['required_count']) ? $step['required_count'] : 1; $trigger_type = $step['trigger_type']; $achievement_type = $step['achievement_type']; // Clear all relation data $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->p2p} WHERE p2p_to=%d", $step_id)); delete_post_meta($step_id, '_badgeos_achievement_post'); // Flip between our requirement types and make an appropriate connection switch ($trigger_type) { // Connect the step to ANY of the given achievement type case 'any-achievement': $title = sprintf(__('any %s', 'badgeos'), $achievement_type); break; case 'all-achievements': $title = sprintf(__('all %s', 'badgeos'), $achievement_type); break; case 'specific-achievement': p2p_create_connection($step['achievement_type'] . '-to-step', array('from' => absint($step['achievement_post']), 'to' => $step_id, 'meta' => array('date' => current_time('mysql')))); $title = '"' . get_the_title($step['achievement_post']) . '"'; break; case 'badgeos_specific_new_comment': update_post_meta($step_id, '_badgeos_achievement_post', absint($step['achievement_post'])); $title = sprintf(__('comment on post %d', 'badgeos'), $step['achievement_post']); break; default: $triggers = badgeos_get_activity_triggers(); $title = $triggers[$trigger_type]; break; } // Update the step order p2p_update_meta(badgeos_get_p2p_id_from_child_id($step_id), 'order', $key); // Update our relevant meta update_post_meta($step_id, '_badgeos_count', $required_count); update_post_meta($step_id, '_badgeos_trigger_type', $trigger_type); update_post_meta($step_id, '_badgeos_achievement_type', $achievement_type); // Available hook for custom Activity Triggers $custom_title = sprintf(__('Earn %1$s %2$s.', 'badgeos'), $title, sprintf(_n('%d time', '%d times', $required_count), $required_count)); $custom_title = apply_filters('badgeos_save_step', $custom_title, $step_id, $step); // Update our original post with the new title $post_title = !empty($step['title']) ? $step['title'] : $custom_title; wp_update_post(array('ID' => $step_id, 'post_title' => $post_title)); // Add the title to our AJAX return $new_titles[$step_id] = stripslashes($post_title); } // Send back all our step titles echo json_encode($new_titles); } // Cave Johnson. We're done here. die; }
function sfhiv_location_relation_save($post_ID, $location_ID) { p2p_delete_connections('related_location', array("from" => $post_ID)); p2p_create_connection('related_location', array('from' => $post_ID, 'to' => $location_ID)); $taxonomies = get_object_taxonomies(get_post_type($post_ID)); if (in_array('sfhiv_neighborhood_category', $taxonomies)) { $neighborhood_terms = wp_get_object_terms($location_ID, 'sfhiv_neighborhood_category', array('fields' => 'slugs')); wp_set_object_terms($post_ID, $neighborhood_terms, 'sfhiv_neighborhood_category'); } }
function attach_domain_by_url($domain_url) { //get the domain $domain = new foolic_domain($domain_url); if ($domain->ID > 0) { $p2p_id = p2p_type(foolic_post_relationships::LICENSEKEY_TO_DOMAINS)->get_p2p_id($this->ID, $domain->ID); if (!$p2p_id) { $p2p_response = p2p_create_connection(foolic_post_relationships::LICENSEKEY_TO_DOMAINS, array('from' => $this->ID, 'to' => $domain->ID, 'meta' => array('date_connected' => current_time('mysql'), 'attached' => '1'))); if ($p2p_response !== false) { //make sure domains are not cached $this->_domains = false; $this->_attached_domains = false; $this->process_domains(); } } else { //we have an existing connection p2p_add_meta($p2p_id, 'attached', '1', true); //make sure domains are not cached $this->_domains = false; $this->_attached_domains = false; $this->process_domains(); } return $domain; } return false; }
function link_to_licensekey($licensekey_id) { p2p_create_connection(foolic_post_relationships::LICENSE_TO_LICENSEKEY, array('from' => $this->ID, 'to' => $licensekey_id)); }