function keel_pet_listings_add_custom_post_type() { // Check that feature is activated $dev_options = keel_developer_options(); if (!$dev_options['pets']) { return; } $options = keel_pet_listings_get_theme_options(); $labels = array('name' => _x('Pets', 'post type general name', 'keel'), 'singular_name' => _x('Pet', 'post type singular name', 'keel'), 'add_new' => _x('Add New', 'course', 'keel'), 'add_new_item' => __('Add New Pet', 'keel'), 'edit_item' => __('Edit Pet', 'keel'), 'new_item' => __('New Pet', 'keel'), 'all_items' => __('All Pets', 'keel'), 'view_item' => __('View Pet', 'keel'), 'search_items' => __('Search Pets', 'keel'), 'not_found' => __('No pets found', 'keel'), 'not_found_in_trash' => __('No pets found in the Trash', 'keel'), 'parent_item_colon' => '', 'menu_name' => __('Pet Listings', 'keel')); $args = array('labels' => $labels, 'description' => 'Holds our pets and pet-specific data from Petfinder', 'public' => true, 'menu_icon' => 'dashicons-screenoptions', 'has_archive' => true, 'rewrite' => array('slug' => $options['slug']), 'map_meta_cap' => true, 'capabilities' => array('create_posts' => false, 'edit_published_posts' => false, 'delete_posts' => false, 'delete_published_posts' => false)); register_post_type('pets', $args); }
/** * Retrieve pet data from Petfinder * @return Array Pet data */ function keel_petfinder_api_get_pet_data() { // Get settings $settings = keel_petfinder_api_get_settings(); $options = keel_pet_listings_get_theme_options(); if (empty($options['developer_key']) || empty($options['shelter_id'])) { return; } // Variables $base_url = 'http://api.petfinder.com/shelter.getPets?'; $params = http_build_query(array('format' => 'json', 'key' => $options['developer_key'], 'id' => $options['shelter_id'], 'count' => $options['count'], 'status' => 'A', 'output' => 'full')); // Get API data $request = wp_remote_get($base_url . $params); $response = wp_remote_retrieve_body($request); $data = json_decode($response, true); // If there was an error, return null if (intval($data['petfinder']['header']['status']['code']['$t']) !== 100) { return null; } // If set to display newest first, reverse pet order return $settings['newest_first'] ? array_reverse($data['petfinder']['pets']['pet']) : $data['petfinder']['pets']['pet']; }
function keel_pet_listings_theme_options_render_page() { $options = keel_pet_listings_get_theme_options(); ?> <div class="wrap"> <h2><?php _e('Pet Listings Options', 'keel'); ?> </h2> <?php // If required API data is not yet provided if (empty($options['developer_key']) || empty($options['shelter_id'])) { if (empty($options['developer_key']) && empty($options['shelter_id'])) { $message = 'Please enter a <a href="https://www.petfinder.com/developers/api-docs">Petfinder developer key</a> and shelter ID to begin using the Petfinder API.'; } elseif (empty($options['developer_key'])) { $message = 'Please enter a <a href="https://www.petfinder.com/developers/api-docs">Petfinder developer key</a> to begin using the Petfinder API.'; } else { $message = 'Please enter a shelter ID to begin using the Petfinder API.'; } ?> <div class="error"> <p><?php _e($message, 'keel'); ?> </p> </div> <?php } ?> <?php // If API failed on it's last run $api_error = get_transient('keel_petfinder_api_get_pets_error'); if (!empty($api_error)) { ?> <div class="error"> <p><?php echo $api_error; ?> </p> </div> <?php } ?> <?php settings_errors(); ?> <?php $timestamp = get_transient('keel_petfinder_api_get_pets_timestamp'); if (!empty($timestamp)) { ?> <p><?php printf(__('Petfinder API data was last retrieved on %s at %s.', 'keel'), date('F j, Y', $timestamp), date('g:i a', $timestamp)); ?> </p> <?php } ?> <form method="post" action="options.php"> <?php settings_fields('keel_pet_listings_options'); do_settings_sections('keel_pet_listings_theme_options'); wp_nonce_field('keel_pet_listings_update_options_nonce', 'keel_pet_listings_update_options_process'); submit_button(); ?> </form> </div> <?php }
<?php /** * content-pets.php * Template for "pets" custom post type content. */ ?> <?php // Variables $options = keel_pet_listings_get_theme_options(); // Pet Listings options $details = get_post_meta($post->ID, 'keel_pet_listings_pet_details', true); // Details for this pet $imgs = get_post_meta($post->ID, 'keel_pet_listings_pet_imgs', true); // Images for this pet ?> <?php /** * Individual Pet Listings */ if (is_single()) { ?> <article class="container"> <header> <h1 class="no-margin-bottom"><?php the_title(); ?>