首页 > 解决方案 > 如何更改 Elementor 弹出位置设置?

问题描述

我在我工作的一个网站上遇到问题,其中 Elementor 弹出窗口的“edit_in_content”位置设置对于所有弹出窗口都设置为 FALSE,并且它阻止管理员进入 Elementor 编辑器。

此问题表现为常见的“the_content not found”错误消息,但是,调试会导致弹出窗口的位置设置成为问题。问题出在\ElementorPro\Modules\ThemeBuilder\Classes\Locations_Manager 的builder_wrapper 方法中,该方法位于/elementor-pro/modules/theme-builder/classes/locations-manager.php 中。

public function builder_wrapper( $content ) {
    $post_id = get_the_ID();

    if ( $post_id ) {
        $document = Module::instance()->get_document( $post_id );
        if ( $document ) {
            $document_location = $document->get_location();
            $location_settings = $this->get_location( $document_location );

            /**
             * Custom Modification Begin
             * ------------------------------------
             */
            if( $document_location == 'popup' )
                return $content;
            /**
             * Custom Modification End
             * ------------------------------------
             */

            // If is a `content` document or the theme is not support the document location (header/footer and etc.).
            if ( $location_settings && ! $location_settings['edit_in_content'] ) {
                $content = '<div class="elementor-theme-builder-content-area">' . __( 'Content Area', 'elementor-pro' ) . '</div>';
            }
        }
    }

    return $content;
}

我知道这是一个插件黑客,不推荐,但我没有找到其他方法来处理这个问题。

  1. 我不确定为什么所有弹出窗口的 edit_in_content 都是 FALSE。
  2. 我发现无法确保 edit_in_content 为 TRUE,以便管理员可以使用弹出窗口。

公平地说,我应该透露主题是定制的,但相当少。当切换到二十二十时,问题就消失了。测试期间所有插件都已禁用,并且弹出位置设置似乎受到自定义主题的影响。

  1. 我在 2020 中没有发现任何以任何方式引用 elementor 的内容。
  2. 我已经阅读了 Elementor 与 the_content 问题相关的文档,但没有任何说明会导致成功。参考:https ://docs.elementor.com/article/56-content-area-not-found

所以,我希望有人能够对这个问题有所了解。我该怎么做才能不必破解插件?

标签: wordpresselementor

解决方案


我发布答案是因为我发现了一些我可以做的事情来不破解插件,尽管我仍然很好奇为什么需要这样做。我基本上只是添加一个钩子/动作,在它最初注册后重新处理弹出位置。这可以放在主题的 functions.php 文件中:

function fixElementorPopupLocation( $that )
{
    $loc = $that->get_location('popup');
    
    if( ! $loc['edit_in_content'] )
    {
        $args = [
            'label'           => $loc['label'],
            'multiple'        => $loc['multiple'],
            'public'          => $loc['public'],
            'edit_in_content' => TRUE,
            'hook'            => $loc['hook'],
        ];
        
        $that->register_location('popup', $args);
    }
}
add_action(
    'elementor/theme/register_locations', 
    'fixElementorPopupLocation', 
    93062220 
);

如果有人能告诉我为什么我需要这样做,以及为什么我在 220 主题中不需要这样做,我很乐意接受这个作为答案,只要我可以使用这些建议来“修复”我的主题。


推荐阅读