Last active
February 5, 2020 16:12
-
-
Save bschulz87/3fc4744a72c15cc0b9daf7da25e66d5c to your computer and use it in GitHub Desktop.
Elementor Custom Control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" />'; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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