Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
For Elementor Page Builder Plugin: Remove the regular WordPress Widgets from the left-hand Panel in the Live Editor. --- CAUTION: Use at your own risk! No support here!!!
<?php
/** Do NOT include the opening php tag */
if ( ! function_exists( 'ddw_tweak_elementor_remove_wp_widgets' ) ) :
add_filter( 'elementor/widgets/black_list', 'ddw_tweak_elementor_remove_wp_widgets' );
/**
* Optionally remove all WordPress widgets from the Elementor Live Editor.
* Note: A native Elementor filter is used.
*
* @link https://gist.github.com/deckerweb/11878962da6f4e31877520e199254cef
* @author David Decker - DECKERWEB
*
* @global array $GLOBALS[ 'wp_widget_factory' ]
*
* @param array $black_list Array holding all blacklisted WordPress widgets.
* @return array Tweaked array of black listed WordPress widgets.
*/
function ddw_tweak_elementor_remove_wp_widgets( $black_list ) {
/** Bail early if Elementor not active or tweak not wanted */
if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
return $black_list;
}
/**
* Get all registered WordPress widgets, but only the classes
* (= the first-level array keys)
*/
$black_list = array_keys( $GLOBALS[ 'wp_widget_factory' ]->widgets );
/** Return black list array for filter */
return (array) $black_list;
} // end function
endif;
@pako69
Copy link

pako69 commented Feb 22, 2020

Hi and thanks for this :)

Do you have any idea to remove chosen widgets that comes from the Pro version as well?

They are listed in this file (comming from the pro version):

<?php
namespace ElementorPro;

use ElementorPro\Base\Module_Base;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

final class Manager {
	/**
	 * @var Module_Base[]
	 */
	private $modules = [];

	public function __construct() {
		$modules = [
			'query-control',
			'custom-attributes',
			'custom-css',
			// role-manager Must be before Global Widget
			'role-manager',
			'global-widget',
			'assets-manager',
			'popup',
			'motion-fx',
			'usage',

			// Modules with Widgets.
			'theme-builder',
			'posts',
			'gallery',
			'forms',
			'slides',
			'nav-menu',
			'animated-headline',
			'pricing',
			'flip-box',
			'call-to-action',
			'carousel',
			'table-of-contents',
			'countdown',
			'share-buttons',
			'theme-elements',
			'blockquote',
			'woocommerce',
			'social',
			'library',
			'dynamic-tags',
			'sticky',
			'wp-cli',
			'link-actions',
		];

		foreach ( $modules as $module_name ) {
			$class_name = str_replace( '-', ' ', $module_name );
			$class_name = str_replace( ' ', '', ucwords( $class_name ) );
			$class_name = __NAMESPACE__ . '\\Modules\\' . $class_name . '\Module';

			/** @var Module_Base $class_name */
			if ( $class_name::is_active() ) {
				$this->modules[ $module_name ] = $class_name::instance();
			}
		}
	}

	/**
	 * @param string $module_name
	 *
	 * @return Module_Base|Module_Base[]
	 */
	public function get_modules( $module_name ) {
		if ( $module_name ) {
			if ( isset( $this->modules[ $module_name ] ) ) {
				return $this->modules[ $module_name ];
			}

			return null;
		}

		return $this->modules;
	}
}
 

@pako69
Copy link

pako69 commented Feb 22, 2020

I did it, sorry:

add_action('elementor/widgets/widgets_registered', function( $widget_manager ){
	// FREE
	$widget_manager->unregister_widget_type('read-more');
	$widget_manager->unregister_widget_type('sidebar');
	$widget_manager->unregister_widget_type('audio');
	
	// PRO
	$widget_manager->unregister_widget_type('form');
	$widget_manager->unregister_widget_type('nav-menu');

}, 15);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment