Skip to content

Instantly share code, notes, and snippets.

@bschulz87
Last active February 5, 2020 16:12
Show Gist options
  • Save bschulz87/3fc4744a72c15cc0b9daf7da25e66d5c to your computer and use it in GitHub Desktop.
Save bschulz87/3fc4744a72c15cc0b9daf7da25e66d5c to your computer and use it in GitHub Desktop.
Elementor Custom Control
<?php
namespace ElementorControls;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class Elementor_Custom_Controls {
private static $_instance = null;
public static function instance() {
if ( is_null( self::$_instance) ) {
self::$_instance = new self();
}
return self::$_instance;
}
public function includes() {
require_once( __DIR__ . '/custom.php' );
}
public function register_controls() {
$this->includes();
$controls_manager = \Elementor\Plugin::$instance->controls_manager;
$controls_manager->register_control( 'CUSTOM', new Controls\Elementor_Custom() );
}
public function __construct() {
add_action( 'elementor/controls/controls_registered', [ $this, 'register_controls' ] );
}
}
Elementor_Custom_Controls::register_controls();
<?php
namespace ElementorControls\Controls;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class Elementor_Custom extends \Elementor\Base_Control {
public function get_type() {
return 'custom';
}
public function content_template() {
echo '<input type="text" placeholder="custom" data-setting="post" />';
}
}
<?php
namespace ElementorWidgets\Widgets;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Elementor Custom Widget
*
* Elementor widget.
*
* @since 1.0.0
*/
class Custom_Widget extends Widget_Base {
/* ... */
/**
* Register the widget controls.
*
* Adds different input fields to allow the user to change and customize the widget settings.
*
* @since 1.0.0
*
* @access protected
*/
protected function _register_controls() {
$this->start_controls_section(
'section_content',
[
'label' => __( 'Content', 'elementor-case-teaser' ),
]
);
$this->add_control(
'title',
[
'label' => __( 'Custom', 'elementor-custom-control' ),
'type' => Controls_Manager::CUSTOM,
]
);
$this->end_controls_section();
/* ... */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment