| 1 |
<?php |
| 2 |
|
| 3 |
if( ! class_exists( 'wp_mapit_the_content' ) ) { |
| 4 |
/** |
| 5 |
* Class to filter the_content to show map |
| 6 |
*/ |
| 7 |
class wp_mapit_the_content |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Add hooks and filters to display map in the content |
| 11 |
* |
| 12 |
* @since 1.0 |
| 13 |
* @access public |
| 14 |
*/ |
| 15 |
public static function init() { |
| 16 |
add_filter( 'the_content', __CLASS__ . '::the_content' ); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Function to manage the_content filter to display map |
| 21 |
* |
| 22 |
* @since 1.0 |
| 23 |
* @access public |
| 24 |
* @param $content String content of the page |
| 25 |
* @return String Returns content including the map as string |
| 26 |
*/ |
| 27 |
public static function the_content( $content ){ |
| 28 |
|
| 29 |
/* Check if map is added */ |
| 30 |
if( wp_mapit_map::has_map() ) { |
| 31 |
|
| 32 |
$mapPosition = wp_mapit_map::get_map_position(); |
| 33 |
|
| 34 |
/* If map is to be displayed before or after content, generate map */ |
| 35 |
if( in_array( $mapPosition, array( 'before', 'after' ) ) ) { |
| 36 |
$mapContent = wp_mapit_map::generate_map(); |
| 37 |
$content = ( ( $mapPosition == 'before' ) ? ( $mapContent . $content ) : ( $content . $mapContent ) ); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
return $content; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Calling init function to activate hooks and filters. |
| 47 |
*/ |
| 48 |
wp_mapit_the_content::init(); |
| 49 |
} |