Skip to content

Instantly share code, notes, and snippets.

@Coop920
Created April 1, 2019 16:00
Show Gist options
  • Save Coop920/ab791effb12d112d3ce85e0d2c7a3b51 to your computer and use it in GitHub Desktop.
Save Coop920/ab791effb12d112d3ce85e0d2c7a3b51 to your computer and use it in GitHub Desktop.
<?
if (!class_exists("BP_Shortcodes"))
{
class BP_Shortcodes
{
public $call;
public function __construct()
{
$call = self::createCallBack($this);
$this->setupShortCodes();
add_action('wp_dashboard_setup', $call('addDashboardWidget'),1000);
}
protected function setupShortCodes()
{
/* we want to create a handle to use the curried function
to use in our method. */
$call = self::createCallBack($this);
add_shortcode('heshe', $call('heshe'));
add_shortcode('himher', $call('himher'));
add_shortcode('hisher', $call('hisher'));
add_shortcode('hishers', $call('hishers'));
add_shortcode('doctor_name', $call('doctor_name'));
add_shortcode('dr_last', $call('dr_last'));
add_shortcode('dr_type', $call('dr_type'));
add_shortcode('practice_name', $call('practice_name'));
add_shortcode('business_name', $call('practice_name'));
add_shortcode('tagline', $call('tagline'));
add_shortcode('phone', $call('phone'));
add_shortcode('phone2', $call('phone2'));
add_shortcode('phone3', $call('phone3'));
add_shortcode('phoneGuru', $call('phoneGuru'));
add_shortcode('facebook_url', $call('facebook'));
add_shortcode('twitter_url', $call('twitter'));
add_shortcode('googleplus_url', $call('googleplus'));
add_shortcode('youtube_url', $call('youtube'));
add_shortcode('yelp_url', $call('yelp'));
add_shortcode('pinterest_url', $call('pinterest'));
add_shortcode('instagram_url', $call('instagram'));
add_shortcode('linkedin_url', $call('linkedin'));
add_shortcode('address', $call('address'));
add_shortcode('city', $call('city'));
add_shortcode('state', $call('state'));
add_shortcode('st', $call('st'));
add_shortcode('zip', $call('zip'));
add_shortcode('latitude', $call('latitude'));
add_shortcode('longitude', $call('longitude'));
add_shortcode('address1', $call('address1'));
add_shortcode('address2', $call('address2'));
add_shortcode('monday_hours', $call('monday'));
add_shortcode('tuesday_hours', $call('tuesday'));
add_shortcode('wednesday_hours', $call('wednesday'));
add_shortcode('thursday_hours', $call('thursday'));
add_shortcode('friday_hours', $call('friday'));
add_shortcode('saturday_hours', $call('saturday'));
add_shortcode('sunday_hours', $call('sunday'));
add_shortcode('hours', $call('hours'));
add_shortcode('hours_line', $call('hours_line'));
add_shortcode('dr_type_schema', $call('drSchema'));
add_shortcode('schema_description', $call('schemaDescription'));
}
function statesList() {
$states = array('AL'=>"Alabama",
'AK'=>"Alaska",
'AB'=>"Alberta",
'AZ'=>"Arizona",
'AR'=>"Arkansas",
'CA'=>"California",
'CO'=>"Colorado",
'CT'=>"Connecticut",
'DE'=>"Delaware",
'DC'=>"District Of Columbia",
'FL'=>"Florida",
'GA'=>"Georgia",
'HI'=>"Hawaii",
'ID'=>"Idaho",
'IL'=>"Illinois",
'IN'=>"Indiana",
'IA'=>"Iowa",
'KS'=>"Kansas",
'KY'=>"Kentucky",
'LA'=>"Louisiana",
'ME'=>"Maine",
'MD'=>"Maryland",
'MA'=>"Massachusetts",
'MI'=>"Michigan",
'MN'=>"Minnesota",
'MS'=>"Mississippi",
'MO'=>"Missouri",
'MT'=>"Montana",
'NE'=>"Nebraska",
'NV'=>"Nevada",
'NH'=>"New Hampshire",
'NJ'=>"New Jersey",
'NM'=>"New Mexico",
'NY'=>"New York",
'NC'=>"North Carolina",
'ND'=>"North Dakota",
'OH'=>"Ohio",
'OK'=>"Oklahoma",
'OR'=>"Oregon",
'PA'=>"Pennsylvania",
'RI'=>"Rhode Island",
'SC'=>"South Carolina",
'SD'=>"South Dakota",
'TN'=>"Tennessee",
'TX'=>"Texas",
'UT'=>"Utah",
'VT'=>"Vermont",
'VA'=>"Virginia",
'WA'=>"Washington",
'WV'=>"West Virginia",
'WI'=>"Wisconsin",
'WY'=>"Wyoming");
return $states;
}
function schemaType()
{
$drSchema = array(
'Dentist' => 'Dentist',
'Physician' => 'Physician',
'Hospital' => 'Hospital',
'FinancialProduct' => 'Financial Product',
'GovernmentService' => 'Government Service',
'GovernmentOrganization' => 'Government Organization',
'AutoDealer' => 'Auto Dealer',
'AutoRepair' => 'Auto Repair',
'FinancialService' => 'Financial Service',
'AccountingService' => 'Accounting Service',
'FoodEstablishment' => 'Food Establishment',
'HealthAndBeautyBusiness' => 'Health And Beauty Business',
'DaySpa' => 'Day Spa',
'HomeAndConstructionBusiness' => 'Home And Construction Business',
'Electrician' => 'Electrician',
'GeneralContractor' => 'General Contractor',
'LegalService' => 'Legal Service',
'Attorney' => 'Attorney',
'Dermatology' => 'Dermatology',
'MedicalClinic' => 'Medical Clinic',
'PrimaryCare' => 'Primary Care',
'LocalBusiness' => 'Local Business'
);
return $drSchema;
}
function heshe(){
return get_option('bp_heshe');
}
function himher(){
$heshe = get_option('bp_heshe');
if ($heshe=='he') {
$return = 'him';
} else if ($heshe=='she') {
$return = 'her';
} else if ($heshe=='they') {
$return = 'them';
}
return $return;
}
function hisher(){
$heshe = get_option('bp_heshe');
if ($heshe=='he') {
$return = 'his';
} else if ($heshe=='she') {
$return = 'her';
} else if ($heshe=='they') {
$return = 'their';
}
return $return;
}
function hishers(){
$heshe = get_option('bp_heshe');
if ($heshe=='he') {
$return = 'his';
} else if ($heshe=='she') {
$return = 'hers';
} else if ($heshe=='they') {
$return = 'theirs';
}
return $return;
}
function dev_name(){
return get_option('bp_dev_name');
}
function design_name(){
return get_option('bp_design_name');
}
function bp_build_date() {
return get_option('bp_build_date');
}
function doctor_name(){
return get_option('bp_doctor_name');
}
function dr_last(){
return get_option('bp_dr_last');
}
function dr_type(){
return (get_option('bp_dr_type')?get_option('bp_dr_type'):'dentist');
}
function practice_name(){
return get_option('blogname');
}
function tagline(){
return get_option('blogdescription');
}
function phone(){
return get_option('bp_phone');
}
function phone2(){
return get_option('bp_phone2');
}
function phone3(){
return get_option('bp_phone3');
}
function phoneGuru(){
return get_option('bp_phoneGuru');
}
function facebook(){
return get_option('bp_facebook');
}
function twitter(){
return get_option('bp_twitter');
}
function googleplus(){
return get_option('bp_googleplus');
}
function youtube(){
return get_option('bp_youtube');
}
function yelp(){
return get_option('bp_yelp');
}
function pinterest(){
return get_option('bp_pinterest');
}
function instagram(){
return get_option('bp_instagram');
}
function linkedin(){
return get_option('bp_linkedin');
}
function monday(){
return get_option('bp_monday_hours');
}
function tuesday(){
return get_option('bp_tuesday_hours');
}
function wednesday(){
return get_option('bp_wednesday_hours');
}
function thursday(){
return get_option('bp_thursday_hours');
}
function friday(){
return get_option('bp_friday_hours');
}
function saturday(){
return get_option('bp_saturday_hours');
}
function sunday(){
return get_option('bp_sunday_hours');
}
function address1(){
return get_option('bp_address1');
}
function address2(){
return get_option('bp_address2');
}
function city(){
return get_option('bp_city');
}
function state(){
$states = $this->statesList();
return $states[get_option('bp_state')];
}
function drSchema(){
$drSchema = $this->schemaType();
return $drSchema[get_option('bp_dr_schema')];
}
function schemaDescription(){
return get_option('bp_schema_description');
}
function st(){
return get_option('bp_state');
}
function zip(){
return get_option('bp_zip');
}
function latitude(){
return get_option('bp_latitude');
}
function longitude(){
return get_option('bp_longitude');
}
function address($atts){
$address1 = get_option('bp_address1');
$address2 = get_option('bp_address2');
$city = get_option('bp_city');
$state = get_option('bp_state');
$zip = get_option('bp_zip');
$address = '';
if (isset($atts['multiline']) && $atts['multiline']==1) {
if ($address1) $address.=$address1."<br>\n";
if ($address2) $address.=$address2."<br>\n";
} else {
if ($address1) $address.=$address1.", ";
if ($address2) $address.=$address2.", ";
}
$address.="$city, $state $zip";
return $address;
}
function hours($atts){
$monday = get_option('bp_monday_hours');
$tuesday = get_option('bp_tuesday_hours');
$wednesday = get_option('bp_wednesday_hours');
$thursday = get_option('bp_thursday_hours');
$friday = get_option('bp_friday_hours');
$saturday = get_option('bp_saturday_hours');
$sunday = get_option('bp_sunday_hours');
$hours = '';
$hours.="$monday<br>$tuesday<br>$wednesday<br>$thursday<br>$friday<br>$saturday<br>$sunday";
return $hours;
}
function hours_line($atts){
$monday = get_option('bp_monday_hours');
$tuesday = get_option('bp_tuesday_hours');
$wednesday = get_option('bp_wednesday_hours');
$thursday = get_option('bp_thursday_hours');
$friday = get_option('bp_friday_hours');
$saturday = get_option('bp_saturday_hours');
$sunday = get_option('bp_sunday_hours');
$hours = '';
$hours.="$monday | $tuesday | $wednesday | $thursday | $friday | $saturday | $sunday";
return $hours;
}
static function addDashboardWidget() {
global $current_user;
wp_get_current_user();
if (current_user_can('manage_options')) {
$call = self::createCallBack($this);
wp_add_dashboard_widget('bp_shortcodes', 'Shortcodes Configuration', $call('dashboardWidget'));
}
}
protected static function createCallBack(&$self)
{
return function($param) use(&$self)
{
return [&$self, $param];
};
}
protected static function deactivatePlugin($path, $bpi_ga_uid)
{
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if (is_plugin_active($path))
{
deactivate_plugins($path);
}
update_option('bpi_ga_uid', $bpi_ga_uid);
}
public function dashboardWidget(){
if ($_POST['bp_shortcodes_update']) {
foreach ($_POST as $k => $v) {
$v = stripslashes($v);
if ($k == 'blogname') {
update_option($k,$v);
} else if ($k == 'blogdescription') {
update_option($k,$v);
} else if (preg_match('/^bp_/',$k)) {
update_option($k,$v);
}
}
}
?>
<form id="form1" name="form1" method="post">
<table border="1">
<?
if (get_option('is_dental_site')) {
?>
<tr><td></td><td class="short-titles" align="center">DOCTOR INFO</td><td></td></tr>
<tr>
<td align="right">Dr. Full Name:</td>
<td><input type="text" name="bp_doctor_name" id="bp_doctor_name" autocomplete="nope" value="<?=get_option('bp_doctor_name') ?>"></td>
<td>[doctor_name]</td>
</tr>
<tr>
<td align="right">Dr. Last Name:</td>
<td><input type="text" name="bp_dr_last" id="bp_dr_last" autocomplete="nope" value="<?=get_option('bp_dr_last') ?>"></td>
<td>[dr_last]</td>
</tr>
<tr>
<td align="right">Doctor Type:</td>
<td><input type="text" name="bp_dr_type" id="bp_dr_type" autocomplete="nope" value="<?=(get_option('bp_dr_type')?get_option('bp_dr_type'):'dentist') ?>"></td>
<td>[dr_type]</td>
</tr>
<tr>
<td align="right">Doctor Pronoun:</td>
<td><label>
<input name="bp_heshe" type="radio" id="heshe_0" value="he" <? if (get_option('bp_heshe')!='she') echo 'checked="checked"'; ?>>he</label><label>
<input type="radio" name="bp_heshe" value="she" id="heshe_1" <? if (get_option('bp_heshe')=='she') echo 'checked="checked"'; ?>>she</label>
<input type="radio" name="bp_heshe" value="they" id="heshe_2" <? if (get_option('bp_heshe')=='they') echo 'checked="checked"'; ?>>they</label>
</td>
<td>[heshe] = he/she/they<br>
[himher] = him/her/them<br>
[hisher] = his/her/their<br>
[hishers] = his/hers/theirs</td>
</tr>
<?
} else {
?>
<tr>
<td align="right">Business Name:</td>
<td>
<input type="text" name="blogname" id="blogname" autocomplete="nope" value="<?=get_option('blogname') ?>">
</td>
<td>[business_name]</td>
</tr>
<?
}
?>
<tr><td></td><td class="short-titles" align="center">SCHEMA INFO</td><td></td></tr>
<tr>
<td align="right">Dr. Type (schema)</td>
<td>
<?
global $bpicustomadmin;
$drSchema = $this->schemaType();
echo '<select name="bp_dr_schema" id="bp_dr_schema">';
echo '<option value=""></option>';
foreach($drSchema as $key=>$value) {
$selected = '';
if ($key == get_option('bp_dr_schema')) $selected = ' selected="selected" ';
echo '<option value="'.$key.'"' . $selected .' >'.$value.'</option>';
}
echo '</select>';
?>
</td>
<td>[dr_type_schema]
<tr>
<td align="right">Schema Description:</td>
<td><input type="text" name="bp_schema_description" id="bp_schema_description" autocomplete="nope" value="<?=get_option('bp_schema_description') ?>"></td>
<td>[schema_description]</td>
</tr>
</tr>
<tr>
<td align="right">Latitude:</td>
<td><input type="text" name="bp_latitude" id="bp_latitude" autocomplete="nope" value="<?=get_option('bp_latitude') ?>"></td>
<td>[latitude]</td>
</tr>
<tr>
<tr>
<td align="right">Longitude:</td>
<td><input type="text" name="bp_longitude" id="bp_longitude" autocomplete="nope" value="<?=get_option('bp_longitude') ?>"></td>
<td>[longitude]</td>
</tr>
<tr>
<tr><td></td><td class="short-titles" align="center">LOCATION INFO</td><td></td></tr>
<tr>
<td align="right">Practice Name:</td>
<td>
<input type="text" name="blogname" id="blogname" autocomplete="nope" value="<?=get_option('blogname') ?>">
</td>
<td>[practice_name]</td>
</tr>
<tr>
<td align="right">Tag Line:</td>
<td><input type="text" name="blogdescription" id="blogdescription" autocomplete="nope" value="<?=get_option('blogdescription') ?>"></td>
<td>[tag_line]</td>
</tr>
<tr>
<td align="right">Phone:</td>
<td><input type="text" name="bp_phone" id="bp_phone" autocomplete="nope" value="<?=get_option('bp_phone') ?>"></td>
<td>[phone]</td>
</tr>
<tr>
<td align="right">Phone 2:</td>
<td><input type="text" name="bp_phone2" id="bp_phone2" autocomplete="nope" value="<?=get_option('bp_phone2') ?>"></td>
<td>[phone2]</td>
</tr>
<tr>
<td align="right">Phone 3:</td>
<td><input type="text" name="bp_phone3" id="bp_phone3" autocomplete="nope" value="<?=get_option('bp_phone3') ?>"></td>
<td>[phone3]</td>
</tr>
<tr>
<tr>
<td align="right">Phone Guru:</td>
<td><input type="text" name="bp_phoneGuru" id="bp_phoneGuru" autocomplete="nope" value="<?=get_option('bp_phoneGuru') ?>"></td>
<td>[phoneGuru]</td>
</tr>
<td align="right"> Address Line 1:</td>
<td><input type="text" name="bp_address1" id="bp_address1" autocomplete="nope" value="<?=get_option('bp_address1') ?>"></td>
<td>[address1]</td>
</tr>
<tr>
<td align="right">Address Line 2:</td>
<td><input type="text" name="bp_address2" id="bp_address2" autocomplete="nope" value="<?=get_option('bp_address2') ?>"></td>
<td>[address2]</td>
</tr>
<tr>
<td align="right">City:</td>
<td><input type="text" name="bp_city" id="bp_city" autocomplete="nope" value="<?=get_option('bp_city') ?>"></td>
<td>[city]</td>
</tr>
<tr>
<td align="right">State:</td>
<td>
<?
global $bpicustomadmin;
$states = $this->statesList();
echo '<select name="bp_state" id="bp_state">';
echo '<option value=""></option>';
foreach($states as $key=>$value) {
$selected = '';
if ($key == get_option('bp_state')) $selected = ' selected="selected" ';
echo '<option value="'.$key.'"' . $selected .' >'.$value.'</option>';
}
echo '</select>';
?>
</td>
<td>[state]=Name<br>
[st]=Abbr.</td>
</tr>
<tr>
<td align="right">ZIP:</td>
<td><input type="text" name="bp_zip" id="bp_zip" autocomplete="nope" value="<?=get_option('bp_zip') ?>"></td>
<td>[zip]</td>
</tr>
<tr>
<td align="right">Full Address:</td>
<td colspan="2"> [address] or [address multiline=1]</td>
</tr>
<tr><td></td><td class="short-titles" align="center">SOCIAL MEDIA</td><td></td></tr>
<tr>
<td align="right">Facebook Link:</td>
<td><input type="text" name="bp_facebook" id="bp_facebook" autocomplete="nope" value="<?=get_option('bp_facebook') ?>"></td>
<td>[facebook_url]</td>
</tr>
<tr>
<td align="right">Twitter Link:</td>
<td><input type="text" name="bp_twitter" id="bp_twitter" autocomplete="nope" value="<?=get_option('bp_twitter') ?>"></td>
<td>[twitter_url]</td>
</tr>
<tr>
<td align="right">Google Link:</td>
<td><input type="text" name="bp_googleplus" id="bp_googleplus" autocomplete="nope" value="<?=get_option('bp_googleplus') ?>"></td>
<td>[googleplus_url]</td>
</tr>
<tr>
<td align="right">YouTube Link:</td>
<td><input type="text" name="bp_youtube" id="bp_youtube" autocomplete="nope" value="<?=get_option('bp_youtube') ?>"></td>
<td>[youtube_url]</td>
</tr>
<tr>
<td align="right">Yelp Link:</td>
<td><input type="text" name="bp_yelp" id="bp_yelp" autocomplete="nope" value="<?=get_option('bp_yelp') ?>"></td>
<td>[yelp_url]</td>
</tr>
<tr>
<td align="right">Pinterest Link:</td>
<td><input type="text" name="bp_pinterest" id="bp_pinterest" autocomplete="nope" value="<?=get_option('bp_pinterest') ?>"></td>
<td>[pinterest_url]</td>
</tr>
<tr>
<td align="right">Instagram Link:</td>
<td><input type="text" name="bp_instagram" id="bp_instagram" autocomplete="nope" value="<?=get_option('bp_instagram') ?>"></td>
<td>[instagram_url]</td>
</tr>
<tr>
<td align="right">Linkedin Link:</td>
<td><input type="text" name="bp_linkedin" id="bp_linkedin" autocomplete="nope" value="<?=get_option('bp_linkedin') ?>"></td>
<td>[linkedin_url]</td>
</tr>
<tr><td></td><td class="short-titles" align="center">HOURS</td><td>All Hours: [hours]<br>On One Line: [hours_line]</td></tr>
<tr>
<td align="right">Monday:</td>
<td><input type="text" name="bp_monday_hours" id="bp_monday_hours" autocomplete="nope" value="<?=get_option('bp_monday_hours') ?>" placeholder="e.g. Mon: 9AM - 4PM"></td>
<td>[monday_hours]</td>
</tr>
<tr>
<td align="right">Tuesday:</td>
<td><input type="text" name="bp_tuesday_hours" id="bp_tuesday_hours" autocomplete="nope" value="<?=get_option('bp_tuesday_hours') ?>" placeholder="e.g. Tues: 9AM - 4PM"></td>
<td>[tuesday_hours]</td>
</tr>
<tr>
<td align="right">Wednesday:</td>
<td><input type="text" name="bp_wednesday_hours" id="bp_wednesday_hours" autocomplete="nope" value="<?=get_option('bp_wednesday_hours') ?>" placeholder="e.g. Wed: 9AM - 4PM"></td>
<td>[wednesday_hours]</td>
</tr>
<tr>
<td align="right">Thursday:</td>
<td><input type="text" name="bp_thursday_hours" id="bp_thursday_hours" autocomplete="nope" value="<?=get_option('bp_thursday_hours') ?>" placeholder="e.g. Thurs: 9AM - 4PM"></td>
<td>[thursday_hours]</td>
</tr>
<tr>
<td align="right">Friday:</td>
<td><input type="text" name="bp_friday_hours" id="bp_friday_hours" autocomplete="nope" value="<?=get_option('bp_friday_hours') ?>" placeholder="e.g. Fri: 9AM - 4PM"></td>
<td>[friday_hours]</td>
</tr>
<tr>
<td align="right">Saturday:</td>
<td><input type="text" name="bp_saturday_hours" id="bp_saturday_hours" autocomplete="nope" value="<?=get_option('bp_saturday_hours') ?>" placeholder="e.g. Sat: 9AM - 4PM"></td>
<td>[saturday_hours]</td>
</tr>
<tr>
<td align="right">Sunday:</td>
<td><input type="text" name="bp_sunday_hours" id="bp_sunday_hours" autocomplete="nope" value="<?=get_option('bp_sunday_hours') ?>" placeholder="e.g. Sun: 9AM - 4PM"></td>
<td>[sunday_hours]</td>
</tr>
<tr>
<td align="right">&nbsp;</td>
<td><input type="submit" name="bp_shortcodes_update" id="bp_shortcodes_update" class="button-primary" value="Update"></td>
<td>&nbsp;</td>
</tr>
</table>
</form>
<?
}
}
}
global $bp_shortcodes;
$bp_shortcodes = new BP_Shortcodes();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment