optionsGetOptions(); add_filter( 'plugin_row_meta', array( &$this, 'optionsSetPluginMeta' ), 10, 2 ); // add plugin page meta links add_action( 'admin_init', array( &$this, 'optionsInit' ) ); // whitelist options page add_action( 'admin_menu', array( &$this, 'optionsAddPage' ) ); // add link to plugin's settings page in 'settings' menu on admin menu initilization add_action( 'admin_notices', array( &$this, 'showAdminMessages' ) ); if( $options['location'] == 'head' ) add_action( 'wp_head', array( &$this, 'getAhalogyCode' ), 99999 ); else add_action( 'wp_footer', array( &$this, 'getAhalogyCode' ), 99999 ); } // load i18n textdomain function loadTextDomain() { load_plugin_textdomain( $this->plugin_textdomain, false, trailingslashit( dirname( plugin_basename( __FILE__ ) ) ) . 'lang/' ); } // get default plugin options function optionsGetDefaults() { $defaults = array( 'client_id' => '', 'insert_code' => 0, 'location' => 'head', 'mobilify_optin' => 0, 'mobilify_api_optin' => 1 ); return $defaults; } function optionsGetOptions() { $options = get_option( $this->options_name, $this->optionsGetDefaults() ); return $options; } // set plugin links function optionsSetPluginMeta( $links, $file ) { $plugin = plugin_basename( __FILE__ ); if ( $file == $plugin ) { // if called for THIS plugin then: $newlinks = array( '' . __( 'Settings', $this->plugin_textdomain ) . '' ); // array of links to add return array_merge( $links, $newlinks ); // merge new links into existing $links } return $links; // return the $links (merged or otherwise) } // plugin startup function optionsInit() { register_setting( $this->options_group, $this->options_name, array( &$this, 'optionsValidate' ) ); $options = $this->optionsGetOptions(); if ( false === $options || ! isset( $options['plugin_version'] ) || $options['plugin_version'] != $this->plugin_version ) { $this->clearCache(); if ( is_array( $options ) ) { $options['plugin_version'] = $this->plugin_version; delete_option('ahalogy_snippet_last_request'); delete_option('ahalogy_js_template'); update_option( $this->options_name, $options ); } } } // create and link options page function optionsAddPage() { add_options_page( $this->plugin_name . ' ' . __( 'Settings', $this->plugin_textdomain ), __( 'Ahalogy', $this->plugin_textdomain ), 'manage_options', $this->options_page, array( &$this, 'optionsDrawPage' ) ); } // sanitize and validate options input function optionsValidate( $input ) { $input['insert_code'] = (( isset($input['insert_code']) && ($input['insert_code'] )) ? 1 : 0 ); // (checkbox) if TRUE then 1, else NULL $input['client_id'] = wp_filter_nohtml_kses( $input['client_id'] ); // (textbox) safe text, no html $input['location'] = ( $input['location'] == 'head' ? 'head' : 'body' ); // (radio) either head or body $input['mobilify_api_optin'] = (( isset($input['mobilify_api_optin']) && ( $input['mobilify_api_optin'] )) ? 1 : 0 ); // (checkbox) if TRUE then 1, else NULL $input['mobilify_optin'] = (( isset($input['mobilify_optin']) && ( $input['mobilify_optin'] )) ? 1 : 0 ); // (checkbox) if TRUE then 1, else NULL //Check if the mobility_optin has changed or not $current_options = $this->optionsGetOptions(); if ($current_options['client_id']) { //Check if client_id has changed. If so, clear any mobilify cache by deleting the 'ahalogy_js_template' option if ((isset($current_options['mobilify_optin'])) && (isset($input['mobilify_optin']))) { if ($current_options['client_id'] <> $input['client_id']) { //Client IDs are different. Clear the cache. delete_option("ahalogy_js_template"); } } if ((isset($current_options['mobilify_optin'])) && (isset($input['mobilify_optin']))) { if ($current_options['mobilify_optin'] <> $input['mobilify_optin']) { if ($input['mobilify_optin']) { //They turned it on $payload_value = 'true'; } else { //They turned it off $payload_value = 'false'; } $url = $this->mobilify_api_domain . '/api/clients/' . $current_options['client_id'] . '/labs_changed'; $response = wp_remote_post( $url, array( 'method' => 'POST', 'timeout' => 10, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => array( 'value' => $payload_value ), 'cookies' => array() ) ); if ( is_wp_error( $response ) ) { //Setting the error but we won't do anything with it for now. $error_message = $response->get_error_message(); } } } } return $input; } // draw a checkbox option function optionsDrawCheckbox( $slug, $label, $style_checked='', $style_unchecked='' ) { $options = $this->optionsGetOptions(); $defaults = $this->optionsGetDefaults(); if (!isset($options[$slug])) { //index isn't identified. set the default $options[$slug] = $defaults[$slug]; } if( !$options[$slug] ) { if( !empty( $style_unchecked ) ) $style = ' style="' . $style_unchecked . '"'; else $style = ''; } else { if( !empty( $style_checked ) ) $style = ' style="' . $style_checked . '"'; else $style = ''; } ?> for="options_name; ?>[]"> plugin_textdomain ); ?> />

