Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active February 18, 2018 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/0491da7dadc9ed8b5ea2720722910fe4 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/0491da7dadc9ed8b5ea2720722910fe4 to your computer and use it in GitHub Desktop.
Modify the market content of Google Map Pro plugin
<?php
/**
* Plugin Name: Google Map Market Content Modify
* Plugin URI: https://premium.wpmudev.org/
* Description: Modify the market content of Google Map Pro plugin
* Author: Ariful Islam @ WPMUDEV
* Author URI: https://premium.wpmudev.org/profile/itsarifulislam
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'GoogleMapMarkerContentModify' ) ) {
class GoogleMapMarkerContentModify {
private static $_instance = null;
public static function get_instance() {
if( is_null( self::$_instance ) ) {
self::$_instance = new GoogleMapMarkerContentModify();
}
return self::$_instance;
}
private function __construct() {
// Init Market Content Modify
add_filter('agm-create-tag', array( $this, 'agm_modify_tag' ), 10, 1);
// Init Market Content Styling
add_action('wp_head', array( $this, 'agm_apply_style' ));
}
public function agm_modify_tag( $map ) {
foreach ( $map['markers'] as $key => $marker ) {
preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $marker['body'], $match);
if ( $match && $match[0] ) {
$post_slug = $match[0][0];
$post_id = url_to_postid( $post_slug );
$thumbnail = get_the_post_thumbnail_url( $post_id, $map['image_size'] );
$marker['body'] = "<a href='{$post_slug}'><img src='{$thumbnail}' /><p>{$marker['title']}</p></a>";
$marker['title'] = "";
$map['markers'][$key] = $marker;
}
}
return $map;
}
public function agm_apply_style() {
if ( is_admin() ) return;
?>
<style>
/*Hide inner logo*/
.agm_mh_info_icon {
display: none;
}
/*Hide inner direction link*/
.agm_mh_marker_item_directions {
display: none;
}
/* Start inner content styling */
.agm_mh_info_body a {
position: relative;
display: block;
}
.agm_mh_info_body a p {
position: absolute;
bottom: 0;
left: 0;
margin-bottom: 0;
color: #fff;
padding: 7px;
font-weight: bold;
z-index: 2;
font-size: 14px;
}
.agm_mh_info_body a:after {
content: "";
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.15);
top: 0;
left: 0;
position: absolute;
}
/* End inner content styling */
</style>
<?php
}
}
function render_google_map_marker_content_modify(){
$GLOBALS['GoogleMapMarkerContentModify'] = GoogleMapMarkerContentModify::get_instance();
}
add_action( 'plugins_loaded', 'render_google_map_marker_content_modify' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment