Inventory PresserCar dealer WordPress plugin
  • Plugins
  • Documentation
    • Feature List
    • Screenshots
    • Theme Compatibility
    • Importing Vehicles
    • Uploading Photos
    • Vehicle Post Type
    • Widgets
    • Shortcodes
    • Template Tags
    • Hooks
  • Sample Sites
  • About
    • About us
    • News
    • Contact us
Home / Documentation / Classes / Inventory_Presser_Email_A_Friend

Inventory_Presser_Email_A_Friend

Inventory_Presser_Email_A_Friend

Contents

  • Description
  • Source
  • Methods
  • Changelog

Description #Description

Implement a mailto: link in a specific menu item in a specific menu that often exists in Inventory Presser websites.

If a menu item of type "Custom Link" exists with "Email a Friend" set as the "Navigation Label", this class will change the URL to a mailto: link containing vehicle information so the vehicle can be sent to a friend via email.


Top ↑

Source #Source

File: includes/class-menu-item-email-a-friend.php

class Inventory_Presser_Email_A_Friend {


	/**
	 * hooks
	 *
	 * Set up filter and action hooks
	 *
	 * @uses add_filter()
	 *
	 * @return void
	 */
	function hooks() {
		add_filter( 'walker_nav_menu_start_el', array( $this, 'maybe_change_link' ), 11, 4 );
	}

	/**
	 * maybe_change_link
	 *
	 * Fills out a mailto: link with vehicle information
	 *
	 * Target a specific button in a specific menu and modify the URL.
	 *
	 * @uses get_bloginfo(), get_permalink()
	 *
	 * @param  string  $menu_item item HTML
	 * @param  WP_Post $item      post object for the menu item
	 * @param  int     $depth     depth of the item for padding
	 * @param  object  $args      nav menu arguments
	 * @return string
	 */
	function maybe_change_link( $menu_item, $item, $depth, $args ) {
		// looking for $menu_item = <a href="mailto:">Email a Friend</a>

		// is it the vehicle details menu?
		if ( empty( $args ) || empty( $args->menu ) || empty( $args->menu->name ) || __( 'Vehicle Details Buttons', 'inventory-presser' ) != $args->menu->name ) {
			// no
			return $menu_item;
		}

		// is it a custom link labeled email a friend?
		if ( 'Custom Link' != $item->type_label || strtolower( __( 'Email a Friend', 'inventory-presser' ) ) != strtolower( $item->title ) ) {
			// no
			return $menu_item;
		}

		// change the link to contain vehicle information
		global $post;
		$menu_item = str_replace(
			'mailto:',
			$this->url( $post ) . '" target="_blank',
			$menu_item
		);

		return $menu_item;
	}

	/**
	 * url
	 *
	 * Creates a mailto: url to draft an email containing vehicle information.
	 *
	 * @uses get_bloginfo(), get_permalink()
	 *
	 * @param  WP_Post $post a post object of type inventory_vehicle
	 * @return string
	 */
	public function url( $post ) {

		if ( ! isset( $post->post_title ) ) {
			return '';
		}

		$subject = 'Check out this ' . $post->post_title;
		$body    = sprintf(
			'Please look at this %s for sale at %s:

%s',
			$post->post_title,
			html_entity_decode( get_bloginfo(), ENT_QUOTES ), // WordPress encodes quotes in site names
			get_permalink( $post )
		);
		return sprintf(
			'mailto:?subject=%s&body=%s',
			rawurlencode( htmlspecialchars_decode( $subject ) ),
			rawurlencode( htmlspecialchars_decode( $body ) )
		);
	}
}

Expand full source code Collapse full source code View on Github


Top ↑

Methods #Methods

  • hooks — hooks
  • maybe_change_link — maybe_change_link
  • url — url

Top ↑

Changelog #Changelog

Changelog
Version Description
3.8.0 Introduced.
Plugins
  • Inventory Presser
  • VIN Decoder
  • Elementor Add-on
  • Vehicle Filters Widget
  • View all Plugins→
Support
  • Documentation
  • Contact
About Us
  • News
  • Our Team
Search
Recent Posts
  • Blocks Preview Plugin Available
  • Inventory Presser is Free and Open Source
  • Inventory Presser integrates CarStory Market reports

© 2023 a Friday Systems product powered by WordPress