Changeset 1931811
- Timestamp:
- 08/28/2018 02:30:43 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
hubspot-tracking-code/branches/deprecation-version-bump/admin/hubspot-tracking-code-admin.php
r1931584 r1931811 30 30 function __construct () 31 31 { 32 //============================================= 33 // Hooks & Filters 34 //============================================= 35 36 $options = get_option('hs_settings'); 37 38 // If the plugin version matches the latest version escape the update function 39 if ( $options['hs_version'] != HUBSPOT_TRACKING_CODE_PLUGIN_VERSION ) 40 self::hubspot_tracking_code_update_check(); 41 42 add_action('admin_menu', array(&$this, 'hubspot_add_menu_items')); 43 add_action('admin_init', array(&$this, 'hubspot_build_settings_page')); 44 add_filter('plugin_action_links_' . HUBSPOT_TRACKING_CODE_PLUGIN_SLUG . '/hubspot-tracking-code.php', array($this, 'hubspot_plugin_settings_link')); 32 //============================================= 33 // Hooks & Filters 34 //============================================= 35 36 $options = get_option('hs_settings'); 37 38 // If the plugin version matches the latest version escape the update function 39 if ( $options['hs_version'] != HUBSPOT_TRACKING_CODE_PLUGIN_VERSION ) 40 self::hubspot_tracking_code_update_check(); 41 42 add_action('admin_menu', array($this, 'hubspot_add_menu_items')); 43 add_action('admin_init', array($this, 'hubspot_build_settings_page')); 44 add_action('admin_notices', array($this, 'admin_notice')); 45 add_filter('plugin_action_links_' . HUBSPOT_TRACKING_CODE_PLUGIN_SLUG . '/hubspot-tracking-code.php', array($this, 'hubspot_plugin_settings_link')); 45 46 } 46 47 47 48 function hubspot_tracking_code_update_check () 48 49 { 49 $options = get_option('hs_settings');50 51 // Set the plugin version52 hubspot_tracking_code_update_option('hs_settings', 'hs_version', HUBSPOT_TRACKING_CODE_PLUGIN_VERSION);50 $options = get_option('hs_settings'); 51 52 // Set the plugin version 53 hubspot_tracking_code_update_option('hs_settings', 'hs_version', HUBSPOT_TRACKING_CODE_PLUGIN_VERSION); 53 54 } 54 55 … … 59 60 function hubspot_add_menu_items () 60 61 { 61 add_submenu_page('options-general.php', 'HubSpot Settings', 'HubSpot Settings', 'edit_posts', basename(__FILE__), array($this, 'hubspot_plugin_options'));62 add_submenu_page('options-general.php', 'HubSpot Settings', 'HubSpot Settings', 'edit_posts', basename(__FILE__), array($this, 'hubspot_plugin_options')); 62 63 } 63 64 … … 75 76 function hubspot_plugin_settings_link ( $links ) 76 77 { 77 $url = get_admin_url() . 'options-general.php?page=hubspot-tracking-code-admin.php';78 $settings_link = '<a href="' . $url . '">Settings</a>';79 array_unshift($links, $settings_link);80 return $links;78 $url = get_admin_url() . 'options-general.php?page=hubspot-tracking-code-admin.php'; 79 $settings_link = '<a href="' . $url . '">Settings</a>'; 80 array_unshift($links, $settings_link); 81 return $links; 81 82 } 82 83 … … 86 87 function hubspot_build_settings_page () 87 88 { 88 global $pagenow;89 $options = get_option('hs_settings');90 91 register_setting(92 'hubspot_settings_options',93 'hs_settings',94 array($this, 'sanitize')95 );96 97 add_settings_section(98 'hubspot_settings_section',99 '',100 array($this, 'hs_settings_section_heading'),101 HUBSPOT_TRACKING_CODE_ADMIN_PATH102 );103 104 add_settings_field(105 'hs_portal',106 'Hub ID',107 array($this, 'hs_portal_callback'),108 HUBSPOT_TRACKING_CODE_ADMIN_PATH,109 'hubspot_settings_section'110 );89 global $pagenow; 90 $options = get_option('hs_settings'); 91 92 register_setting( 93 'hubspot_settings_options', 94 'hs_settings', 95 array($this, 'sanitize') 96 ); 97 98 add_settings_section( 99 'hubspot_settings_section', 100 '', 101 array($this, 'hs_settings_section_heading'), 102 HUBSPOT_TRACKING_CODE_ADMIN_PATH 103 ); 104 105 add_settings_field( 106 'hs_portal', 107 'Hub ID', 108 array($this, 'hs_portal_callback'), 109 HUBSPOT_TRACKING_CODE_ADMIN_PATH, 110 'hubspot_settings_section' 111 ); 111 112 } 112 113 113 114 function hs_settings_section_heading ( ) 114 115 { 115 $this->print_hidden_settings_fields();116 $this->print_hidden_settings_fields(); 116 117 } 117 118 118 119 function print_hidden_settings_fields () 119 120 { 120 // Hacky solution to solve the Settings API overwriting the default values121 $options = get_option('hs_settings');122 123 $hs_installed = ( isset($options['hs_installed']) ? $options['hs_installed'] : 1 );124 $hs_version = ( isset($options['hs_version']) ? $options['hs_version'] : HUBSPOT_TRACKING_CODE_PLUGIN_VERSION );125 126 printf(127 '<input id="hs_installed" type="hidden" name="hs_settings[hs_installed]" value="%d"/>',128 $hs_installed129 );130 131 printf(132 '<input id="hs_version" type="hidden" name="hs_settings[hs_version]" value="%s"/>',133 $hs_version134 );121 // Hacky solution to solve the Settings API overwriting the default values 122 $options = get_option('hs_settings'); 123 124 $hs_installed = ( isset($options['hs_installed']) ? $options['hs_installed'] : 1 ); 125 $hs_version = ( isset($options['hs_version']) ? $options['hs_version'] : HUBSPOT_TRACKING_CODE_PLUGIN_VERSION ); 126 127 printf( 128 '<input id="hs_installed" type="hidden" name="hs_settings[hs_installed]" value="%d"/>', 129 $hs_installed 130 ); 131 132 printf( 133 '<input id="hs_version" type="hidden" name="hs_settings[hs_version]" value="%s"/>', 134 $hs_version 135 ); 135 136 } 136 137 … … 140 141 function hubspot_plugin_options () 141 142 { 142 ?>143 ?> 143 144 <div class="wrap"> 144 145 <div class="dashboard-widgets-wrap"> … … 192 193 </div> 193 194 </div> 194 <?php 195 <?php 196 } 197 198 function admin_notice() { 199 printf( '<div class="notice notice-warning"><p>The HubSpot Tracking Code plugin is unsupported. <a href="%1$s">More details</a></p></div>', admin_url( 'options-general.php?page=hubspot-tracking-code-admin.php' ) ); 195 200 } 196 201 … … 202 207 public function sanitize ( $input ) 203 208 { 204 $new_input = array();205 206 $options = get_option('hs_settings');207 208 if ( isset($input['hs_portal']) )209 $new_input['hs_portal'] = $input['hs_portal'];210 211 if ( isset($input['hs_installed']) )212 $new_input['hs_installed'] = $input['hs_installed'];213 214 if ( isset($input['hs_version']) )215 $new_input['hs_version'] = $input['hs_version'];216 217 return $new_input;209 $new_input = array(); 210 211 $options = get_option('hs_settings'); 212 213 if ( isset($input['hs_portal']) ) 214 $new_input['hs_portal'] = $input['hs_portal']; 215 216 if ( isset($input['hs_installed']) ) 217 $new_input['hs_installed'] = $input['hs_installed']; 218 219 if ( isset($input['hs_version']) ) 220 $new_input['hs_version'] = $input['hs_version']; 221 222 return $new_input; 218 223 } 219 224 … … 223 228 function hs_portal_callback () 224 229 { 225 $options = get_option('hs_settings'); 226 $hs_portal = ( isset($options['hs_portal']) && $options['hs_portal'] ? $options['hs_portal'] : '' ); 227 228 printf( 229 '<input id="hs_portal" type="text" id="title" name="hs_settings[hs_portal]" style="width: 400px;" value="%s"/>', 230 $hs_portal 231 ); 232 233 //echo '<p><a href="http://help.hubspot.com/articles/KCS_Article/Account/Where-can-I-find-my-HUB-ID" target="_blank">Where can I find my HUB ID?</a></p>'; 230 $options = get_option('hs_settings'); 231 $hs_portal = ( isset($options['hs_portal']) && $options['hs_portal'] ? $options['hs_portal'] : '' ); 232 233 printf( 234 '<input id="hs_portal" type="text" id="title" name="hs_settings[hs_portal]" style="width: 400px;" value="%s"/>', 235 $hs_portal 236 ); 237 234 238 } 235 239 } 236 237 240 ?>
Note: See TracChangeset
for help on using the changeset viewer.