/** * Save function for contact company * * @global array $contact_fields List of contact fields * @param string $field_name Field Name to be saved * @param id $post_id Post ID * @since 0.1 */ function rolo_save_contact_company($field_name, $post_id) { global $contact_fields; $company_field = $contact_fields[$field_name]; $company_name = $_POST['rolo_contact_' . $company_field['name']]; if ($company_name != '') { // Set the custom taxonmy for the post wp_set_post_terms($post_id, $company_name, 'company'); $company_id = get_post_by_title(stripslashes($company_name)); if (!$company_id) { // create an empty post for company $new_post = array(); $new_post['post_title'] = $company_name; $new_post['post_type'] = 'post'; $new_post['post_status'] = 'publish'; $company_id = wp_insert_post($new_post); // Store only company name as seperate custom field update_post_meta($company_id, 'rolo_company_name', $company_name); $new_company = array(); $new_company['rolo_company_name'] = $company_name; update_post_meta($company_id, 'rolo_company', $new_company); // Set the custom taxonmy for the post wp_set_post_terms($company_id, 'Company', 'type'); wp_set_post_terms($company_id, $company_name, 'company'); } } }
function display_page($title) { $post = get_post_by_title($title); if (!$post) { echo 'Please add a page with the title "' . $title . '".'; } else { echo do_shortcode($post->post_content); } }
/** * Create initial posts (contact and company) * @global object $wpdb * @since 1.4 */ function rolo_create_initial_posts() { global $wpdb; //TODO: Check for proper user permission /* NO NEED RIGHT NOW $company_name = "RoloPress Inc"; $company_website = "www.RoloPress.com"; $company_twitter = "rolopress"; $company_email = "*****@*****.**"; $contact_first_name = "Rolo"; $contact_last_name = "Press"; $contact_name = $contact_first_name . " " . $contact_last_name; // Create a default company $default_company_post = get_post_by_title($company_name); if (!($default_company_post->ID > 0)) { $new_post = array(); $new_post['post_title'] = $company_name; $new_post['post_type'] = 'post'; $new_post['post_content'] = 'This is a sample company. You can delete this if you like.<br/>You might be interested to know that the company picture is being pulled from twitter.'; $new_post['post_status'] = 'publish'; $post_id = wp_insert_post($new_post); update_post_meta($post_id, 'rolo_company_name', $company_name); $new_company = array(); $new_company['rolo_company_name'] = $company_name; $new_company['rolo_company_website'] = $company_website; $new_company['rolo_company_twitter'] = $company_twitter; $new_company['rolo_company_email'] = $company_email; update_post_meta($post_id, 'rolo_company' , $new_company); wp_set_post_terms($post_id, 'Company', 'type'); $current_name = wp_get_post_terms($post_id, 'company'); if (count($current_name) > 0) { //update the current taxonomy $new_value = array(); $new_value['name'] = $company_name; $new_value['term_id'] = $current_name[0]->term_id; wp_update_term($current_name[0]->term_id, 'company', $new_value); } else { // create the new taxonomy wp_set_post_terms($post_id, $company_name, 'company', true); } }*/ $contact_first_name = "SOS"; $contact_last_name = ""; $contact_name = $contact_first_name . " " . $contact_last_name; $sos = '112'; // Create a default contact $default_contact_post = get_post_by_title($contact_name); if (!($default_contact_post->ID > 0)) { $new_post = array(); $new_post['post_title'] = $contact_name; $new_post['post_type'] = 'post'; $new_post['post_content'] = 'Este é o contacto que vem com a aplicação'; $new_post['post_status'] = 'publish'; $post_id = wp_insert_post($new_post); update_post_meta($post_id, 'rolo_contact_first_name', $contact_name); $new_contact = array(); $new_contact['rolo_contact_first_name'] = $contact_first_name; $new_contact['rolo_contact_last_name'] = $contact_last_name; $new_contact['rolo_contact_phone_'] = $sos; update_post_meta($post_id, 'rolo_contact', $new_contact); wp_set_post_terms($post_id, 'Contact', 'type'); // Set the custom taxonmy for the post } }
function aigashow_import_winners_from_csv() { ?> <div class='wrap'> <?php screen_icon('tools'); ?> <h2><?php _e('CSV Winners Importer'); ?> </h2> <?php if (isset($_GET['sheet'])) { $sheet = get_attached_file($_GET['sheet']); $row = 0; if (($handle = fopen($sheet, "r")) !== false) { while (($data = fgetcsv($handle, 0, ",")) !== false) { $row++; $student = get_post_by_title($data[1], 'student'); if ($student === false) { echo "<p>Entry {$row} is Professional work.</p>"; } else { if (!term_exists($data[0], 'student-winner')) { wp_insert_term($data[0], 'student-winner', array('slug' => sanitize_title('student-' . $data[0]))); } wp_set_object_terms($student->ID, sanitize_title('student-' . $data[0]), 'student-winner'); echo "<p>Updated existing Student entry for row {$row}.</p>"; } $professional = get_post_by_title($data[1], 'professional'); if ($professional === false) { echo "<p>Entry {$row} was Student work.</p>"; } else { if (!term_exists($data[0], 'professional-winner')) { wp_insert_term($data[0], 'professional-winner', array('slug' => sanitize_title('professional-' . $data[0]))); } wp_set_object_terms($professional->ID, sanitize_title('professional-' . $data[0]), 'professional-winner'); echo "<p>Updated existing Professional entry for row {$row}.</p>"; } } } fclose($handle); } else { $args = array('post_type' => 'attachment', 'post_mime_type' => 'text/csv', 'numberposts' => -1, 'post_status' => null); $attachments = get_posts($args); ?> <?php if ($attachments) { ?> <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?> "> <input type="hidden" id="page" name="page" value="<?php echo $_GET['page']; ?> " /> <table class="form-table"> <tr> <th> <label for="sheet">Select a CSV file: </label> </th> <td> <select id="sheet" name="sheet" style="width:100%"> <?php foreach ($attachments as $attachment) { ?> <option value="<?php echo $attachment->ID; ?> "><?php echo $attachment->post_title; ?> </option> <?php } ?> </select> </td> </tr> </table> <input type="submit" value="Import" class="button-primary" /> </form> <?php } else { ?> <h3>No CSV files found.</h3> <?php } } ?> </div> <?php }
function post_author_link($class, $after, $linkToProfile) { global $post; $temps = $post; $people = wp_get_object_terms($post->ID, 'people'); foreach ($people as $author) { $name = $author->name; if ($author) { if ($linkToProfile) { $post = get_post_by_title($name); $person_link = get_permalink(); } else { // link to archive page $person_link = get_term_link($name, 'people'); } echo "<a href='{$person_link}' class='{$class}' title='{$name}'>{$name}</a>{$after}"; } } $post = $temps; }