api = $api;
$this->settings = $settings;
$this->sections = $this->settings->sections;
$this->settings_fields = $this->settings->settings_fields;
add_action( 'admin_enqueue_scripts', array($this, 'asslAdminStyle') );
//Avviso admin
add_action('admin_notices', array($this, 'noHttpsWarning') );
add_action('admin_init', array($this, 'noHttpsWarningReaded') );
add_action('admin_notices', array($this, 'notSavedTab') );
add_action( 'admin_init', array($this, 'admin_init') );
add_action( 'admin_menu', array($this, 'admin_menu') );
}
/**
*
*/
public function asslAdminStyle()
{
wp_enqueue_style( 'assl-admin-style', ASSL__PLUGIN_URL . 'assets/backend/css/assl-admin-style.css' );
}
/**
* @return bool
*/
public function checkHttpsServer()
{
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
return true;
} else {
return false;
}
}
/**
*
*/
public function noHttpsWarning()
{
if(!$this->checkHttpsServer()) {
global $current_user;
$user_id = $current_user->ID;
if ( ! get_user_meta($user_id, 'no_https_hide') ) {
$html = '';
$html .= '
';
$html .= '
As Store Locator Plugin - ' .__("User Geolocation features only be accessible on \"secure origins\" (such as HTTPS). To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.", ASSL__TEXTDOMAIN) . '
';
$html .= sprintf(__('
Ok, dismiss this notice.
', ASSL__TEXTDOMAIN), '?no_https_hide=0');
$html .= '
';
echo $html;
}
}
}
/**
*
*/
public function notSavedTab() {
$html = '';
$layout = get_option('assl_admin_layout');
$map = get_option('assl_admin_map');
$advanced = get_option('assl_admin_advanced');
if(
empty($layout)
||
empty($map)
||
empty($advanced)
) {
$html .= '';
$html .= '
As Store Locator Plugin - ' .__("Save all 3 settings tabs.", ASSL__TEXTDOMAIN) . '
';
$html .= '
';
$html .= empty($layout) ? '- ' . __("Layout Settings not saved;", ASSL__TEXTDOMAIN) . '
' : '';
$html .= empty($map) ? '- ' . __("Map Settings not saved;", ASSL__TEXTDOMAIN) . '
' : '';
$html .= empty($advanced) ? '- ' . __("Advanced Settings not saved;", ASSL__TEXTDOMAIN) . '
' : '';
$html .= '
';
$html .= sprintf(__('
Go to settings and save all tabs.
', ASSL__TEXTDOMAIN), menu_page_url('assl_settings', false));
$html .= '
';
}
echo $html;
}
/**
*
*/
public function noHttpsWarningReaded()
{
if(!$this->checkHttpsServer()) {
global $current_user;
$user_id = $current_user->ID;
/* If user clicks to ignore the notice, add that to their user meta */
if ( isset($_GET['no_https_hide']) && '0' == $_GET['no_https_hide'] ) {
add_user_meta($user_id, 'no_https_hide', 'true', true);
}
}
}
/**
*
*/
function admin_init()
{
//set the settings
$this->api->set_sections( $this->get_settings_sections() );
$this->api->set_fields( $this->get_settings_fields() );
//initialize settings
$this->api->admin_init();
}
/**
*
*/
function admin_menu()
{
add_submenu_page('edit.php?post_type=store', __('Settings', ASSL__TEXTDOMAIN), __('Settings', ASSL__TEXTDOMAIN), 'manage_options', 'assl_settings', array($this, 'plugin_page'));
}
/**
* @return array
*/
function get_settings_sections()
{
$sections = $this->sections;
return $sections;
}
/**
* @return array
*/
function get_settings_fields() {
$settings_fields = $this->settings_fields;
return $settings_fields;
}
/**
*
*/
function plugin_page() {
$this->api->show_intro();
echo '';
$this->api->show_navigation();
$this->api->show_forms();
echo '
';
echo '
';
echo __('Developed by', ASSL__TEXTDOMAIN).' alfiosalanitri.it | '.__('Support', ASSL__TEXTDOMAIN).' | '.__('Plugin Homepage', ASSL__TEXTDOMAIN).'';
}
/**
* @param $option
* @param $section
* @param string $default
*
* @return string
*/
public function getOption( $option, $section, $default = '' ) {
$options = get_option( $section );
if ( isset( $options[$option] ) ) {
return $options[$option];
}
return $default;
}
}