| 1 |
<?php |
| 2 |
|
| 3 |
namespace Amedea; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Class Plugin |
| 11 |
* |
| 12 |
* Main Plugin class |
| 13 |
* @since 1.0.0 |
| 14 |
*/ |
| 15 |
class Amedea { |
| 16 |
|
| 17 |
/** |
| 18 |
* Instance |
| 19 |
* |
| 20 |
* @since 1.0.0 |
| 21 |
* @access private |
| 22 |
* @static |
| 23 |
* |
| 24 |
* @var Plugin The single instance of the class. |
| 25 |
*/ |
| 26 |
private static $_instance = null; |
| 27 |
|
| 28 |
/** |
| 29 |
* Instance |
| 30 |
* |
| 31 |
* Ensures only one instance of the class is loaded or can be loaded. |
| 32 |
* |
| 33 |
* @since 1.0.0 |
| 34 |
* @access public |
| 35 |
* |
| 36 |
* @return Plugin An instance of the class. |
| 37 |
*/ |
| 38 |
public static function instance() { |
| 39 |
if ( is_null( self::$_instance ) ) { |
| 40 |
self::$_instance = new self(); |
| 41 |
} |
| 42 |
return self::$_instance; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* widget_scripts |
| 47 |
* |
| 48 |
* Load required plugin core files. |
| 49 |
* |
| 50 |
* @since 1.0.0 |
| 51 |
* @access public |
| 52 |
*/ |
| 53 |
public function amedea__widget_scripts() { |
| 54 |
|
| 55 |
wp_enqueue_script('jquery'); |
| 56 |
|
| 57 |
//Register Libraries |
| 58 |
foreach (glob(__DIR__ . '/assets/lib/*.js') as $filename) { |
| 59 |
wp_register_script(basename($filename, '.js'), plugins_url('/assets/lib/'.basename($filename),__FILE__), array(), true, true); |
| 60 |
} |
| 61 |
|
| 62 |
// Register jQuery |
| 63 |
foreach (glob(__DIR__ . '/assets/js/*.js') as $filename) { |
| 64 |
wp_register_script('amedea-'.basename($filename, '.js'), plugins_url('/assets/js/'.basename($filename),__FILE__), array(), true, true); |
| 65 |
} |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* widget_styles |
| 71 |
* |
| 72 |
* Load required plugin core files. |
| 73 |
* |
| 74 |
* @since 1.2.0 |
| 75 |
* @access public |
| 76 |
*/ |
| 77 |
public function amedea__widget_styles(){ |
| 78 |
|
| 79 |
wp_register_style('amedea',plugins_url('/assets/style.css',__FILE__)); |
| 80 |
wp_enqueue_style( 'amedea' ); |
| 81 |
|
| 82 |
foreach (glob(__DIR__ . '/assets/css/*.css') as $filename) { |
| 83 |
|
| 84 |
wp_register_style(basename($filename, '.css'),plugins_url('/assets/css/'.basename($filename),__FILE__)); |
| 85 |
} |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Include Widgets files |
| 91 |
* |
| 92 |
* Load widgets files |
| 93 |
* |
| 94 |
* @since 1.0.0 |
| 95 |
* @access private |
| 96 |
*/ |
| 97 |
private function amedea__include_widgets_files() { |
| 98 |
|
| 99 |
foreach (glob(__DIR__ . '/widgets/*/*.php') as $filename) { |
| 100 |
require_once $filename; |
| 101 |
} |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Register Widgets |
| 107 |
* |
| 108 |
* Register new Elementor widgets. |
| 109 |
* |
| 110 |
* @since 1.0.0 |
| 111 |
* @access public |
| 112 |
*/ |
| 113 |
public function amedea__register_widgets() { |
| 114 |
// Its is now safe to include Widgets files |
| 115 |
$this->amedea__include_widgets_files(); |
| 116 |
|
| 117 |
// Get the namespace |
| 118 |
$namespace = __NAMESPACE__ . '\\Widgets\\amedea__'; |
| 119 |
|
| 120 |
// Register widgets |
| 121 |
foreach (glob(__DIR__ . '/widgets/*/*.php') as $filename) { |
| 122 |
$className = str_replace("-","_",$namespace . basename($filename, '.php')); |
| 123 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type(new $className()); |
| 124 |
} |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
//category registered |
| 129 |
public function amedea__add_elementor_categories( $elements_manager ) { |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
$elements_manager->add_category( |
| 134 |
'amedea-category', |
| 135 |
[ |
| 136 |
'title' => esc_html__( 'Amedea', 'amedea' ), |
| 137 |
'icon' => 'fa fa-plug', |
| 138 |
] |
| 139 |
); |
| 140 |
|
| 141 |
$elements_manager->add_category( |
| 142 |
'amedea-theme-widgets-category', |
| 143 |
[ |
| 144 |
'title' => esc_html__( 'Amedea:Theme Widgets', 'amedea' ), |
| 145 |
'icon' => 'fa fa-plug', |
| 146 |
] |
| 147 |
); |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Plugin class constructor |
| 152 |
* |
| 153 |
* Register plugin action hooks and filters |
| 154 |
* |
| 155 |
* @since 1.0.0 |
| 156 |
* @access public |
| 157 |
*/ |
| 158 |
public function __construct() { |
| 159 |
|
| 160 |
// Enqueue widget styles |
| 161 |
add_action( 'elementor/frontend/after_register_styles', [ $this, 'amedea__widget_styles' ] , 100 ); |
| 162 |
add_action( 'admin_enqueue_scripts', [ $this, 'amedea__widget_styles' ] , 100 ); |
| 163 |
|
| 164 |
// Enqueue widget scripts |
| 165 |
add_action( 'elementor/frontend/after_register_scripts', [ $this, 'amedea__widget_scripts' ], 100 ); |
| 166 |
|
| 167 |
// Register widgets |
| 168 |
add_action( 'elementor/widgets/widgets_registered', [ $this, 'amedea__register_widgets' ] ); |
| 169 |
|
| 170 |
// Category registered |
| 171 |
add_action( 'elementor/elements/categories_registered', [ $this,'amedea__add_elementor_categories' ]); |
| 172 |
|
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
// Instantiate Plugin Class |
| 177 |
Amedea::instance(); |