'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => '',
'show_in_rest' => false,
]
);
add_filter('allowed_redirect_hosts', [$this, 'add_allowed_redirect_host']);
}
/**
* Adding the domain to the list of allowed redirects
*
* @param array $hosts Array of allowed hosts
* @return array Updated array of hosts
*/
public function add_allowed_redirect_host($hosts) {
$hosts[] = 'app.allsourcedata.io';
return $hosts;
}
/**
* Adding a menu item in the admin area
*/
public function add_admin_menu() {
add_options_page(
esc_html__('Allsource Settings', 'allsource'),
esc_html__('Allsource', 'allsource'),
'manage_options',
'allsource-settings',
[$this, 'render_settings_page']
);
}
/**
* Displaying the settings page
*/
public function render_settings_page() {
if (!current_user_can('manage_options')) {
wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'allsource'));
}
$settings_file = ALLSOURCE_PLUGIN_DIR . 'admin/views/allsource-settings.php';
if (!file_exists($settings_file)) {
wp_die(esc_html__('Settings template file not found.', 'allsource'));
}
require_once $settings_file;
}
/**
* Enabling scripts on the frontend
*/
public function enqueue_frontend_scripts() {
$pixel_client_id = get_option(ALLSOURCE_OPTION_PIXEL_CLIENT_ID, '');
if (empty($pixel_client_id)) {
return;
}
$script_path = ALLSOURCE_PLUGIN_DIR . 'includes/js/allsource-pixel.js';
if (!file_exists($script_path)) {
return;
}
wp_enqueue_script(
'allsource-pixel',
ALLSOURCE_PLUGIN_URL . 'includes/js/allsource-pixel.js',
[],
ALLSOURCE_VERSION,
['strategy' => 'async']
);
wp_localize_script(
'allsource-pixel',
'allsourceConfig',
[
'pixelClientId' => $pixel_client_id,
'pluginUrl' => ALLSOURCE_PLUGIN_URL,
'nonce' => wp_create_nonce('allsource_frontend_nonce'),
]
);
}
/**
* Enabling styles in the admin area
*/
public function enqueue_admin_styles($hook) {
if ('settings_page_allsource-settings' !== $hook) {
return;
}
$css_path = ALLSOURCE_PLUGIN_DIR . 'admin/static/allsource-admin-style.css';
if (!file_exists($css_path)) {
return;
}
wp_enqueue_style(
'allsource-admin-style',
ALLSOURCE_PLUGIN_URL . 'admin/static/allsource-admin-style.css',
[],
filemtime($css_path)
);
}
/**
* Adding links on the plugins page
*
* @param array $links Existing links
* @return array Changed links
*/
public function add_plugin_action_links($links) {
$settings_link = sprintf(
'%s',
esc_url(admin_url('options-general.php?page=allsource-settings')),
esc_html__('Settings', 'allsource')
);
$support_link = sprintf(
'%s',
esc_url('https://allsourceio.zohodesk.com/portal/en/kb/articles/how-to-integrate-wordpress'),
esc_html__('Support', 'allsource')
);
array_unshift($links, $settings_link, $support_link);
return $links;
}
}