Skip to content

Instantly share code, notes, and snippets.

@bob-moore
Last active April 4, 2023 12:45
Show Gist options
  • Save bob-moore/986bafade1aa0b04bb30e0a2f08fb105 to your computer and use it in GitHub Desktop.
Save bob-moore/986bafade1aa0b04bb30e0a2f08fb105 to your computer and use it in GitHub Desktop.
Removing core theme builder locations in Elementor. The first file is the original file in Elementor, just for reference. The second is a mu plugin to disable select locations. This must be ran via plugin or mu-plugin, because it runs before themes are loaded.
<?php
/**
* Plugin Name: Elementor Mods
* Plugin URI: https://gist.github.com/bob-moore/986bafade1aa0b04bb30e0a2f08fb105
* Description: Mod some elementor stuff
* Version: 0.1.0
* Author: Bob Moore
* Author URI: https://github.com/bob-moore
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
/**
* Remove the action the registers the default document types in the theme builder
*
* 1. Get the instance of the types manager, so we can remove the same instance
* 2. Remove the action
*
* @see elementor-pro/modules/theme-builder/classes/template-types-manager.php
* @return void
*/
function prefix_unregister_types_manager() {
if ( ! class_exists( '\\ElementorPro\\Modules\\ThemeBuilder\\Module' ) ) {
return false;
}
$types_manager = \ElementorPro\Modules\ThemeBuilder\Module::instance()->get_types_manager();
remove_action( 'elementor/documents/register', [$types_manager, 'register_documents']);
}
add_action( 'elementor/init', 'prefix_unregister_types_manager' );
/**
* Register only the document types you want to allow
*
* Copied from the core elementor class. Uncomment each document type you want
* to be allowed to show
*
* @see elementor-pro/modules/theme-builder/classes/template-types-manager.php
* @return void
*/
function prefix_register_document_types() {
if ( ! class_exists( '\\ElementorPro\\Modules\\ThemeBuilder\\Module' ) ) {
return false;
}
$docs_types = [
'section' => \ElementorPro\Modules\ThemeBuilder\Documents\Section::get_class_full_name(),
'header' => \ElementorPro\Modules\ThemeBuilder\Documents\Header::get_class_full_name(),
'footer' => \ElementorPro\Modules\ThemeBuilder\Documents\Footer::get_class_full_name(),
// 'single' => Documents\Single::get_class_full_name(),
// 'single-post' => Documents\Single_Post::get_class_full_name(),
// 'single-page' => Documents\Single_Page::get_class_full_name(),
// 'archive' => Documents\Archive::get_class_full_name(),
// 'search-results' => Documents\Search_Results::get_class_full_name(),
'error-404' => \ElementorPro\Modules\ThemeBuilder\Documents\Error_404::get_class_full_name(),
];
foreach ( $docs_types as $type => $class_name ) {
\Elementor\Plugin::instance()->documents->register_document_type( $type, $class_name );
}
}
add_action( 'elementor/documents/register', 'prefix_register_document_types' );
<?php
/**
* Original file in Elementor
*/
namespace ElementorPro\Modules\ThemeBuilder\Classes;
use ElementorPro\Modules\ThemeBuilder\Documents;
use ElementorPro\Plugin;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Templates_Types_Manager {
private $docs_types = [];
public function __construct() {
add_action( 'elementor/documents/register', [ $this, 'register_documents' ] );
}
public function get_types_config( $args = [] ) {
$config = [];
$document_types = Plugin::elementor()->documents->get_document_types( $args );
foreach ( $document_types as $type => $document_type ) {
$properties = $document_type::get_properties();
if ( ( new $document_type() ) instanceof Documents\Theme_Document ) {
$config[ $type ] = $properties;
}
}
return $config;
}
public function register_documents() {
$this->docs_types = [
'section' => Documents\Section::get_class_full_name(),
'header' => Documents\Header::get_class_full_name(),
'footer' => Documents\Footer::get_class_full_name(),
'single' => Documents\Single::get_class_full_name(),
'single-post' => Documents\Single_Post::get_class_full_name(),
'single-page' => Documents\Single_Page::get_class_full_name(),
'archive' => Documents\Archive::get_class_full_name(),
'search-results' => Documents\Search_Results::get_class_full_name(),
'error-404' => Documents\Error_404::get_class_full_name(),
];
foreach ( $this->docs_types as $type => $class_name ) {
Plugin::elementor()->documents->register_document_type( $type, $class_name );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment