| 1 |
<?php |
| 2 |
/** |
| 3 |
* Elementor service provider. |
| 4 |
* |
| 5 |
* @package sureforms. |
| 6 |
* @since 0.0.5 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace SRFM\Inc\Page_Builders\Elementor; |
| 10 |
|
| 11 |
use SRFM\Inc\Traits\Get_Instance; |
| 12 |
|
| 13 |
/** |
| 14 |
* Elementor service provider. |
| 15 |
*/ |
| 16 |
class Service_Provider { |
| 17 |
use Get_Instance; |
| 18 |
|
| 19 |
/** |
| 20 |
* Constructor |
| 21 |
* |
| 22 |
* Load Elementor integration. |
| 23 |
* |
| 24 |
* @since 0.0.5 |
| 25 |
* @return void |
| 26 |
*/ |
| 27 |
public function __construct() { |
| 28 |
if ( ! class_exists( '\Elementor\Plugin' ) ) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
add_action( 'elementor/widgets/register', [ $this, 'widget' ] ); |
| 33 |
add_action( 'elementor/elements/categories_registered', [ $this, 'categories_registered' ] ); |
| 34 |
add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'load_scripts' ] ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Elementor load scripts |
| 39 |
* |
| 40 |
* @since 0.0.5 |
| 41 |
* @return void |
| 42 |
*/ |
| 43 |
public function load_scripts() { |
| 44 |
wp_enqueue_script( 'sureforms-elementor-editor', plugins_url( 'assets/editor.js', __FILE__ ), [], SRFM_VER, true ); |
| 45 |
wp_enqueue_style( 'sureforms-elementor-style', plugins_url( 'assets/editor.css', __FILE__ ), [], SRFM_VER, 'all' ); |
| 46 |
wp_localize_script( |
| 47 |
'sureforms-elementor-editor', |
| 48 |
'srfmElementorData', |
| 49 |
[ |
| 50 |
'admin_url' => admin_url(), |
| 51 |
'add_new_form_url' => admin_url( 'admin.php?page=add-new-form' ), |
| 52 |
] |
| 53 |
); |
| 54 |
// Note: Styling preview script is loaded in Form_Widget constructor |
| 55 |
// when in preview mode to ensure it runs in the correct iframe context. |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Elementor surecart categories register |
| 60 |
* |
| 61 |
* @param object $elements_manager Elementor category manager. |
| 62 |
* @since 0.0.5 |
| 63 |
* @return void |
| 64 |
*/ |
| 65 |
public function categories_registered( $elements_manager ) { |
| 66 |
|
| 67 |
if ( ! method_exists( $elements_manager, 'add_category' ) ) { |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
$elements_manager->add_category( |
| 72 |
'sureforms-elementor', |
| 73 |
[ |
| 74 |
'title' => esc_html__( 'SureForms', 'sureforms' ), |
| 75 |
'icon' => 'fa fa-plug', |
| 76 |
] |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Elementor widget register |
| 82 |
* |
| 83 |
* @param object $widgets_manager Elementor widget manager. |
| 84 |
* @since 0.0.5 |
| 85 |
* @return void |
| 86 |
*/ |
| 87 |
public function widget( $widgets_manager ) { |
| 88 |
if ( ! method_exists( $widgets_manager, 'register' ) ) { |
| 89 |
return; |
| 90 |
} |
| 91 |
$widgets_manager->register( new Form_Widget() ); |
| 92 |
$widgets_manager->register( new Payment_History_Widget() ); |
| 93 |
} |
| 94 |
|
| 95 |
} |
| 96 |
|