Skip to content

Instantly share code, notes, and snippets.

@NateWr
Created November 23, 2016 10:09
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 NateWr/390833a12905401eb1cf3d339cf7ac93 to your computer and use it in GitHub Desktop.
Save NateWr/390833a12905401eb1cf3d339cf7ac93 to your computer and use it in GitHub Desktop.
Add field for any arbitrary URL for the Menu schema for their Business profile. This only works with the main location.
<?php
/**
* Plugin Name: Menu Schema URL for Business Profile
* Plugin URI: http://themeofthecrop.com
* Description: Add field for any arbitrary URL for the Menu schema for their Business profile. This only works with the main location.
* Version: 0.0.1
* Author: Theme of the Crop
* Author URI: http://themeofthecrop.com
* License: GNU General Public License v2.0 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along with this program; if not, write
* to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
defined( 'ABSPATH' ) || exit;
/**
* Add an option to enter a menu URL in Business Profile settings
*
* @param sapLibrary $sap Simple Admin Pages library instance
* @since 1.5
*/
function msrfbp_add_menu_setting( $sap ) {
$sap->add_setting(
'bpfwp-settings',
'bpfwp-contact',
'text',
array(
'id' => 'menu-url',
'title' => __( 'Menu URL', 'business-profile' ),
'description' => __( 'Enter a direct URL (including http://) to the main restaurant menu on your website. Entering a URL will override the Menu option selected above.', 'business-profile' ),
'placeholder' => 'http://',
)
);
return $sap;
}
add_filter( 'bpfwp_settings_page', 'msrfbp_add_menu_setting' );
/**
* Register the menu component in the Business Profile contact card
*
* @param array $components List component callback functions to print details
* @since 1.5
*/
function msrfbp_add_menu_callback( $components ) {
$components['menu'] = 'msrfbp_print_menu_schema';
return $components;
}
add_filter( 'bpwfwp_component_callbacks', 'msrfbp_add_menu_callback' );
/**
* Print the menu schema details in the Business Profile contact card
*
* @param int $location A post ID if this is for a specific location
* @since 1.5
*/
function msrfbp_print_menu_schema( $location = false ) {
$menu_url = bpfwp_setting( 'menu-url', $location );
if ( empty( $menu_url ) ) {
return;
}
?>
<meta itemprop="menu" itemtype="http://schema.org/menu" content="<?php echo esc_url( $menu_url ); ?>">
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment