PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 7.2.1
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v7.2.1
7.2.2 7.2.1 7.2 7.1.2 7.1.1 7.1 7.0.4 7.0.6 7.0.7 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 6.3.1 trunk 5.7.3 5.7.5 5.8.1 5.8.2 5.8.3 5.8.4 5.8.6 6.0.4 All 37 releases
mlsimport / public / class-mlsimport-public.php

class-mlsimport-public.php in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 7.2.1, at public/class-mlsimport-public.php

129 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Bail if the file is requested directly (outside of WordPress).
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 /**
8 * Public-facing side of the plugin.
9 *
10 * Defines the hooks that run on the front end: enqueuing the public CSS/JS and a
11 * filter that rewrites MLS-imported attachment URLs. The heavy front-end surfaces
12 * (standalone listings, agent pages, page blocks) live elsewhere; this class is the
13 * thin public bootstrap wired up by Mlsimport_Loader.
14 *
15 * @link http://mlsimport.com/
16 * @since 1.0.0
17 *
18 * @package Mlsimport
19 * @subpackage Mlsimport/public
20 */
21
22 /**
23 * The public-facing functionality of the plugin.
24 *
25 * @package Mlsimport
26 * @subpackage Mlsimport/public
27 * @author MlsImport <office@mlsimport.com>
28 */
29 class Mlsimport_Public {
30
31 /**
32 * The ID of this plugin.
33 *
34 * @since 1.0.0
35 * @access private
36 * @var string $plugin_name The ID of this plugin.
37 */
38 private $plugin_name;
39
40 /**
41 * The version of this plugin.
42 *
43 * @since 1.0.0
44 * @access private
45 * @var string $version The current version of this plugin.
46 */
47 private $version;
48
49 /**
50 * Initialize the class and set its properties.
51 *
52 * @since 1.0.0
53 * @param string $plugin_name The name of the plugin.
54 * @param string $version The version of this plugin.
55 */
56 public function __construct( $plugin_name, $version ) {
57
58 // Stash the plugin slug (used as the enqueue handle base).
59 $this->plugin_name = $plugin_name;
60 // Stash the current version (used for cache-busting the public script).
61 $this->version = $version;
62 }
63
64 /**
65 * Register the stylesheets for the public-facing side of the site.
66 *
67 * Enqueues the base public stylesheet and, when applicable, a theme-specific
68 * override sheet named after the active theme environment (e.g. residence).
69 *
70 * @since 1.0.0
71 * @return void
72 */
73 public function enqueue_styles() {
74 // Pull the active theme environment slug from the plugin core singleton.
75 global $mlsimport;
76 $theme_enviroment = $mlsimport->get_plugin_data( 'theme_enviroment' );
77 // Always enqueue the base public stylesheet.
78 wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/mlsimport-public.css', array(), MLSIMPORT_VERSION, 'all' );
79
80 // When an environment override is flagged, enqueue the theme-specific sheet
81 // (mlsimport-public-<theme>.css). Note: $options is not defined in this scope.
82 if ( isset( $options['enviroment'] ) ) {
83 wp_enqueue_style( $this->plugin_name . strtolower( $theme_enviroment ), plugin_dir_url( __FILE__ ) . 'css/mlsimport-public-' . strtolower( $theme_enviroment ) . '.css', array(), MLSIMPORT_VERSION, 'all' );
84 }
85 }
86
87 /**
88 * Register the JavaScript for the public-facing side of the site.
89 *
90 * @since 1.0.0
91 * @return void
92 */
93 public function enqueue_scripts() {
94 // Enqueue the public script (depends on jQuery), versioned for cache-busting.
95 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/mlsimport-public.js', array( 'jquery' ), $this->version, false );
96 }
97
98
99 /**
100 * ReWrite Image url
101 *
102 * Filter callback (wp_get_attachment_url): for attachments imported by MLSImport
103 * it returns the path portion after '/wp-content/uploads/' instead of the full URL;
104 * all other attachments pass through unchanged.
105 *
106 * @since 1.0.0
107 * @param string $url The attachment URL WordPress resolved.
108 * @param int $post_id The attachment post ID.
109 * @return string The rewritten path for MLS imports, else the original URL.
110 */
111 public function mlsimport_wp_get_attachment_url( $url, $post_id ) {
112
113
114 // Only rewrite attachments tagged as MLS imports (is_mlsimport meta === 1).
115 if( intval(get_post_meta($post_id,'is_mlsimport',true)) === 1){
116
117 // Split on the uploads base and return the trailing path segment.
118 $explode = explode('/wp-content/uploads/', $url);
119 return $explode[1];
120
121 }
122
123 // Non-MLS attachments keep their original URL untouched.
124 return $url;
125 }
126
127
128 }
129