Plugin for QuickSites
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 16 Oct 2014 13:14:18 +0000 (09:14 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 16 Oct 2014 13:14:18 +0000 (09:14 -0400)
Holds states array
Holds the data from the quicksite
address phone numbers

GlmQuickSite.php [new file with mode: 0644]

diff --git a/GlmQuickSite.php b/GlmQuickSite.php
new file mode 100644 (file)
index 0000000..3c4d0e6
--- /dev/null
@@ -0,0 +1,292 @@
+<?php
+/**
+ * Plugin Name: QuickSite Options
+ * Description: Option Setting for the name address and phone numbers for the * quicksite
+ * Version: 1.0
+ * Author: Steve Sutton
+ * Author URI: http://www.gaslightmedia.com
+ * License: All right reserved
+ */
+add_action( 'admin_menu', 'glmQuickSite_add_admin_menu' );
+add_action( 'admin_init', 'glmQuickSite_settings_init' );
+register_activation_hook(__FILE__, 'glmQuickSite_install_plugin_data');
+register_deactivation_hook(__FILE__, 'glmQuickSite_remove_plugin_data');
+
+function glmQuickSite_install_plugin_data(){
+    // [status_US] array of states and their abbr.
+    $states_US['']   = '-- Select --';// {{{
+    $states_US['AL'] = 'Alabama';
+    $states_US['AK'] = 'Alaska';
+    $states_US['AZ'] = 'Arizona';
+    $states_US['AR'] = 'Arkansas';
+    $states_US['CA'] = 'California';
+    $states_US['CO'] = 'Colorado';
+    $states_US['CT'] = 'Connecticut';
+    $states_US['DE'] = 'Delaware';
+    $states_US['DC'] = 'District of Columbia';
+    $states_US['FL'] = 'Florida';
+    $states_US['GA'] = 'Georgia';
+    $states_US['HI'] = 'Hawaii';
+    $states_US['ID'] = 'Idaho';
+    $states_US['IL'] = 'Illinois';
+    $states_US['IN'] = 'Indiana';
+    $states_US['IA'] = 'Iowa';
+    $states_US['KS'] = 'Kansas';
+    $states_US['KY'] = 'Kentucky';
+    $states_US['LA'] = 'Louisiana';
+    $states_US['ME'] = 'Maine';
+    $states_US['MD'] = 'Maryland';
+    $states_US['MA'] = 'Massachusetts';
+    $states_US['MI'] = 'Michigan';
+    $states_US['MN'] = 'Minnesota';
+    $states_US['MS'] = 'Mississippi';
+    $states_US['MO'] = 'Missouri';
+    $states_US['MT'] = 'Montana';
+    $states_US['NE'] = 'Nebraska';
+    $states_US['NV'] = 'Nevada';
+    $states_US['NH'] = 'New Hampshire';
+    $states_US['NJ'] = 'New Jersey';
+    $states_US['NM'] = 'New Mexico';
+    $states_US['NY'] = 'New York';
+    $states_US['NC'] = 'North Carolina';
+    $states_US['ND'] = 'North Dakota';
+    $states_US['OH'] = 'Ohio';
+    $states_US['OK'] = 'Oklahoma';
+    $states_US['OR'] = 'Oregon';
+    $states_US['PA'] = 'Pennsylvania';
+    $states_US['RI'] = 'Rhode Island';
+    $states_US['SC'] = 'South Carolina';
+    $states_US['SD'] = 'South Dakota';
+    $states_US['TN'] = 'Tennessee';
+    $states_US['TX'] = 'Texas';
+    $states_US['UT'] = 'Utah';
+    $states_US['VT'] = 'Vermont';
+    $states_US['VA'] = 'Virginia';
+    $states_US['WA'] = 'Washington';
+    $states_US['WV'] = 'West Virginia';
+    $states_US['WI'] = 'Wisconsin';
+    $states_US['WY'] = 'Wyoming';// }}}
+
+    // [states] extended states array
+    $states['AB'] = 'Alberta';// {{{
+    $states['AS'] = 'American Samoa';
+    $states['BC'] = 'British Columbia';
+    $states['DC'] = 'District of Columbia';
+    $states['FM'] = 'Federated States of Micronesia';
+    $states['GU'] = 'Guam';
+    $states['MB'] = 'Manitoba';
+    $states['MH'] = 'Marshall Islands';
+    $states['NB'] = 'New Brunswick';
+    $states['NF'] = 'Newfoundland';
+    $states['MP'] = 'Northern Mariana Islands';
+    $states['NT'] = 'Northwest Territories';
+    $states['NS'] = 'Nova Scotia';
+    $states['ON'] = 'Ontario';
+    $states['PW'] = 'Palau';
+    $states['PE'] = 'Prince Edward Island';
+    $states['PR'] = 'Puerto Rico';
+    $states['QC'] = 'Quebec';
+    $states['SK'] = 'Saskatchewan';
+    $states['VI'] = 'Virgin Islands';
+    $states['YT'] = 'Yukon';// }}}
+
+    //  Merge the 50 US states together with some of the extended
+    //  provinces / territories and then sort them on their keys
+    //  Then add the remaining countries and areas at the end
+    //  of the array.
+    $states = $states_US + $states;
+    ksort($states);
+    add_option( 'glmquicksite_states', $states );
+}
+
+function glmQuickSite_remove_plugin_data() {
+    delete_option( 'glmquicksite_settings' );
+    delete_option( 'glmquicksite_states' );
+}
+
+function glmQuickSite_add_admin_menu(  ) {
+
+    add_menu_page( 'glmQuickSite', 'glmQuickSite', 'edit_pages', 'glmquicksite', 'glmquicksite_options_page' );
+
+}
+
+
+function glmQuickSite_settings_exist(  ) {
+
+    if( false == get_option( 'glmquicksite_settings' ) ) {
+
+        add_option( 'glmquicksite_settings' );
+
+    }
+
+}
+
+function glmQuickSiteAddSettingTextField($name, $label, $type) {
+    switch ($type) {
+    case 'text':
+        $callback = 'glmQuickSiteRenderText';
+        break;
+    case 'textarea':
+        $callback = 'glmQuickSiteRenderTextArea';
+        break;
+    case 'state':
+        $callback = 'glmQuickSiteRenderStateSelect';
+        break;
+    default:
+        return false;
+        break;
+    }
+    add_settings_field(
+        $name,
+        __( $label, 'wordpress' ),
+        $callback,
+        'pluginPage',
+        'glmQuickSite_pluginPage_section',
+        $name
+    );
+}
+
+
+function glmQuickSite_settings_init(  ) {
+
+    register_setting( 'pluginPage', 'glmQuickSite_settings' );
+
+    add_settings_section(
+        'glmQuickSite_pluginPage_section',
+        __( 'Edit your Site Info', 'wordpress' ),
+        'glmQuickSite_settings_section_callback',
+        'pluginPage'
+    );
+
+    $fieldNames = array(
+        array(
+            'name'  => 'businessName',
+            'label' => 'Business Name',
+            'type'  => 'text'
+        ),
+        array(
+            'name'  => 'address',
+            'label' => 'Address',
+            'type'  => 'text'
+        ),
+        array(
+            'name'  => 'city',
+            'label' => 'City',
+            'type'  => 'text'
+        ),
+        array(
+            'name'  => 'state',
+            'label' => 'State',
+            'type'  => 'state'
+        ),
+        array(
+            'name'  => 'zip',
+            'label' => 'Zip',
+            'type'  => 'text'
+        ),
+        array(
+            'name'  => 'address2',
+            'label' => 'Address 2',
+            'type'  => 'text'
+        ),
+        array(
+            'name'  => 'city2',
+            'label' => 'City 2',
+            'type'  => 'text'
+        ),
+        array(
+            'name'  => 'state2',
+            'label' => 'State 2',
+            'type'  => 'state'
+        ),
+        array(
+            'name'  => 'zip2',
+            'label' => 'Zip 2',
+            'type'  => 'text'
+        ),
+        array(
+            'name'  => 'phone',
+            'label' => 'Phone',
+            'type'  => 'text'
+        ),
+        array(
+            'name'  => 'fax',
+            'label' => 'Fax',
+            'type'  => 'text'
+        ),
+        array(
+            'name'  => 'extra',
+            'label' => 'Extra Content',
+            'type'  => 'textarea'
+        ),
+    );
+
+    foreach ($fieldNames as $field) {
+        glmQuickSiteAddSettingTextField($field['name'], $field['label'], $field['type']);
+    }
+
+}
+
+function glmQuickSiteRenderText($fieldName) {
+    static $options;
+    if (!$options) {
+        $options = get_option( 'glmQuickSite_settings' );
+    }
+?>
+    <input type='text' name='glmQuickSite_settings[<?php echo $fieldName;?>]' value='<?php echo $options[$fieldName]; ?>'>
+<?php
+}
+
+function glmQuickSiteRenderTextArea($fieldName) {
+    static $options;
+    $options = get_option( 'glmQuickSite_settings' );
+?>
+    <textarea cols='40' rows='5' name='glmQuickSite_settings[<?php echo $fieldName;?>]'><?php echo $options[$fieldName]; ?></textarea>
+<?php
+}
+
+function glmQuickSiteRenderStateSelect($fieldName) {
+    static $options;
+    $options = get_option( 'glmQuickSite_settings' );
+    $states = get_option( 'glmQuickSite_states' );
+?>
+    <select name="glmQuickSite_settings[<?php echo $fieldName;?>]">
+    <?php foreach ($states as $stateAbbr => $stateName) :?>
+        <option value="<?php echo $stateAbbr;?>"<?php if ($options[$fieldName] == $stateAbbr) {echo ' selected';};?>>
+        <?php echo $stateName;?>
+        </option>
+    <?php endforeach;?>
+    </select>
+<?php
+}
+
+
+function glmQuickSite_settings_section_callback(  ) {
+
+    echo __( 'Business Name, Address and phone numbers', 'wordpress' );
+
+}
+
+
+function glmquicksite_options_page(  ) {
+
+?>
+<div class="wrap">
+
+    <form action='options.php' method='post'>
+
+        <h2>glmQuickSite</h2>
+
+<?php
+    settings_fields( 'pluginPage' );
+    do_settings_sections( 'pluginPage' );
+    submit_button();
+?>
+
+    </form>
+</div>
+<?php
+
+}
+
+?>