Skip to content

Commit

Permalink
Add return types (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
rami-elementor authored Dec 1, 2024
1 parent 7ff399b commit 2f9f3ed
Show file tree
Hide file tree
Showing 127 changed files with 476 additions and 475 deletions.
14 changes: 7 additions & 7 deletions src/addons/addon-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ final class Plugin {
* @since 1.0.0
* @access public
*/
public function is_compatible() {
public function is_compatible(): void {

// Check if Elementor installed and activated
if ( ! did_action( 'elementor/loaded' ) ) {
Expand Down Expand Up @@ -192,7 +192,7 @@ final class Plugin {
* @since 1.0.0
* @access public
*/
public function admin_notice_missing_main_plugin() {
public function admin_notice_missing_main_plugin(): void {

if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );

Expand All @@ -215,7 +215,7 @@ final class Plugin {
* @since 1.0.0
* @access public
*/
public function admin_notice_minimum_elementor_version() {
public function admin_notice_minimum_elementor_version(): void {

if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );

Expand All @@ -239,7 +239,7 @@ final class Plugin {
* @since 1.0.0
* @access public
*/
public function admin_notice_minimum_php_version() {
public function admin_notice_minimum_php_version(): void {

if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );

Expand All @@ -265,7 +265,7 @@ final class Plugin {
* @since 1.0.0
* @access public
*/
public function init() {
public function init(): void {

add_action( 'elementor/widgets/register', [ $this, 'register_widgets' ] );
add_action( 'elementor/controls/register', [ $this, 'register_controls' ] );
Expand All @@ -281,7 +281,7 @@ final class Plugin {
*
* @param \Elementor\Widgets_Manager $widgets_manager Elementor widgets manager.
*/
public function register_widgets( $widgets_manager ) {
public function register_widgets( $widgets_manager ): void {

require_once( __DIR__ . '/includes/widgets/widget-1.php' );
require_once( __DIR__ . '/includes/widgets/widget-2.php' );
Expand All @@ -300,7 +300,7 @@ final class Plugin {
*
* @param \Elementor\Controls_Manager $controls_manager Elementor controls manager.
*/
public function register_controls( $controls_manager ) {
public function register_controls( $controls_manager ): void {

require_once( __DIR__ . '/includes/controls/control-1.php' );
require_once( __DIR__ . '/includes/controls/control-2.php' );
Expand Down
9 changes: 5 additions & 4 deletions src/addons/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ final class Plugin {
*
* @since 1.0.0
* @access public
* @return bool
*/
public function is_compatible() {
public function is_compatible(): bool {

// Check if Elementor is installed and activated
if ( ! did_action( 'elementor/loaded' ) ) {
Expand Down Expand Up @@ -86,7 +87,7 @@ final class Plugin {
* @since 1.0.0
* @access public
*/
public function admin_notice_missing_main_plugin() {
public function admin_notice_missing_main_plugin(): void {

if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );

Expand All @@ -109,7 +110,7 @@ final class Plugin {
* @since 1.0.0
* @access public
*/
public function admin_notice_minimum_elementor_version() {
public function admin_notice_minimum_elementor_version(): void {

if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );

Expand All @@ -133,7 +134,7 @@ final class Plugin {
* @since 1.0.0
* @access public
*/
public function admin_notice_minimum_php_version() {
public function admin_notice_minimum_php_version(): void {

if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );

Expand Down
14 changes: 7 additions & 7 deletions src/addons/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ final class Plugin {
* @since 1.0.0
* @access public
*/
public function init() {
public function init(): void {

add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'frontend_styles' ] );
add_action( 'elementor/frontend/after_register_scripts', [ $this, 'frontend_scripts' ] );

}

public function frontend_styles() {
public function frontend_styles(): void {

wp_register_style( 'frontend-style-1', plugins_url( 'assets/css/frontend-style-1.css', __FILE__ ) );
wp_register_style( 'frontend-style-2', plugins_url( 'assets/css/frontend-style-2.css', __FILE__ ), [ 'external-framework' ] );
Expand All @@ -39,7 +39,7 @@ final class Plugin {

}

public function frontend_scripts() {
public function frontend_scripts(): void {

wp_register_script( 'frontend-script-1', plugins_url( 'assets/js/frontend-script-1.js', __FILE__ ) );
wp_register_script( 'frontend-script-2', plugins_url( 'assets/js/frontend-script-2.js', __FILE__ ), [ 'external-library' ] );
Expand Down Expand Up @@ -70,7 +70,7 @@ final class Plugin {
* @since 1.0.0
* @access public
*/
public function init() {
public function init(): void {

add_action( 'elementor/widgets/register', [ $this, 'register_widgets' ] );

Expand All @@ -85,7 +85,7 @@ final class Plugin {
*
* @param \Elementor\Widgets_Manager $widgets_manager Elementor widgets manager.
*/
public function register_widgets( $widgets_manager ) {
public function register_widgets( $widgets_manager ): void {

require_once( __DIR__ . '/includes/widgets/widget-1.php' );
require_once( __DIR__ . '/includes/widgets/widget-2.php' );
Expand Down Expand Up @@ -115,7 +115,7 @@ final class Plugin {
* @since 1.0.0
* @access public
*/
public function init() {
public function init(): void {

add_action( 'elementor/controls/register', [ $this, 'register_controls' ] );

Expand All @@ -130,7 +130,7 @@ final class Plugin {
*
* @param \Elementor\Controls_Manager $controls_manager Elementor controls manager.
*/
public function register_controls( $controls_manager ) {
public function register_controls( $controls_manager ): void {

require_once( __DIR__ . '/includes/controls/control-1.php' );
require_once( __DIR__ . '/includes/controls/control-2.php' );
Expand Down
8 changes: 4 additions & 4 deletions src/addons/main-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ final class Plugin {
public static function instance() {}

public function __construct() {}
public function is_compatible() {}
public function init() {}
public function is_compatible(): bool {}
public function init(): void {}

}
```
Expand Down Expand Up @@ -94,7 +94,7 @@ final class Plugin {
* @since 1.0.0
* @access public
*/
public function is_compatible() {
public function is_compatible(): bool {

// Compatibility checks here...

Expand All @@ -110,7 +110,7 @@ final class Plugin {
* @since 1.0.0
* @access public
*/
public function init() {
public function init(): void {

// Addon functionality here...

Expand Down
24 changes: 12 additions & 12 deletions src/controls/complex-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Elementor_EmojiOneArea_Control extends \Elementor\Base_Data_Control {
* @access public
* @return string Control type.
*/
public function get_type() {
public function get_type(): string {
return 'emojionearea';
}

Expand All @@ -119,7 +119,7 @@ class Elementor_EmojiOneArea_Control extends \Elementor\Base_Data_Control {
* @since 1.0.0
* @access public
*/
public function enqueue() {
public function enqueue(): void {
// Styles
wp_register_style( 'emojionearea', 'https://cdnjs.cloudflare.com/ajax/libs/emojionearea/3.4.2/emojionearea.css', [], '3.4.2' );
wp_enqueue_style( 'emojionearea' );
Expand All @@ -140,7 +140,7 @@ class Elementor_EmojiOneArea_Control extends \Elementor\Base_Data_Control {
* @access protected
* @return array Control default settings.
*/
protected function get_default_settings() {
protected function get_default_settings(): array {
return [
'label_block' => true,
'rows' => 3,
Expand All @@ -158,7 +158,7 @@ class Elementor_EmojiOneArea_Control extends \Elementor\Base_Data_Control {
* @since 1.0.0
* @access public
*/
public function content_template() {
public function content_template(): void {
$control_uid = $this->get_control_uid();
?>
<div class="elementor-control-field">
Expand Down Expand Up @@ -245,7 +245,7 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {
* @access public
* @return string Widget name.
*/
public function get_name() {
public function get_name(): string {
return 'test';
}

Expand All @@ -258,7 +258,7 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {
* @access public
* @return string Widget title.
*/
public function get_title() {
public function get_title(): string {
return esc_html__( 'Test', 'elementor-emojionearea-control' );
}

Expand All @@ -271,7 +271,7 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {
* @access public
* @return string Widget icon.
*/
public function get_icon() {
public function get_icon(): string {
return 'eicon-code';
}

Expand All @@ -284,7 +284,7 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {
* @access public
* @return array Widget categories.
*/
public function get_categories() {
public function get_categories(): array {
return [ 'general' ];
}

Expand All @@ -297,7 +297,7 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {
* @access public
* @return array Widget keywords.
*/
public function get_keywords() {
public function get_keywords(): array {
return [ 'test', 'emoji' ];
}

Expand All @@ -310,7 +310,7 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {
* @access public
* @return string Widget help URL.
*/
public function get_custom_help_url() {
public function get_custom_help_url(): string {
return 'https://developers.elementor.com/docs/widgets/';
}

Expand All @@ -322,7 +322,7 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {
* @since 1.0.0
* @access protected
*/
protected function register_controls() {
protected function register_controls(): void {

$this->start_controls_section(
'content_section',
Expand Down Expand Up @@ -353,7 +353,7 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {
* @since 1.0.0
* @access protected
*/
protected function render() {
protected function render(): void {
$settings = $this->get_settings_for_display();

if ( empty( $settings['content'] ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/controls/control-enqueue.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ If you need to use an external library or some custom JS/CSS, you can do that by
```php
class Elementor_Test_Control extends \Elementor\Base_Control {

protected function enqueue() {
protected function enqueue(): void {

// Styles
wp_register_style( 'control-style', plugins_url( 'assets/css/control-style.css', __FILE__ ) );
Expand Down
2 changes: 1 addition & 1 deletion src/controls/control-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ If a control uses the default settings, you don't need to add it to your class.
```php
class Elementor_Test_Control extends \Elementor\Base_Control {

protected function get_default_settings() {
protected function get_default_settings(): array {

return [
'label_block' => true,
Expand Down
14 changes: 7 additions & 7 deletions src/controls/control-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ A simple control only requires two methods, the control type and the template:
```php
class Elementor_Test_Control extends \Elementor\Base_Control {

public function get_type() {}
public function get_type(): string {}

public function content_template() {}
public function content_template(): void {}

}
```
Expand All @@ -43,15 +43,15 @@ More advanced controls can use other available methods:
```php
class Elementor_Test_Control extends \Elementor\Base_Control {

public function get_type() {}
public function get_type(): string {}

protected function get_default_settings() {}
protected function get_default_settings(): array {}

public function get_default_value() {}
public function get_default_value(): string {}

public function content_template() {}
public function content_template(): void {}

public function enqueue() {}
public function enqueue(): void {}

}
```
Expand Down
2 changes: 1 addition & 1 deletion src/controls/control-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ With JS templates we don’t need to retrieve data using a special function, Ele
<?php
class Elementor_Test_Control extends \Elementor\Base_Control {

public function content_template() {
public function content_template(): void {
$control_uid = $this->get_control_uid();
?>

Expand Down
8 changes: 4 additions & 4 deletions src/controls/control-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ The following will set a default value for a [data control](./../editor-controls
```php
class Elementor_Test_Control extends \Elementor\Base_Data_Control {

public function get_type() {
public function get_type(): string {
return 'continents-control';
}

protected function get_default_settings() {
protected function get_default_settings(): array {
return [
'continents' => [ 'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Australia/Oceania', 'Antarctica', ]
];
}

public function get_default_value() {
public function get_default_value(): string {
return 'Europe';
}

Expand All @@ -38,7 +38,7 @@ When controls are used in widgets, you can either use the default value set by t
<?php
class Elementor_Test_Widget extends \Elementor\Widget_Base {

protected function register_controls() {
protected function register_controls(): void {

$this->start_controls_section(
'section_content',
Expand Down
Loading

0 comments on commit 2f9f3ed

Please sign in to comment.