Extend Business Profile to include a Store Florist Business Schema and Add Mobile number field
<?php
/**
* Plugin Name: Florist and Mobile extensions for Business Profile
* Plugin URI: http://wpbeaches.com
* Description: Modifies the Business Profile plugin to include info for Florist business.
* Version: 0.0.1
* Author: Neil Gee
* Author URI: http://wpbeaches.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.
* Reference - https://gist.github.com/NateWr/b28bb63ba8a73bb14eac
*/
if ( ! defined( 'ABSPATH' ) )
exit;
/**
* Add Schema options for a local business store which is a florist
*
* This preserves the existing options and just adds the one for
* Florist which is a sublevel of Store. But if your working in an environment where
* these are the only options you'll need, you can replace the options
* array instead of adding to it.
*/
//This example is using the themes prefix of fbhb to extend the plugin which uses bpfwp
if ( !function_exists( 'fbhb_extend_schema' ) ) {
function fbhb_extend_schema( $sap ) {
// Loop over the schema options. When we hit the
// Store option which already exists, add in our florist business schema.
$new_schema_options = array();
foreach ( $sap->pages['bpfwp-settings']->sections['bpfwp-seo']->settings['schema_type']->options as $schema => $label ) {
$new_schema_options[$schema] = $label;
if ( $schema == 'Store' ) {
$new_schema_options['Florist'] = '-- Florist';//Adding in new schema
}
}
// Replace the existing schema options with the new ones
$sap->pages['bpfwp-settings']->sections['bpfwp-seo']->settings['schema_type']->options = $new_schema_options;
return $sap;
}
add_filter( 'bpfwp_settings_page', 'fbhb_extend_schema', 100 );
} // endif;
/**
* Add settings options for a mobile number
*/
if ( !function_exists( 'fbhb_add_settings' ) ) {
function fbhb_add_settings( $sap ) {
$sap->add_setting(
'bpfwp-settings',
'bpfwp-contact',
'text',
array(
'id' => 'mobile',
'title' => __( 'Mobile', BPFWP_TEXTDOMAIN ),
)
);
//Repeat the above array for further fields
return $sap;
}
add_filter( 'bpfwp_settings_page', 'fbhb_add_settings', 100 );
} // endif;
/**
* Add the mobile number to the defaults
*/
if ( !function_exists( 'fbhb_contact_card_defaults' ) ) {
function fbhb_contact_card_defaults( $defaults ) {
$defaults['show_mobile'] = true;
return $defaults;
}
add_filter( 'bpwfp_contact_card_defaults', 'fbhb_contact_card_defaults' );
} // endif;
function fbhb_component_callbacks( $callbacks ) {
global $bpfwp_controller;
if ( $bpfwp_controller->settings->get_setting( 'mobile' ) ) {
$callbacks['mobile'] = 'fbhb_print_mobile';
$new_callbacks = array();
foreach( $callbacks as $key => $val ) {
$new_callbacks[$key] = $val;
// When you find the element you want to place it after,
// slot it in. This positions the new field where you want it - here it is being placed after the phone field
if ( $key == 'phone' ) {
$new_callbacks['mobile'] = 'fbhb_print_mobile';
}
$callbacks = $new_callbacks;
}
}
return $callbacks;
}
add_filter( 'bpwfwp_component_callbacks', 'fbhb_component_callbacks' );
/**
* Print the mobile number
* @since 0.0.1
*/
if ( !function_exists( 'fbhb_print_mobile' ) ) {
function fbhb_print_mobile() {
//This is the mark up - is the same format as the original but has the number in a clickable link.
global $bpfwp_controller;
if ( $bpfwp_controller->display_settings['show_mobile'] ) : ?>
<div class="bp-mobile" itemprop="telephone">
<a href="tel:<?php echo (str_replace(' ','',$bpfwp_controller->settings->get_setting('mobile') )); ?>"><?php echo $bpfwp_controller->settings->get_setting( 'mobile' ); ?></a>
</div>
<?php else : ?>
<meta itemprop="telephone" content="<?php echo esc_attr( $bpfwp_controller->settings->get_setting( 'mobile' ) ); ?>">
<?php endif;
}
} // endif;
/**
* Add the mobile icon with a bit of CSS and add via wp_add_inline_style to append to core Business Profile CSS - bpfwp-default
*/
function fbhb_added_styles() {
wp_enqueue_style(
'bpfwp-default',
plugins_url() . '/business-profile/assets/css/contact-card.css'
);
$custom_css = '
.bp-mobile:before {
display: inline-block;
width: 1.5em;
height: 1em;
font-size: 20px;
line-height: 1;
font-family: fontawesome;
text-decoration: inherit;
font-weight: 400;
font-style: normal;
vertical-align: top;
text-align: center;
-webkit-transition: color .1s ease-in 0;
transition: color .1s ease-in 0;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.bp-mobile:before {
content: "\f10b";
}';
wp_add_inline_style( 'bpfwp-default', $custom_css );
}
add_action( 'wp_enqueue_scripts', 'fbhb_added_styles' );