在beaver builder自定义模块开发中,如何在创建这些设置的同一页面中获取创建的设置。例如,如果我在custom.php
文件中创建设置并且frontend.php
文件中有设置,我想在custom.php
文件中获取这些已保存的值...是否可以?如果可能的话怎么做?
以下是custom.php文件中的数据:
FLBuilder::register_module('FLExampleModuleGallery', array(
'general' => array( // Tab
'title' => __('General', 'fl-builder'), // Tab title
'sections' => array( // Tab Sections
'general' => array( // Section
'title' => __('Section Title', 'fl-builder'), // Section Title
'fields' => array( // Section Fields
'select_field' => array(
'type' => 'select',
'label' => __('Show Filter or Not?', 'fl-builder'),
'default' => 'option-1',
'options' => array(
'option-1' => __('Yes', 'fl-builder'),
'option-2' => __('No', 'fl-builder')
)
),
'no_of_posts' => array(
'type' => 'my-custom-field',
'label' => __('Provide your desired number of Posts', 'fl-builder'),
'default' => '8'
),
'no_of_cols' => array(
'type' => 'select',
'label' => __('Provide your desired number of Cols', 'fl-builder'),
'default' => 'option-2',
'options' => array(
'option-1' => __('2', 'fl-builder'),
'option-2' => __('3', 'fl-builder'),
'option-3' => __('4', 'fl-builder'),
'option-4' => __('6', 'fl-builder')
)
),
'show_overlay' => array(
'type' => 'select',
'label' => __('Do You Want to Show Overlay?', 'fl-builder'),
'default' => 'option-1',
'options' => array(
'option-1' => __('Yes', 'fl-builder'),
'option-2' => __('No', 'fl-builder')
)
),
'show_lightbox' => array(
'type' => 'select',
'label' => __('Do You Want to Open Image in lightbox?', 'fl-builder'),
'default' => 'option-1',
'options' => array(
'option-1' => __('Yes', 'fl-builder'),
'option-2' => __('No', 'fl-builder')
)
),
'show_lightbox_link' => array(
'type' => 'select',
'label' => __('Do You Want to show Link Icon in Lightbox?', 'fl-builder'),
'default' => 'option-1',
'options' => array(
'option-1' => __('Yes', 'fl-builder'),
'option-2' => __('No', 'fl-builder')
)
),
'show_title' => array(
'type' => 'select',
'label' => __('Do You Want to show Post Title?', 'fl-builder'),
'default' => 'option-1',
'options' => array(
'option-1' => __('Yes', 'fl-builder'),
'option-2' => __('No', 'fl-builder')
)
),
'show_title_link' => array(
'type' => 'select',
'label' => __('Do You Want to use Link in Post Title?', 'fl-builder'),
'default' => 'option-1',
'options' => array(
'option-1' => __('Yes', 'fl-builder'),
'option-2' => __('No', 'fl-builder')
)
),
'show_content' => array(
'type' => 'select',
'label' => __('Do You Want to show Post Content?', 'fl-builder'),
'default' => 'option-1',
'options' => array(
'option-1' => __('Yes', 'fl-builder'),
'option-2' => __('No', 'fl-builder')
)
),
'show_link' => array(
'type' => 'select',
'label' => __('Do You Want to show Post Link?', 'fl-builder'),
'default' => 'option-1',
'options' => array(
'option-1' => __('Yes', 'fl-builder'),
'option-2' => __('No', 'fl-builder')
)
),
)
)
)
),
));
现在,frontend.php
中的代码可以获取这些值:
$show_lightbox = $settings->show_lightbox;
$show_lightbox_link = $settings->show_lightbox_link;
$show_title = $settings->show_title;
$show_title_link = $settings->show_title_link;
$show_content = $settings->show_content;
$show_link = $settings->show_link;
如何在custom.php
文件中获取上述值?
答案 0 :(得分:1)
在您自己的模块类中创建一个自定义方法,如下所示:
public function custom_file(){
$settings = $this->settings;
require_once 'includes/custom.php';
}
现在将这个方法调用到enqueue_scripts(),如下所示:
public function enqueue_scripts(){
$this->custom_file();
}
或在你的frontend.php中:
$module->custom_file();
最后创建custom.php然后检查$ settings值以查看它是否正常工作
var_dump($settings);
希望这可以被现代发展标准所接受