| 1 |
<?php |
| 2 |
namespace ElementorPostGrid; |
| 3 |
|
| 4 |
/** |
| 5 |
* Class Elementor_Post_Grid_Main |
| 6 |
* |
| 7 |
* Main Plugin class |
| 8 |
* @since 1.2.0 |
| 9 |
*/ |
| 10 |
class Elementor_Post_Grid_Main { |
| 11 |
|
| 12 |
/** |
| 13 |
* Instance |
| 14 |
* |
| 15 |
* @since 1.2.0 |
| 16 |
* @access private |
| 17 |
* @static |
| 18 |
* |
| 19 |
* @var Plugin The single instance of the class. |
| 20 |
*/ |
| 21 |
private static $_instance = null; |
| 22 |
|
| 23 |
/** |
| 24 |
* Instance |
| 25 |
* |
| 26 |
* Ensures only one instance of the class is loaded or can be loaded. |
| 27 |
* |
| 28 |
* @since 1.2.0 |
| 29 |
* @access public |
| 30 |
* |
| 31 |
* @return Plugin An instance of the class. |
| 32 |
*/ |
| 33 |
public static function instance() { |
| 34 |
if ( is_null( self::$_instance ) ) { |
| 35 |
self::$_instance = new self(); |
| 36 |
} |
| 37 |
return self::$_instance; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* widget_style |
| 42 |
* |
| 43 |
* Load main style files. |
| 44 |
* |
| 45 |
* @since 1.0.0 |
| 46 |
* @access public |
| 47 |
*/ |
| 48 |
|
| 49 |
public function widget_styles() { |
| 50 |
wp_register_style( 'post-grid-elementor-addon-main', plugins_url( '/assets/css/main.css', __FILE__ ) ); |
| 51 |
wp_enqueue_style( 'post-grid-elementor-addon-main' ); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Include Widgets files |
| 56 |
* |
| 57 |
* Load widgets files |
| 58 |
* |
| 59 |
* @since 1.2.0 |
| 60 |
* @access private |
| 61 |
*/ |
| 62 |
private function include_widgets_files() { |
| 63 |
require_once( __DIR__ . '/widgets/post-grid.php' ); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Register Widgets |
| 68 |
* |
| 69 |
* Register new Elementor widgets. |
| 70 |
* |
| 71 |
* @since 1.2.0 |
| 72 |
* @access public |
| 73 |
*/ |
| 74 |
public function register_widgets() { |
| 75 |
// Its is now safe to include Widgets files |
| 76 |
$this->include_widgets_files(); |
| 77 |
|
| 78 |
// Register Widgets |
| 79 |
\Elementor\Plugin::instance()->widgets_manager->register( new Widgets\Elementor_Post_Grid_Widget() ); |
| 80 |
} |
| 81 |
|
| 82 |
public function register_widget_category( $elements_manager ) { |
| 83 |
|
| 84 |
$elements_manager->add_category( |
| 85 |
'wpcap-items', |
| 86 |
[ |
| 87 |
'title' => __( 'WPC Elements', 'post-grid-elementor-addon' ), |
| 88 |
'icon' => 'fa fa-plug', |
| 89 |
] |
| 90 |
); |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Add action links to the plugins page. |
| 95 |
* |
| 96 |
* @since 2.0.3 |
| 97 |
* |
| 98 |
* @param array $links Links. |
| 99 |
*/ |
| 100 |
public function add_action_links( $links ) { |
| 101 |
$output = array_merge( |
| 102 |
array( |
| 103 |
'welcome' => '<a href="' . esc_url( admin_url( 'admin.php?page=pgea-welcome' ) ) . '">' . esc_html__( 'Welcome', 'post-grid-elementor-addon' ) . '</a>', |
| 104 |
), |
| 105 |
$links |
| 106 |
); |
| 107 |
|
| 108 |
$output = array_merge( |
| 109 |
$output, |
| 110 |
array( |
| 111 |
'go-pro' => '<a href="https://wphait.com/plugins/post-grid-elementor-addon/" target="_blank" style="font-weight:700;">' . esc_html__( 'Go Pro', 'post-grid-elementor-addon' ) . '</a>', |
| 112 |
) |
| 113 |
); |
| 114 |
|
| 115 |
return $output; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
/** |
| 120 |
* Plugin class constructor |
| 121 |
* |
| 122 |
* Register plugin action hooks and filters |
| 123 |
* |
| 124 |
* @since 1.2.0 |
| 125 |
* @access public |
| 126 |
*/ |
| 127 |
public function __construct() { |
| 128 |
|
| 129 |
// Register widget style |
| 130 |
add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'widget_styles' ] ); |
| 131 |
|
| 132 |
// Register widgets |
| 133 |
add_action( 'elementor/widgets/register', [ $this, 'register_widgets' ] ); |
| 134 |
|
| 135 |
add_action( 'elementor/elements/categories_registered', [ $this, 'register_widget_category' ] ); |
| 136 |
|
| 137 |
// Add an action links. |
| 138 |
add_filter( 'plugin_action_links_' . plugin_basename(__DIR__) . '/post-grid-elementor-addon.php', [ $this, 'add_action_links' ] ); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
// Instantiate Plugin Class |
| 143 |
Elementor_Post_Grid_Main::instance(); |
| 144 |
|