plugin_name . __( ' Settings', $this->plugin_textdomain ); ?>

options_group ); // nonce settings page ?> optionsGetOptions(); //populate $options array from database ?>

Ahalogy Support

optionsDrawCheckbox( 'insert_code', 'Include code snippet on my site', '', 'color:#000;' ); ?> optionsDrawCheckbox( 'mobilify_api_optin', 'Enable Ahalogy API Access', '', 'color:#000;' ); ?> optionsDrawCheckbox( 'mobilify_optin', 'Enable Mobile Optimization', '', 'color:#000;' ); ?>
/> (recommended)
/>

optionsGetOptions(); // code removed for all pages $disabled = sprintf(' ' , $this->plugin_version ); // Ahalogy widget code $widget_code = sprintf( ' ' , $this->plugin_version , $options['client_id'] , $this->widget_js_domain ); // build code if ( ( !$options['insert_code'] || strlen($options['client_id']) < 10) ) { echo $disabled; } else { echo $widget_code; } } /** * Generic function to show a message to the user using WP's * standard CSS classes to make use of the already-defined * message colour scheme. * * @param $message The message you want to tell the user. * @param $errormsg If true, the message is an error, so use * the red message style. If false, the message is a status * message, so use the yellow information message style. */ function showMessage($message, $errormsg = false) { if ($errormsg) { echo '
'; } else { echo '
'; } echo "

$message

"; } /** * Just show ClientID error message if necessary */ function showAdminMessages() { //Show a message on all admin pages if the client id is not set $options = get_option( $this->options_name, $this->optionsGetDefaults() ); if (empty($options['client_id'])) { // Only show to admins if ( current_user_can('manage_options') ) { $this->showMessage("Please enter your client ID to activate the Ahalogy plugin.", true); } } } public static function clearCache() { //Remove our options //delete_option('ahalogy_snippet_last_request'); //delete_option('ahalogy_js_template'); // Check for W3 Total Cache if (function_exists('w3tc_pgcache_flush')) { w3tc_pgcache_flush(); //echo ''; } // Check for WP Super Cache if (function_exists('wp_cache_clear_cache')) { wp_cache_clear_cache(); // echo ''; } } } // end class endif; // end collision check register_activation_hook( __FILE__, array( 'ahalogyWP', 'clearCache' ) ); $ahalogyWP_instance = new ahalogyWP; include_once dirname(__FILE__) . '/Ahalogy-wp-mobile.php'; include_once dirname(__FILE__) . '/Ahalogy-wp-mobile-post.php'; include_once dirname(__FILE__) . '/Ahalogy-wp-mobile-author.php'; include_once dirname(__FILE__) . '/Ahalogy-wp-mobile-attachment.php';