*/
class Ajax_AutoSearch_Admin {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Breadcrumb_Loader as all of the hooks are defined
* in that particular class.
*
* The Breadcrumb_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name . '-icon', plugin_dir_url( __FILE__ ) . 'css/icon-style.css', array(), $this->version, 'all' );
if ( isset( $_GET['page'] ) && 'ajax-autosearch' === $_GET['page'] ) {
wp_enqueue_style( $this->plugin_name . '-display-dashboard', plugin_dir_url( __FILE__ ) . 'css/admin-dashboard.css', array(), $this->version, 'all' );
}
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Breadcrumb_Loader as all of the hooks are defined
* in that particular class.
*
* The Breadcrumb_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
if ( isset( $_GET['page'] ) && 'ajax-autosearch' === $_GET['page'] ) {
wp_enqueue_script( 'matchHeight', plugin_dir_url( __FILE__ ) . 'js/jquery-matchHeight.min.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/ajax-autosearch-admin.js', array( 'jquery', 'matchHeight', 'jquery-ui-tooltip' ), $this->version, false );
}
}
/**
* Ajax AutoSearch: action_links
* Ajax AutoSearch Settings Link function callback
*
* @param arrray $links Link url.
*
* @param arrray $file File name.
*/
public function action_links( $links, $file ) {
if ( $file === $this->plugin_name . '/' . $this->plugin_name . '.php' ) {
$settings_link = '' . esc_html__( 'Settings', 'ajax-autosearch' ) . '';
array_unshift( $links, $settings_link );
}
return $links;
}
/**
* Add plugin menu for the admin area.
*
* @since 1.0.0
*/
public function add_plugin_settings_menu() {
$icon = AJAX_AUTOSEARCH_URL . 'admin/images/icon.svg';
add_menu_page(
esc_html__( 'Ajax AutoSearch', 'ajax-autosearch' ), // $page_title.
esc_html__( 'Ajax AutoSearch', 'ajax-autosearch' ), // $menu_title.
'manage_options', // $capability.
'ajax-autosearch', // $menu_slug.
array( $this, 'settings_page' ), // $callback_function.
$icon, // $icon_url.
'99.01564' // $position.
);
}
/**
* Settings page for the admin area.
*
* @since 1.0.0
*/
public function settings_page() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'ajax-autosearch' ) );
}
require plugin_dir_path( __FILE__ ) . 'partials/ajax-autosearch-admin-display.php';
}
/**
* Register the plugin settings for the admin area.
*
* @since 1.0.0
*/
public function register_settings() {
register_setting(
'ajax-autosearch-group',
'ajax_autosearch_options',
array( $this, 'sanitize_callback' )
);
}
/**
* Register the stylesheets for the admin area.
*
* @param array $input Input data.
* @since 1.0.0
*/
public function sanitize_callback( $input ) {
if ( isset( $input['reset'] ) && $input['reset'] ) {
// If reset, restore defaults.
return ajax_autosearch_default_options();
}
$message = null;
$type = null;
// Verify the nonce before proceeding.
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|| ( ! isset( $_POST['ajax_autosearch_nounce'] )
|| ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['ajax_autosearch_nounce'] ) ), basename( __FILE__ ) ) )
|| ( ! check_admin_referer( basename( __FILE__ ), 'ajax_autosearch_nounce' ) ) ) {
if ( null !== $input ) {
$input['enable_post_filter'] = ( isset( $input['enable_post_filter'] ) && '1' === $input['enable_post_filter'] ) ? '1' : '0';
$input['enable_category_filter'] = ( isset( $input['enable_category_filter'] ) && '1' === $input['enable_category_filter'] ) ? '1' : '0';
$input['enable_tags_filter'] = ( isset( $input['enable_tags_filter'] ) && '1' === $input['enable_tags_filter'] ) ? '1' : '0';
$input['show_featured_image'] = ( isset( $input['show_featured_image'] ) && '1' === $input['show_featured_image'] ) ? '1' : '0';
$input['limit'] = ( isset( $input['limit'] ) ) ? absint( $input['limit'] ) : 10;
}
return $input;
}
return 'Invalid Nonce';
}
/**
* Adds meta links in plugin page.
*
* @param array $meta_fields Meta fields.
* @param string $file File Path.
* @since 1.0.0
*/
public function add_plugin_meta_links( $meta_fields, $file ) {
if ( AJAX_AUTOSEARCH_BASENAME == $file ) {
$meta_fields[] = '' . esc_html__( 'Support Forum', 'ajax-autosearch' ) . '';
$meta_fields[] = '
'
. ""
. ""
. ""
. ""
. ""
. '';
$stars_color = '#ffb900';
echo '';
}
return $meta_fields;
}
}