Using within a custom Plugin
-
I have a custom plugin that I want to place the content within tabs. I am unable to figure out how to get this work properly.
<?php /** * FoxtrottProperties. * * @package FoxtrottProperties * @author Your Name <email@example.com> * @license GPL-2.0+ * @link http://example.com * @copyright 2013 Your Name or Company Name */ /** * @package FoxtrottProperties * @author Your Name <email@example.com> */ $tabbyOverview = do_shortcode('[tabby title="Overview"]'); $tabbyMap = do_shortcode('[tabby title="Map"]'); $tabbyPhotos = do_shortcode('[tabby title="Photos"]'); $tabbyend = do_shortcode('[tabbyending]'); class FoxtrottProperties { /** * Plugin version, used for cache-busting of style and script file references. * * @since 1.0.0 * * @var string */ const VERSION = '1.0.0'; /** * Unique identifier for your plugin. * * * The variable name is used as the text domain when internationalizing strings * of text. Its value should match the Text Domain file header in the main * plugin file. * * @since 1.0.0 * * @var string */ protected $plugin_slug = 'foxtrot-properties'; /** * @var string * * Prefix used for plugin custom variables */ protected $slug = 'property'; /** * Instance of this class. * * @since 1.0.0 * * @var object */ protected static $instance = null; /** * Initialize the plugin by setting localization and loading public scripts * and styles. * * @since 1.0.0 */ private function __construct() { require_once(plugin_dir_path(__FILE__) . '../foxtrot-properties-core.php'); // Load plugin text domain add_action('init', array($this, 'load_plugin_textdomain')); // Activate plugin when new blog is added add_action('wpmu_new_blog', array($this, 'activate_new_site')); // Load public-facing style sheet and JavaScript. add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts')); /* Define custom functionality. * Refer To http://codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters */ // Initialize core assets add_action('init', 'foxtrot_core_init'); // if ( class_exists( 'foxtrotBio' ) ){ // add_action( 'pre_get_posts', array( $this ,'foxtrot_listings_alter_query' )); // } add_filter('the_content', array($this, 'foxtrot_display_property')); add_filter('foxtrot_property_sidebar_content', array($this, 'foxtrot_sidebar_display_property')); add_filter('foxtrot_property_sidebar_map', array($this, 'foxtrot_display_map_action')); } /** * @param $content * @return string * * Filter for the_content to display property data */ function foxtrot_display_property($content) { global $post; if (null !== $post) { if ('property' !== get_post_type($post->ID)) { return $content; } $meta = get_post_meta($post->ID); // Single, large featured property image added to content if available if (has_post_thumbnail($post->ID)) { $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'foxtrot-property-main'); $content .= '<div class="feature-image img-responsive"><img src=' . $large_image_url[0] . ' class="img-responsive img-thumbnail" /></div>'; } else { $content .= '<div class="feature-image"><img class="img-responsive img-thumbnail" src="' . (get_stylesheet_directory_uri() . '/assets/img/property-holder-image.jpg' . '" height="480" ></div>'); } // Collect all Property Data and table $building_size = $meta['foxtrot_building_size']; $building_size = (empty($building_size[0]) ? '' : number_format((float)$building_size[0]) . ' sq. ft.'); $lease_rate_type = $meta['foxtrot_nnn']; $lease_rate = $meta['foxtrot_lease_rate']; $lease_rate = (empty($lease_rate[0]) ? 'For sale only' : '$' . number_format((float)$lease_rate[0], 2) . ' per sq. ft. <br/>' . $lease_rate_type[0]); $total_sf = $meta['foxtrot_space_available']; $total_sf = (empty($total_sf[0]) ? '' : number_format((float)$total_sf[0]) . ' sq. ft.'); $price = $meta['foxtrot_price']; $price = (empty($price[0]) ? 'Lease only' : '$' . number_format((float)$price[0])); $min_size = $meta['foxtrot_space_available_min']; $min_size = (empty($min_size[0]) ? '' : number_format((float)$min_size[0]) . ' sq. ft.'); $max_size = $meta['foxtrot_space_available_max']; $max_size = (empty($max_size[0]) ? '' : number_format((float)$max_size[0]) . ' sq. ft.'); $retx = $meta['foxtrot_retx']; $opex = $meta['foxtrot_opex']; $retx = (empty($retx[0]) ? '' : '$' . $retx[0] . ' per sq. ft. (est)'); $opex = (empty($opex[0]) ? '' : '$' . $opex[0] . ' per sq. ft. (est)'); $pdf_url = ''; global $num_property_suites; for ($i = 1; $i <= $num_property_suites; $i++) { ${"suite_".$i} = isset($meta["foxtrot_suite_{$i}"]) ? $meta["foxtrot_suite_{$i}"] : ""; ${"suite_".$i."_size"} = isset($meta["foxtrot_suite_size_{$i}"]) ? $meta["foxtrot_suite_size_{$i}"] : ""; ${"suite_".$i."_photos"} = isset($meta["foxtrot_suite_photos_{$i}"]) ? $meta["foxtrot_suite_photos_{$i}"] : ""; ${"suite_".$i."_videos"} = isset($meta["foxtrot_suite_videos_{$i}"]) ? $meta["foxtrot_suite_videos_{$i}"] : ""; ${"suite_".$i."_notes"} = isset($meta["foxtrot_suite_notes_{$i}"]) ? $meta["foxtrot_suite_notes_{$i}"] : ""; ${"suite_".$i."_min_divisible"} = isset($meta["foxtrot_min_divisible_suite_{$i}"]) ? $meta["foxtrot_min_divisible_suite_{$i}"] : ""; ${"suite_".$i."_max_contig"} = isset($meta["foxtrot_max_contig_suite_{$i}"]) ? $meta["foxtrot_max_contig_suite_{$i}"] : ""; ${"suite_".$i."_lease_rate"} = isset($meta["foxtrot_suite_lease_rate_{$i}"]) ? $meta["foxtrot_suite_lease_rate_{$i}"] : ""; ${"suite_".$i."_lease_type"} = isset($meta["foxtrot_suite_lease_type_{$i}"]) ? $meta["foxtrot_suite_lease_type_{$i}"] : ""; } /* $suite_1 = isset($meta['foxtrot_suite_1']) ? $meta['foxtrot_suite_1'] : ''; $suite_1_size = isset($meta['foxtrot_suite_size_1']) ? $meta['foxtrot_suite_size_1'] : ''; $suite_1_photos = isset($meta['foxtrot_suite_photos_1']) ? $meta['foxtrot_suite_photos_1'] : ''; $suite_1_videos = isset($meta['foxtrot_suite_videos_1']) ? $meta['foxtrot_suite_videos_1'] : ''; $suite_1_notes = isset($meta['foxtrot_suite_notes_1']) ? $meta['foxtrot_suite_notes_1'] : ''; $suite_1_min_divisible = isset($meta['foxtrot_min_divisible_suite_1']) ? $meta['foxtrot_min_divisible_suite_1'] : ''; $suite_1_max_contig = isset($meta['foxtrot_max_contig_suite_1']) ? $meta['foxtrot_max_contig_suite_1'] : ''; $suite_1_lease_rate = isset($meta['foxtrot_suite_lease_rate_1']) ? $meta['foxtrot_suite_lease_rate_1'] : ''; $suite_1_lease_type = isset($meta['foxtrot_suite_lease_type_1']) ? $meta['foxtrot_suite_lease_type_1'] : ''; $suite_2 = isset($meta['foxtrot_suite_2']) ? $meta['foxtrot_suite_2'] : ''; $suite_2_size = isset($meta['foxtrot_suite_size_2']) ? $meta['foxtrot_suite_size_2'] : ''; $suite_2_photos = isset($meta['foxtrot_suite_photos_2']) ? $meta['foxtrot_suite_photos_2'] : ''; $suite_2_videos = isset($meta['foxtrot_suite_videos_2']) ? $meta['foxtrot_suite_videos_2'] : ''; $suite_2_notes = isset($meta['foxtrot_suite_notes_2']) ? $meta['foxtrot_suite_notes_2'] : ''; $suite_2_min_divisible = isset($meta['foxtrot_min_divisible_suite_2']) ? $meta['foxtrot_min_divisible_suite_2'] : ''; $suite_2_max_contig = isset($meta['foxtrot_max_contig_suite_2']) ? $meta['foxtrot_max_contig_suite_2'] : ''; $suite_2_lease_rate = isset($meta['foxtrot_suite_lease_rate_2']) ? $meta['foxtrot_suite_lease_rate_2'] : ''; $suite_2_lease_type = isset($meta['foxtrot_suite_lease_type_2']) ? $meta['foxtrot_suite_lease_type_2'] : ''; $suite_3 = isset($meta['foxtrot_suite_3']) ? $meta['foxtrot_suite_3'] : ''; $suite_3_size = isset($meta['foxtrot_suite_size_3']) ? $meta['foxtrot_suite_size_3'] : ''; $suite_3_photos = isset($meta['foxtrot_suite_photos_3']) ? $meta['foxtrot_suite_photos_3'] : ''; $suite_3_videos = isset($meta['foxtrot_suite_videos_3']) ? $meta['foxtrot_suite_videos_3'] : ''; $suite_3_notes = isset($meta['foxtrot_suite_notes_3']) ? $meta['foxtrot_suite_notes_3'] : ''; $suite_3_min_divisible = isset($meta['foxtrot_min_divisible_suite_3']) ? $meta['foxtrot_min_divisible_suite_3'] : ''; $suite_3_max_contig = isset($meta['foxtrot_max_contig_suite_3']) ? $meta['foxtrot_max_contig_suite_3'] : ''; $suite_3_lease_rate = isset($meta['foxtrot_suite_lease_rate_3']) ? $meta['foxtrot_suite_lease_rate_3'] : ''; $suite_3_lease_type = isset($meta['foxtrot_suite_lease_type_3']) ? $meta['foxtrot_suite_lease_type_3'] : ''; $suite_4 = isset($meta['foxtrot_suite_4']) ? $meta['foxtrot_suite_4'] : ''; $suite_4_size = isset($meta['foxtrot_suite_size_4']) ? $meta['foxtrot_suite_size_4'] : ''; $suite_4_photos = isset($meta['foxtrot_suite_photos_4']) ? $meta['foxtrot_suite_photos_4'] : ''; $suite_4_videos = isset($meta['foxtrot_suite_videos_4']) ? $meta['foxtrot_suite_videos_4'] : ''; $suite_4_notes = isset($meta['foxtrot_suite_notes_4']) ? $meta['foxtrot_suite_notes_4'] : ''; $suite_4_max_contig = isset($meta['foxtrot_max_contig_suite_4']) ? $meta['foxtrot_max_contig_suite_4'] : ''; $suite_4_min_divisible = isset($meta['foxtrot_min_divisible_suite_4']) ? $meta['foxtrot_min_divisible_suite_4'] : ''; $suite_4_lease_rate = isset($meta['foxtrot_suite_lease_rate_4']) ? $meta['foxtrot_suite_lease_rate_4'] : ''; $suite_4_lease_type = isset($meta['foxtrot_suite_lease_type_4']) ? $meta['foxtrot_suite_lease_type_4'] : ''; $suite_5 = isset($meta['foxtrot_suite_5']) ? $meta['foxtrot_suite_5'] : ''; $suite_5_size = isset($meta['foxtrot_suite_size_5']) ? $meta['foxtrot_suite_size_5'] : ''; $suite_5_photos = isset($meta['foxtrot_suite_photos_5']) ? $meta['foxtrot_suite_photos_5'] : ''; $suite_5_videos = isset($meta['foxtrot_suite_videos_5']) ? $meta['foxtrot_suite_videos_5'] : ''; $suite_5_notes = isset($meta['foxtrot_suite_notes_5']) ? $meta['foxtrot_suite_notes_5'] : ''; $suite_5_max_contig = isset($meta['foxtrot_max_contig_suite_5']) ? $meta['foxtrot_max_contig_suite_5'] : ''; $suite_5_min_divisible = isset($meta['foxtrot_min_divisible_suite_5']) ? $meta['foxtrot_min_divisible_suite_5'] : ''; $suite_5_lease_rate = isset($meta['foxtrot_suite_lease_rate_5']) ? $meta['foxtrot_suite_lease_rate_5'] : ''; $suite_5_lease_type = isset($meta['foxtrot_suite_lease_type_5']) ? $meta['foxtrot_suite_lease_type_5'] : ''; */ // Set the number of suites $suite_count = 0; for ($i = 1; $i <= $num_property_suites; $i++) { $suite_count += ( ! empty( ${'suite_'.$i}[0] ) ) ? 1 : 0; } // Do we have any brochure attachments? $brochure_query = array(array( 'taxonomy' => 'attachment_type', 'field' => 'slug', 'terms' => 'brochure' )); $brochures = foxtrot_get_pdfs($post, $brochure_query); if ($brochures) { if (is_array($brochures)) { foreach ($brochures as $brochure) { $pdf_url = $brochure->guid; } } } // Do we have any image attachments? $image_query = array( 'taxonomy' => 'attachment_type', 'field' => 'slug', 'terms' => 'photo' ); $images = foxtrot_get_images($post, $image_query); // Video? $video_link = $meta['foxtrot_video_link']; $video_link = (empty($video_link[0]) ? '' : '$' . $video_link[0]); // Collect additional images and place into slideshow array $imagecdata = ''; $photosdisabled = ' disabled'; if (is_array($images) || '' != $images) { $photosdisabled = ''; $imagecdata .= ' <script> //<![CDATA[ var propertyPhotos = ['; foreach ($images as $image) { $imagecdata .= ' { href: "' . wp_get_attachment_url($image->ID) . '", title: "' . $image->post_excerpt . '" },'; } $imagecdata .= ' ] //]]> </script> '; } $pdf_disabled = '' == $pdf_url ? ' inactive' : ''; echo $tabbyOverview; $content .= $imagecdata; $content .= ''; /* $content .= '<div class="row btn-featured"> <div class="col-xs-5"> <a href="' . $pdf_url . '" class="' . $pdf_disabled . ' feature" target="_blank"><i class="fa fa-download"></i> Property Brochure</a> </div> <div class="col-xs-5"> <a href="javascript:;" class="openfancybox feature' . $photosdisabled . '"><i class="fa fa-camera"></i> Photo Slideshow</a> </div> </div>'; */ $content .= '<div class="row btn-featured"> <div class="col-xs-5"> <a href="javascript:;" class="openfancybox feature' . $photosdisabled . '"><i class="fa fa-camera"></i> Photo Slideshow</a> </div> </div>'; // Property Information $content .= '<h3>Property Information</h3>'; $content .= '<div class="table-responsive">'; $content .= '<table class="table table-striped">'; $content .= '<tbody>'; $content .= '<tr><td class="label"><label>Building Size</label>: </td><td class="data">' . $building_size . '</td><td class="label"><label>Lease Rate</label>: </td><td class="data">' . $lease_rate . '</td></tr>'; $content .= '<tr><td class="label"><label>Min. Size</label>: </td><td class="data">' . $min_size . '</td><td class="label"><label>RETX</label>: </td><td class="data">' . $retx . '</td></tr>'; $content .= '<tr><td class="label"><label>Max. Size</label>: </td><td class="data">' . $max_size . '</td><td class="label"><label>OPEX</label>: </td><td class="data">' . $opex . '</td></tr>'; $content .= '<tr><td class="label"><label>Total sq. ft.</label>: </td><td class="data">' . $total_sf . '</td><td class="label"><label>Sale Price</label>: </td><td class="data">' . $price . '</td></tr>'; $content .= '</tbody>'; $content .= '</table>'; $content .= '</div><!-- /.table-responsive -->'; // Space Available $content .= '<h3 class="spaceavailable">Space Availability: <span>' . $suite_count . ' spaces</span></h3>'; $content .= "<!-- Suite Count: $suite_count -->"; // #B82C16 // #A81B15 // for ($i = 1; $i <= $num_property_suites; $i++) { $content .= $this->render_suite_block( $i, ${'suite_'.$i}, ${'suite_'.$i.'_size'}, ${'suite_'.$i.'_notes'}, ${'suite_'.$i.'_min_divisible'}, ${'suite_'.$i.'_max_contig'}, ${'suite_'.$i.'_lease_rate'}, ${'suite_'.$i.'_lease_type'} ); } /* $content .= $this->render_suite_block(2, $suite_2, $suite_2_size, $suite_2_notes, $suite_2_min_divisible, $suite_2_max_contig, $suite_2_lease_rate, $suite_2_lease_type); $content .= $this->render_suite_block(3, $suite_3, $suite_3_size, $suite_3_notes, $suite_3_min_divisible, $suite_3_max_contig, $suite_3_lease_rate, $suite_3_lease_type); $content .= $this->render_suite_block(4, $suite_4, $suite_4_size, $suite_4_notes, $suite_4_min_divisible, $suite_4_max_contig, $suite_4_lease_rate, $suite_4_lease_type); $content .= $this->render_suite_block(5, $suite_5, $suite_5_size, $suite_5_notes, $suite_5_min_divisible, $suite_5_max_contig, $suite_5_lease_rate, $suite_5_lease_type); $content .= $this->render_suite_block(6, $suite_6, $suite_6_size, $suite_6_notes, $suite_6_min_divisible, $suite_6_max_contig, $suite_6_lease_rate, $suite_6_lease_type); */ $content .= "<!--<p>Suite Count: $suite_count</p>-->"; return $content; } } /** * @param $post * @param $size * @param $additional_class * @return string * * Get img src block with featured image or '' */ function get_featured_image($post, $size = '', $additional_class = '') { $content = ''; $thumb_size = 'foxtrot-property-main'; if ('' != $size) { $thumb_size = $size; } if (has_post_thumbnail($post->ID)) { $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $thumb_size); $content .= '<div class="feature-image"><img src=' . $large_image_url[0] . ' height=' . $large_image_url[2] . ' class="img-responsive img-thumbnail ' . $additional_class . '" /></div>'; return $content; } else { return ''; } } function foxtrot_sidebar_display_property($content) { global $post; if ('property' !== get_post_type($post->ID)) { return $content; } $meta = get_post_meta($post->ID); $address = $meta['foxtrot_address']; $website = $meta['foxtrot_website']; $city = $meta['foxtrot_city']; $state = $meta['foxtrot_state']; $zip = $meta['foxtrot_zip']; $broker1_name = $meta['foxtrot_contact_name_1']; $broker1_phone = $meta['foxtrot_contact_number_1']; $broker1_email = $meta['foxtrot_contact_email_1']; $broker2_name = $meta['foxtrot_contact_name_2']; $broker2_phone = $meta['foxtrot_contact_number_2']; $broker2_email = $meta['foxtrot_contact_email_2']; $broker1_id = $meta['foxtrot_broker_1']; $broker2_id = $meta['foxtrot_broker_2']; $description = $meta['foxtrot_property_description']; $bio = foxtrotBioDisplay::getInstance(); $broker1_cell = $bio->foxtrot_get_cell($broker1_id[0]); $broker2_cell = $bio->foxtrot_get_cell($broker2_id[0]); $email_subject_address = $address[0] . ' in ' . $city[0]; // Do we have any brochure attachments? $brochure_query = array( 'taxonomy' => 'attachment_type', 'field' => 'slug', 'terms' => 'brochure' ); $brochures = foxtrot_get_pdfs($post, $brochure_query); if ($brochures) { if (is_array($brochures)) { foreach ($brochures as $brochure) { $pdf_url = $brochure->guid; } } } // Do we have any image attachments? $image_query = array( 'taxonomy' => 'attachment_type', 'field' => 'slug', 'terms' => 'photo' ); $images = foxtrot_get_images($post, $image_query); // Video? $video_link = $meta['foxtrot_video_link']; $video_link = (empty($video_link[0]) ? '' : '$' . $video_link[0]); // Collect additional images and place into slideshow array $imagecdata = ''; $photosdisabled = ' disabled'; if (is_array($images) || '' != $images) { $photosdisabled = ''; $imagecdata .= ' <script> //<![CDATA[ var propertyPhotos = ['; foreach ($images as $image) { $imagecdata .= ' { href: "' . wp_get_attachment_url($image->ID) . '", title: "' . $image->post_excerpt . '" },'; } $imagecdata .= ' ] //]]> </script> '; } $content .= '<p>' . $address[0] . '<br/> ' . $city[0] . ', ' . $state[0] . ', ' . $zip[0] . '</p>'; $content .= '<p>' . $website[0] . '</p>'; $content .= '<h3>Property Description</h3>'; $content .= '<p>' . $description[0] . '</p>'; $content .= '<p><a href="' . $pdf_url . '" class="' . $pdf_disabled . ' feature" target="_blank"><i class="fa fa-download"></i> Property Brochure</a> </p>'; //$content .= '<h3>Property Downloads</h3>'; // Buttons $pdf_disabled = '' == $pdf_url ? ' inactive' : ''; $video_disabled = '' == $video_link ? ' inactive' : ''; //$buttons = '<div class="row">'; //$buttons .= '<div class="col-xs-4"><a href="javascript:;" class="openfancybox' . $photosdisabled . '"><img src="%1$s" class="img-responsive" width="206"/></a>%5$s</div>'; //$buttons .= '<div class="col-xs-4 colcenter' . $video_disabled . '"><a href="#"><img src="%2$s" class="img-responsive" width="166" /></a></div>'; //$buttons .= '<div class="col-xs-4 ' . $pdf_disabled . '"><a href="%4$s" class="foxtrot_links" target="_blank"><img src="%3$s" width="231" class="img-responsive" /></a></div></div>'; //$content .= '<a href="javascript:;" class="openfancybox' . $photosdisabled . '"><i class="fa fa-camera"></i> View Slideshow</a>'; //$content .= '<a href="' . $pdf_url . '" class="' . $pdf_disabled . '" target="_blank"><i class="fa fa-download"></i> Download Brochure</a>'; //$content .= '<div class="' . $video_disabled . '"><a href="javascript:;" class="openfancybox' . $video_disabled . '"><i class="fa fa-play-circle-o"></i> Watch Video</a></div>'; $content .= '<div class="row">'; if ('' != $broker2_email[0]) { $content .= '<div class="brokers col-xs-12 two">'; } else { $content .= '<div class="brokers col-xs-12">'; } $content .= '<h3>Contact</h3>'; $content .= '<div class="row">'; $content .= '<div class="broker col-xs-6">'; $content .= '<p><h4>' . $broker1_name[0] . '</h4></p>'; $content .= '<p>Direct <span>' . $broker1_phone[0] . '</span></p>'; $content .= '<p>Mobile <span>' . $broker1_cell . '</span></p>'; $content .= '<p>Mobile <span>' . $broker1_cell . '</span></p>'; $content .= '<p><a target="_blank" href="mailto:' . $broker1_email[0] . '?subject=' . $email_subject_address . '">Email</a></p>'; $content .= '</div>'; $content .= '<div class="broker col-xs-6">'; if ('' != $broker2_email[0]) { $content .= '<p><a href="mailto:' . $broker2_email[0] . '?subject=' . $email_subject_address . '">' . $broker2_name[0] . '</a></p>'; $content .= '<p>Direct <span>' . $broker2_phone[0] . '</span></p>'; $content .= '<p>Mobile <span>' . $broker2_cell . '</span></p>'; } $content .= '</div>'; $content .= '</div><!--brokers-->'; $content .= '</div>'; $content .= '<div class="row">'; $content .= apply_filters('foxtrot_property_sidebar_map', ''); $content .= '</div>'; $content .= '</div>'; return $content; } /** * @param $content * @return string * * // Map */ function foxtrot_display_map_action($content) { global $post; if ('property' !== get_post_type($post->ID)) { return $content; } $meta = get_post_meta($post->ID); $gmap_static_url = 'http://maps.googleapis.com/maps/api/staticmap?center='; $latitude = $meta['foxtrot_latitude']; $longitude = $meta['foxtrot_longitude']; $gmap_zoom = 13; $content .= '<div class="row">'; $content .= '<div class="col-xs-11"><a href="http://maps.google.com/maps?q=' . $latitude[0] . ',+' . $longitude[0] . '&t=h&z=15&" target="_blank"><img src="' . $gmap_static_url . $latitude[0] . ',' . $longitude[0] . '&zoom=' . $gmap_zoom . '&size=306x206&markers=color:green%7Clabel:A%7C' . $latitude[0] . ',' . $longitude[0] . '&sensor=false" class="img-responsive img-thumbnail" /></a></div>'; $content .= '</div>'; $content .= '<a href="http://maps.google.com/maps?q=' . $latitude[0] . ',+' . $longitude[0] . '&t=h&z=15&" target="_blank"><i class="fa fa-map-marker"></i> View Larger Map</a>'; return $content; } /* * * Display Content Blocks - * Usage <?php foxtrot_content_block(2); ?> ** 2 Being the Page ID * */ function foxtrot_properties_content_block($pageid, $echo = true) { //remove_filter ('the_content', 'wpautop'); $post_id = get_post($pageid); $content = $post_id->post_content; //$content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); if ($echo) { echo $content; } else { return $content; } } function foxtrot_display_attachments($attachments, $title = 'Suite 1 plan') { if (is_array($attachments)) { // $pdf_html = '<div><h4>'.$title.'</h4><ul class="foxtrot_pdf_attachments">%1$s'; $pdf_html = '%1$s'; $attach_inner_html = ''; foreach ($attachments as $attachment) { //$format = '<a href="%2$s" target="_blank" class="foxtrot_links"><i class="fa fa-download"></i>%1$s</a>'; $format = '<a href="%2$s" target="_blank" class="foxtrot_links"><i class="fa fa-download"></i></a>'; $attach_inner_html .= sprintf($format, $attachment->post_title, $attachment->guid); } // $attach_inner_html .= '</ul><p><strong>Note: </strong>View/Delete all attachments/images in the <a href="'.home_url().'/wp-admin/upload.php">Media</a> tab. (you need to publish/update changes here first).</p></div>'; return sprintf($pdf_html, $attach_inner_html); } else { return '<span class="inactive"><i class="fa fa-download"></i> </span>'; } } function foxtrot_display_floorplan($attachments, $floorplan_url) { if (is_array($attachments) && !empty($floorplan_url)) { foreach ($attachments as $attachment) { $return = "<a href=\"{$attachment->guid}\" target=\"_blank\"> <img src=\"$floorplan_url\" alt=\"floorplan\" class=\"floorplan\" width=\"120\"/> </a>"; return $return; } } else { return ''; } } function render_suite_block($x, $suite_x, $suite_x_size, $suite_x_notes, $suite_x_min_divisible, $suite_x_max_continguous, $suite_x_lease_rate, $suite_x_lease_type) { global $post; $content = ''; // Setup vars $suite_query = array( array( 'taxonomy' => 'attachment_type', 'field' => 'slug', 'terms' => 'suite' ), array( 'taxonomy' => 'post_tag', 'field' => 'name', 'terms' => array($x) ) ); $pdfs = foxtrot_get_pdfs($post, $suite_query); $photo_query = array( array( 'taxonomy' => 'attachment_type', 'field' => 'slug', 'terms' => 'photo' ), array( 'taxonomy' => 'post_tag', 'field' => 'name', 'terms' => array($x) ) ); $photos = foxtrot_get_images($post, $photo_query); $floorplan_query = array( array( 'taxonomy' => 'attachment_type', 'field' => 'slug', 'terms' => 'floorplan' ), array( 'taxonomy' => 'post_tag', 'field' => 'name', 'terms' => array($x) ) ); $floorplan = foxtrot_get_images($post, $floorplan_query, 'tags__and'); if (!empty($floorplan[0])) { $floorplan_url = $floorplan[0]->guid; } else { $floorplan_url = ''; } $suite_x_images = ''; if (is_array($photos)) { foreach ($photos as $photo) { $image_src = wp_get_attachment_image_src($photo->ID, 'full'); $suite_x_images .= '<a href="' . $image_src[0] . '" class="foxtrot_links">'; $suite_x_images .= '<i class="fa fa-camera"></i>'; $suite_x_images .= '</a>'; } } else { $suite_x_images = '<span class="inactive"><i class="fa fa-camera"></i></span>'; } //Display if (('' != $suite_x[0]) || ('' != $suite_x_size[0])) { $content .= '<div class="suite"><h4>' . $suite_x[0] . $suite_x_images . $this->foxtrot_display_attachments($pdfs, 'Suite 1') . '</h4>'; $content .= $this->foxtrot_display_floorplan($pdfs, $floorplan_url); $content .= "<table> <tr> <td>Space Available:</td> <td>".number_format((float)$suite_x_size[0])." ft.</td> </tr> <tr> <td>Min. Divisible:</td> <td>".number_format((float)$suite_x_min_divisible[0])." sq. ft.</td> </tr> <tr> <td>Max. Continguous:</td> <td>".number_format((float)$suite_x_max_continguous[0])." sq. ft.</td> </tr> <tr> <td>Lease Rate:</td> <td>\$$suite_x_lease_rate[0]/sf/yr.</td> </tr> <tr> <td>Lease Type:</td> <td>$suite_x_lease_type[0]</td> </tr> </table>"; $content .= " <aside> <h5>Notes:</h5> <p>{$suite_x_notes[0]}</p> </aside> <div class=\"cleaner\"></div> </div>"; } return $content; } /** * Return the plugin slug. * * @since 1.0.0 * * @return Plugin slug variable. */ public function get_plugin_slug() { return $this->plugin_slug; } /** * Return an instance of this class. * * @since 1.0.0 * * @return object A single instance of this class. */ public static function get_instance() { // If the single instance hasn't been set, set it now. if (null == self::$instance) { self::$instance = new self; } return self::$instance; } /** * Fired when the plugin is activated. * * @since 1.0.0 * * @param boolean $network_wide True if WPMU superadmin uses * "Network Activate" action, false if * WPMU is disabled or plugin is * activated on an individual blog. */ public static function activate($network_wide) { if (function_exists('is_multisite') && is_multisite()) { if ($network_wide) { // Get all blog ids $blog_ids = self::get_blog_ids(); foreach ($blog_ids as $blog_id) { switch_to_blog($blog_id); self::single_activate(); } restore_current_blog(); } else { self::single_activate(); } } else { self::single_activate(); } } /** * Fired when the plugin is deactivated. * * @since 1.0.0 * * @param boolean $network_wide True if WPMU superadmin uses * "Network Deactivate" action, false if * WPMU is disabled or plugin is * deactivated on an individual blog. */ public static function deactivate($network_wide) { if (function_exists('is_multisite') && is_multisite()) { if ($network_wide) { // Get all blog ids $blog_ids = self::get_blog_ids(); foreach ($blog_ids as $blog_id) { switch_to_blog($blog_id); self::single_deactivate(); } restore_current_blog(); } else { self::single_deactivate(); } } else { self::single_deactivate(); } } /** * Fired when a new site is activated with a WPMU environment. * * @since 1.0.0 * * @param int $blog_id ID of the new blog. */ public function activate_new_site($blog_id) { if (1 !== did_action('wpmu_new_blog')) { return; } switch_to_blog($blog_id); self::single_activate(); restore_current_blog(); } /** * Get all blog ids of blogs in the current network that are: * - not archived * - not spam * - not deleted * * @since 1.0.0 * * @return array|false The blog ids, false if no matches. */ private static function get_blog_ids() { global $wpdb; // get an array of blog ids $sql = "SELECT blog_id FROM $wpdb->blogs WHERE archived = '0' AND spam = '0' AND deleted = '0'"; return $wpdb->get_col($sql); } /** * Fired for each blog when the plugin is activated. * * @since 1.0.0 */ private static function single_activate() { // @TODO: Define activation functionality here } /** * Fired for each blog when the plugin is deactivated. * * @since 1.0.0 */ private static function single_deactivate() { // @TODO: Define deactivation functionality here } /** * Load the plugin text domain for translation. * * @since 1.0.0 */ public function load_plugin_textdomain() { $domain = $this->plugin_slug; $locale = apply_filters('plugin_locale', get_locale(), $domain); load_textdomain($domain, trailingslashit(WP_LANG_DIR) . $domain . '/' . $domain . '-' . $locale . '.mo'); } /** * Register and enqueue public-facing style sheet. * * @since 1.0.0 */ public function enqueue_styles() { if (is_singular('property')) { wp_enqueue_style($this->plugin_slug . '-plugin-styles-fb', plugins_url('assets/css/fancybox/jquery.fancybox.css', __FILE__), array(), self::VERSION); wp_enqueue_style($this->plugin_slug . '-plugin-styles-fb', plugins_url('assets/css/fancybox/jquery.fancybox-thumbs.css', __FILE__), array(), self::VERSION); wp_enqueue_style($this->plugin_slug . '-plugin-styles', plugins_url('assets/css/public.css', __FILE__), array(), self::VERSION); wp_enqueue_style($this->plugin_slug . '-plugin-styles', plugins_url('assets/css/public.css', __FILE__), array(), self::VERSION); } } /** * Register and enqueues public-facing JavaScript files. * * @since 1.0.0 */ public function enqueue_scripts() { if (is_singular('property')) { wp_enqueue_script($this->plugin_slug . '-plugin-script-fb-mouse', plugins_url('assets/js/fancybox/jquery.mousewheel-3.0.6.pack.js', __FILE__), array('jquery'), self::VERSION); wp_enqueue_script($this->plugin_slug . '-plugin-script-fb-mouse', plugins_url('assets/js/fancybox/jquery.fancybox-thumbs.js', __FILE__), array('jquery'), self::VERSION); wp_enqueue_script($this->plugin_slug . '-plugin-script-fb', plugins_url('assets/js/fancybox/jquery.fancybox.pack.js', __FILE__), array('jquery'), self::VERSION); wp_enqueue_script($this->plugin_slug . '-plugin-script-fb-media', plugins_url('assets/js/fancybox/jquery.fancybox-media.js', __FILE__), array('jquery'), self::VERSION); wp_enqueue_script($this->plugin_slug . '-plugin-script', plugins_url('assets/js/public.js', __FILE__), array('jquery'), self::VERSION); wp_enqueue_script($this->plugin_slug . '-plugin-script-tabs', plugins_url('assets/js/responsive-tabs.js', __FILE__), array('jquery'), self::VERSION); } } /** * NOTE: Actions are points in the execution of a page or process * lifecycle that WordPress fires. * * Actions: http://codex.wordpress.org/Plugin_API#Actions * Reference: http://codex.wordpress.org/Plugin_API/Action_Reference * * @since 1.0.0 */ public function action_method_name() { // @TODO: Define your action hook callback here } /** * NOTE: Filters are points of execution in which WordPress modifies data * before saving it or sending it to the browser. * * Filters: http://codex.wordpress.org/Plugin_API#Filters * Reference: http://codex.wordpress.org/Plugin_API/Filter_Reference * * @since 1.0.0 */ public function filter_method_name() { // @TODO: Define your filter hook callback here } /** * @param $query * This adds in the filter to include listings on author profile page * */ function foxtrot_listings_alter_query($query) { global $wp_the_query; if ($wp_the_query === $query && $query->is_author()) { $query->set('post_type', $this->slug); } } }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Using within a custom Plugin’ is closed to new replies.