Plugin Directory

Changeset 1931811


Ignore:
Timestamp:
08/28/2018 02:30:43 PM (8 years ago)
Author:
gcorne
Message:

Add admin notice to nudge folks to switch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • hubspot-tracking-code/branches/deprecation-version-bump/admin/hubspot-tracking-code-admin.php

    r1931584 r1931811  
    3030        function __construct ()
    3131        {
    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'));
    4546        }
    4647
    4748        function hubspot_tracking_code_update_check ()
    4849        {
    49                 $options = get_option('hs_settings');
    50 
    51                 // Set the plugin version
    52                 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);
    5354        }
    5455
     
    5960        function hubspot_add_menu_items ()
    6061        {
    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'));
    6263        }
    6364
     
    7576        function hubspot_plugin_settings_link ( $links )
    7677        {
    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;
    8182        }
    8283
     
    8687        function hubspot_build_settings_page ()
    8788        {
    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_PATH
    102                 );
    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            );
    111112        }
    112113
    113114        function hs_settings_section_heading ( )
    114115        {
    115                 $this->print_hidden_settings_fields();
     116            $this->print_hidden_settings_fields();
    116117        }
    117118
    118119        function print_hidden_settings_fields ()
    119120        {
    120                 // Hacky solution to solve the Settings API overwriting the default values
    121                 $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_installed
    129                 );
    130 
    131                 printf(
    132                         '<input id="hs_version" type="hidden" name="hs_settings[hs_version]" value="%s"/>',
    133                         $hs_version
    134                 );
     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            );
    135136        }
    136137
     
    140141        function hubspot_plugin_options ()
    141142        {
    142                 ?>
     143            ?>
    143144            <div class="wrap">
    144145                <div class="dashboard-widgets-wrap">
     
    192193                </div>
    193194            </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' ) );
    195200        }
    196201
     
    202207        public function sanitize ( $input )
    203208        {
    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;
    218223        }
    219224
     
    223228        function hs_portal_callback ()
    224229        {
    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
    234238        }
    235239}
    236 
    237240?>
Note: See TracChangeset for help on using the changeset viewer.