admin_actions();
}
}
/**
* Instance.
*
* Implements a Singleton pattern - Ensures only one instance of the plugin class is loaded or can be loaded.
*
* @since 2.0.0
* @static
*
* @return Plugin An instance of the class.
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
/**
* Add Chat App loaded.
*
* Fires when Add Chat App Button was fully loaded and instantiated.
*
* @since 1.0.0
*/
do_action( 'add_chat_app_button_loaded' );
}
return self::$instance;
}
/**
* Admin Actions
*
* Run actions for the Admin Dashboard.
*
* @since 2.0.0
*/
private function admin_actions() {
require_once( __DIR__ . '/admin/settings.php' );
//Load admin notice dismissal management library
require_once( plugin_dir_path( __FILE__ ) . '/vendors/persist-admin-notices-dismissal/persist-admin-notices-dismissal.php' );
add_action( 'admin_init', array( 'PAnD', 'init' ) );
// Add a link to the plugin's Settings page from the Plugins Page
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), [ $this, 'add_plugin_action_link' ], 10, 5 );
new Admin_Settings();
}
// Load Plugin Textdomain
public function load_awb_textdomain() {
load_plugin_textdomain( 'add-whatsapp-button', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
/**
* Add Plugin Action Link
*
* Add a link to the plugin settings page to the list of action links displayed for a specific plugin in the Plugins list table.
*
* @since 2.0.0
*/
public function add_plugin_action_link( $links ) {
$settings = array(
'settings' => '' . esc_html__( 'Settings', 'add-whatsapp-button' ) . ''
);
return array_merge( $settings, $links );
}
/**
* Init
*
* Initializes the plugin's functionality.
*
* @since 2.0.0
*/
public function init() {
require_once( plugin_dir_path( __FILE__ ) . '/includes/scripts-manager.php' );
require_once( plugin_dir_path( __FILE__ ) . '/includes/styles-manager.php' );
$this->scripts_manager = new Scripts_Manager();
$this->styles_manager = new Styles_Manager();
if ( $this->get_plugin_options( 'enable' ) && ! is_admin() ) {
// Print the WhatsApp button
add_action('wp_footer', [ $this, 'print_button' ] );
}
}
public function print_button() {
$settings = $this->get_plugin_options();
$button_text = isset( $settings['button_text'] ) ? sanitize_text_field( $settings['button_text'] ) : _e('Message Us on WhatsApp', 'add-whatsapp-button');
$displayNoneIfIcon = ( $settings['button_type'] == 'wab-icon-plain' || $settings['button_type'] == 'wab-icon-styled' ) ? 'awb-displaynone' : '';
$button_style = !empty( $settings['button_type'] ) ? $settings['button_type'] : 'wab-side-rectangle';
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$close_button_icon = '';
if ( 'wab-bottom-rectangle' !== $settings['button_type'] ) {
$button_location = isset( $settings['button_location'] ) ? 'wab-pull-'.$settings['button_location'] : 'wab-pull-left';
}
if ( 'full' === $settings['hide_button'] ) {
$close_button_icon = 'x';
}
else if ( 'hide' === $settings['hide_button'] ) {
if ( 'right' === $settings['button_location'] && 'wab-bottom-rectangle' !== $settings['button_type'] ) {
$close_button_icon = '';
} else if ( 'left' === $settings['button_location'] && 'wab-bottom-rectangle' !== $settings['button_type'] ) {
$close_button_icon = '
';
} else if ( 'wab-bottom-rectangle' === $settings['button_type'] ) {
$close_button_icon = '
';
}
}
ob_start();
?>