Skip to content
This repository has been archived by the owner on May 9, 2019. It is now read-only.

Commit

Permalink
Merge pull request #242 from algolia/ease-poweredby-removal
Browse files Browse the repository at this point in the history
Add an option to disable Algolia powered by link
  • Loading branch information
rayrutjes authored Sep 12, 2016
2 parents 36ac4bc + b06321a commit af0ac6c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 16 deletions.
8 changes: 5 additions & 3 deletions assets/css/algolia-instantsearch.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#algolia-search-box {
position: relative;
margin-bottom: 2rem;
margin-bottom: 3rem;
}

#algolia-search-box input {
Expand All @@ -49,9 +49,11 @@
}

.ais-search-box--powered-by {
position: absolute;
top: 54px;
right: 0;
font-size: 14px;
text-align: right;
margin-top: 2px;
}

.ais-search-box--powered-by-link {
Expand All @@ -68,7 +70,7 @@
}
.ais-stats {
position: absolute;
bottom: 0;
top: 54px;
font-size: 14px;
}

Expand Down
28 changes: 28 additions & 0 deletions includes/admin/class-algolia-admin-page-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,18 @@ public function add_settings() {
$this->section
);

add_settings_field(
'algolia_powered_by_enabled',
__( 'Remove Algolia powered by logo', 'algolia' ),
array( $this, 'powered_by_enabled_callback' ),
$this->slug,
$this->section
);

register_setting( $this->option_group, 'algolia_application_id', array( $this, 'sanitize_application_id' ) );
register_setting( $this->option_group, 'algolia_search_api_key', array( $this, 'sanitize_search_api_key' ) );
register_setting( $this->option_group, 'algolia_api_key', array( $this, 'sanitize_api_key' ) );
register_setting( $this->option_group, 'algolia_powered_by_enabled', array( $this, 'sanitize_powered_by_enabled' ) );
}

public function application_id_callback() {
Expand All @@ -132,6 +141,16 @@ public function api_key_callback() {
'<p class="description" id="home-description">' . __( 'Your Algolia ADMIN API key (kept private).', 'algolia' ) . '</p>';
}

public function powered_by_enabled_callback() {
$powered_by_enabled = $this->plugin->get_settings()->is_powered_by_enabled();
$checked = '';
if( ! $powered_by_enabled) {
$checked = ' checked';
}
echo "<input type='checkbox' name='algolia_powered_by_enabled' value='no' " . $checked . " />" .
'<p class="description" id="home-description">' . __( 'This will remove the Algolia logo from the autocomplete and the search page. We require that you keep the Algolia logo if you are using a free Hacker plan.', 'algolia' ) . '</p>';
}

public function sanitize_application_id( $value ) {
$value = sanitize_text_field( $value );

Expand Down Expand Up @@ -222,6 +241,15 @@ public function sanitize_api_key( $value ) {

return $value;
}

/**
* @param $value
*
* @return string
*/
public function sanitize_powered_by_enabled( $value ) {
return $value === 'no' ? 'no' : 'yes';
}

/**
* Display the page.
Expand Down
18 changes: 18 additions & 0 deletions includes/class-algolia-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct()
add_option( 'algolia_index_name_prefix', 'wp_' );
add_option( 'algolia_logging_enabled', 'no' );
add_option( 'algolia_api_is_reachable', 'no' );
add_option( 'algolia_powered_by_enabled', 'yes' );
}

/**
Expand Down Expand Up @@ -168,4 +169,21 @@ public function set_api_is_reachable( $flag ) {
$value = (bool) $flag === true ? 'yes' : 'no';
update_option( 'algolia_api_is_reachable', $value );
}

/**
* @return bool
*/
public function is_powered_by_enabled() {
$enabled = get_option( 'algolia_powered_by_enabled', 'yes' );

return $enabled === 'yes';
}

public function enable_powered_by() {
update_option( 'algolia_powered_by_enabled', 'yes' );
}

public function disable_powered_by() {
update_option( 'algolia_powered_by_enabled', 'no' );
}
}
1 change: 1 addition & 0 deletions includes/class-algolia-template-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function load_algolia_config() {
'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
'application_id' => $settings->get_application_id(),
'search_api_key' => $settings->get_search_api_key(),
'powered_by_enabled' => $settings->is_powered_by_enabled(),
'autocomplete' => array(
'sources' => $autocomplete_config->get_config(),
),
Expand Down
26 changes: 14 additions & 12 deletions templates/autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,21 @@
jQuery("input[name='s']").each(function(i) {
var $searchInput = jQuery(this);

var config = {
debug: algolia.debug,
hint: false,
openOnFocus: true,
templates: {}
};
//Todo: Add empty template when we fixed https://github.com/algolia/autocomplete.js/issues/109

if(algolia.powered_by_enabled) {
config.templates.footer = wp.template('autocomplete-footer');
}

// Instantiate autocomplete.js
autocomplete($searchInput[0],
{
debug: algolia.debug,
hint: false,
openOnFocus: true,
templates: {
//empty: wp.template('autocomplete-empty'), // Waiting for https://github.com/algolia/autocomplete.js/issues/109
footer: wp.template('autocomplete-footer')
}
},
sources
).on('autocomplete:selected', function(e, suggestion, datasetName) {
autocomplete($searchInput[0], config, sources)
.on('autocomplete:selected', function(e, suggestion, datasetName) {
// Redirect the user when we detect a suggestion selection.
window.location.href = suggestion.permalink;
});
Expand Down
2 changes: 1 addition & 1 deletion templates/instantsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
container: '#algolia-search-box',
placeholder: 'Search for...',
wrapInput: false,
poweredBy: true
poweredBy: algolia.powered_by_enabled
})
);

Expand Down

0 comments on commit af0ac6c

Please sign in to comment.