Skip to content

Instantly share code, notes, and snippets.

@NateWr
Last active February 3, 2016 10:20
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/b28bb63ba8a73bb14eac to your computer and use it in GitHub Desktop.
Save NateWr/b28bb63ba8a73bb14eac to your computer and use it in GitHub Desktop.
Modifies the Business Profile plugin to include info for Home and Construction Businesses.
<?php
/**
* Plugin Name: Home and Construction Extensions for Business Profile
* Plugin URI: http://themeofthecrop.com
* Description: Modifies the Business Profile plugin to include info for Home and Construction Businesses.
* 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
*/
if ( ! defined( 'ABSPATH' ) )
exit;
/**
* Add Schema options for Home and Construction Businesses
*
* This preserves the existing options and just adds the ones for
* Home and Construction. 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.
*/
if ( !function_exists( 'hcbp_extend_schema' ) ) {
function hcbp_extend_schema( $sap ) {
// Loop over the schema options. When we hit the
// HomeAndConstructionBusiness, add in our new options.
$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 == 'HomeAndConstructionBusiness' ) {
$new_schema_options['Electrician'] = '-- Electrician';
$new_schema_options['GeneralContractor'] = '-- General Contractor';
$new_schema_options['HVACBusiness'] = '-- HVAC Business';
$new_schema_options['HousePainter'] = '-- House Painter';
$new_schema_options['Locksmith'] = '-- Locksmith';
$new_schema_options['MovingCompany'] = '-- Moving Company';
$new_schema_options['Plumber'] = '-- Plumber';
$new_schema_options['RoofingContractor'] = '-- Roofing Contractor';
}
}
// 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', 'hcbp_extend_schema', 100 );
} // endif;
/**
* Add settings options for a US formatted Phone Number and a Fax number
*/
if ( !function_exists( 'hcbp_add_settings' ) ) {
function hcbp_add_settings( $sap ) {
$sap->add_setting(
'bpfwp-settings',
'bpfwp-contact',
'text',
array(
'id' => 'phone-formatted',
'title' => __( 'Formatted Phone Number', BPFWP_TEXTDOMAIN ),
'description' => __( 'Enter phone number in the format of +18005551212 to be used for mobile phone call links.', BPFWP_TEXTDOMAIN ),
)
);
$sap->add_setting(
'bpfwp-settings',
'bpfwp-contact',
'text',
array(
'id' => 'fax',
'title' => __( 'Fax', BPFWP_TEXTDOMAIN ),
)
);
return $sap;
}
add_filter( 'bpfwp_settings_page', 'hcbp_add_settings', 100 );
} // endif;
/**
* Add the fax number to the defaults
*/
if ( !function_exists( 'hcbp_contact_card_defaults' ) ) {
function hcbp_contact_card_defaults( $defaults ) {
$defaults['show_fax'] = true;
return $defaults;
}
add_filter( 'bpwfp_contact_card_defaults', 'hcbp_contact_card_defaults' );
} // endif;
/**
* Modify the callback function for phone and add one for fax
*/
if ( !function_exists( 'hcbp_component_callbacks' ) ) {
function hcbp_component_callbacks( $callbacks ) {
if ( !empty( $callbacks['phone'] ) ) {
$callbacks['phone'] = 'hcbp_print_phone';
}
global $bpfwp_controller;
if ( $bpfwp_controller->settings->get_setting( 'fax' ) ) {
$callbacks['fax'] = 'hcbp_print_fax';
}
return $callbacks;
}
add_filter( 'bpwfwp_component_callbacks', 'hcbp_component_callbacks' );
} // endif;
/**
* Print the phone number with the formatted phone if available
*/
if ( !function_exists( 'hcbp_print_phone' ) ) {
function hcbp_print_phone() {
global $bpfwp_controller;
$phone = $bpfwp_controller->settings->get_setting( 'phone' );
$formatted = $bpfwp_controller->settings->get_setting( 'phone-formatted' );
if ( $bpfwp_controller->display_settings['show_phone'] ) :
?>
<div class="bp-phone" itemprop="telephone">
<?php if ( !empty( $formatted ) ) : ?>
<a href="tel:<?php echo esc_attr( $formatted ); ?>"><?php echo $phone; ?></a>
<?php else :
echo $phone;
endif; ?>
</div>
<?php else : ?>
<meta itemprop="telephone" content="<?php echo esc_attr( $bpfwp_controller->settings->get_setting( 'phone' ) ); ?>">
<?php endif;
}
} // endif;
/**
* Print the fax number
* @since 0.0.1
*/
if ( !function_exists( 'hcbp_print_fax' ) ) {
function hcbp_print_fax() {
global $bpfwp_controller;
if ( $bpfwp_controller->display_settings['show_fax'] ) : ?>
<div class="bp-fax" itemprop="faxNumber">
<?php echo $bpfwp_controller->settings->get_setting( 'fax' ); ?>
</div>
<?php else : ?>
<meta itemprop="faxNumber" content="<?php echo esc_attr( $bpfwp_controller->settings->get_setting( 'fax' ) ); ?>">
<?php endif;
}
} // endif;
/**
* Add the fax icon with a bit of CSS in the head
*/
if ( !function_exists( 'hcbp_enqueue_assets' ) ){
function hcbp_enqueue_assets() {
wp_add_inline_style( 'bpfwp-default', '.bp-fax:before {
display: inline-block;
width: 1.5em;
height: 1em;
font-size: 1.5em;
line-height: 1;
font-family: dashicons;
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-fax:before {
content: "\f491";
}'
);
}
add_action( 'wp_enqueue_scripts', 'hcbp_enqueue_assets' );
} // endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment