| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class LP_Elementor_Widgets |
| 5 |
* |
| 6 |
* @author Nhamdv |
| 7 |
* @since 4.1.6 |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
class LP_Elementor_Widgets { |
| 11 |
/** |
| 12 |
* @var LP_Elementor_Widgets |
| 13 |
*/ |
| 14 |
protected static $instance = null; |
| 15 |
/** |
| 16 |
* @var array |
| 17 |
*/ |
| 18 |
public static $widgets = []; |
| 19 |
|
| 20 |
/** |
| 21 |
* Construct |
| 22 |
*/ |
| 23 |
public function __construct() { |
| 24 |
self::$widgets = include_once 'lp-elementor-widgets-config.php'; |
| 25 |
add_action( 'elementor/elements/categories_registered', array( $this, 'register_category' ) ); |
| 26 |
add_action( 'elementor/widgets/widgets_registered', array( $this, 'register_widgets' ), 10, 1 ); |
| 27 |
add_action( 'elementor/frontend/before_enqueue_scripts', array( $this, 'enqueue_frontend_scripts' ) ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Register category LearnPress |
| 32 |
* |
| 33 |
* @param Elementor\Elements_Manager $elements_manager |
| 34 |
* |
| 35 |
* @return void |
| 36 |
*/ |
| 37 |
public function register_category( Elementor\Elements_Manager $elements_manager ) { |
| 38 |
$elements_manager->add_category( |
| 39 |
'learnpress', |
| 40 |
array( |
| 41 |
'title' => esc_html__( 'LearnPress', 'learnpress' ), |
| 42 |
'icon' => 'eicon-navigator', |
| 43 |
) |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
public function register_widgets( $widgets_manager ) { |
| 48 |
if ( ! empty( self::$widgets ) ) { |
| 49 |
|
| 50 |
// Abstract class for widgets. |
| 51 |
require_once LP_PLUGIN_PATH . 'inc/external-plugin/elementor/widgets/widget-base.php'; |
| 52 |
|
| 53 |
foreach ( self::$widgets as $widget => $class ) { |
| 54 |
if ( ! class_exists( $class ) ) { |
| 55 |
$widget_path = LP_PLUGIN_PATH . 'inc/external-plugin/elementor/widgets/' . $widget . '.php'; |
| 56 |
|
| 57 |
if ( file_exists( $widget_path ) ) { |
| 58 |
require_once $widget_path; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
if ( class_exists( $class ) ) { |
| 63 |
$widgets_manager->register_widget_type( new $class() ); |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
public function enqueue_frontend_scripts() { |
| 70 |
if ( ! wp_style_is( 'font-awesome-5-all' ) ) { |
| 71 |
wp_enqueue_style( 'font-awesome-5-all', LP_PLUGIN_URL . 'assets/src/css/vendor/font-awesome-5.min.css', array(), array() ); |
| 72 |
} |
| 73 |
|
| 74 |
if ( ! wp_style_is( 'learnpress' ) ) { |
| 75 |
wp_enqueue_style( 'learnpress', LP_PLUGIN_URL . 'css/learnpress.css', array(), array() ); |
| 76 |
} |
| 77 |
|
| 78 |
if ( ! wp_script_is( 'lp-utils' ) ) { |
| 79 |
wp_enqueue_script( 'lp-utils', LP_PLUGIN_URL . 'js/dist/utils.js', array( 'jquery' ), LEARNPRESS_VERSION ); |
| 80 |
} |
| 81 |
|
| 82 |
if ( ! wp_script_is( 'lp-become-a-teacher' ) ) { |
| 83 |
wp_enqueue_script( 'lp-become-a-teacher', LP_PLUGIN_URL . 'src/js/frontend/become-teacher.js', array( 'jquery' ), LEARNPRESS_VERSION, true ); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
public static function instance() { |
| 88 |
if ( ! self::$instance ) { |
| 89 |
self::$instance = new self(); |
| 90 |
} |
| 91 |
|
| 92 |
return self::$instance; |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
LP_Elementor_Widgets::instance(); |
| 97 |
|