template_type = $this->set_template_type(); // Set the specific template for this view $this->set_active_template(); // Add the filter add_filter( 'the_content', array( &$this, 'apply_template' ), 1 ); } /** * Parses wp_query to determine the template type we are going to use * As of 2.4, the only opiton is single-location * * @since 2.4 */ function set_template_type() { global $post; // Exit if we're not on a single disply of the location post type if ( 'sm-location' != $post->post_type || ! is_single() ) return false; return 'single-location'; } /** * Sets the template we will use for the current view based on a cascading set of rules * If this is a single location view, do the following: * * * @since 2.4 */ function set_active_template() { global $post; // Switch based on template type switch ( $this->template_type ) { case 'single-location' : default : // Grab the ID for the specific template for this post if it is present $template_id = ( get_post_meta( $post->ID, 'sm-location-template', false ) ) ? get_post_meta( $post->ID, 'sm-location-template', false ) : 0; break; } $this->template_id = $template_id; $this->template_structure = $this->get_template_structure(); } /** * Returns the actual template structure we're going to use for this object * * @since 2.4 */ function get_template_structure() { // Grab the post that contains the template strucutre or the hard_coded structure if ( 0 != $this->template_id ) { // get post obejct via ID // return post_content } else { $return = "
"; $return .= "
[sm-location data='iframe-map' map_width='100px' map_height='100px']
"; $return .= "
[sm-location data='full-address']"; $return .= "
Get Directions"; $return .= ""; $return .= "
"; $return .= "
"; $return .= "
"; $return .= "[sm-location data='description']"; return apply_filters( 'sm-single-location-default-template', $return ); } return $return; } /** * This method applies the template to the content * * @since 2.4 */ function apply_template( $content ) { // Return content untouched if not location data if ( ! $this->template_type || ! $this->template_structure ) return $content; // Return if not in the loop if ( ! in_the_loop() ) return $content; // Save the location 'description' $location_description = $content; // Send it through the shortcode parser $content = do_shortcode( $this->template_structure ); return $content; } } }