【发布时间】:2014-08-03 16:23:11
【问题描述】:
我有一个需要加载的 php 文件来声明一些数组:
主配置文件.php
/* Defined main names, php files and action */
function __construct() {
define( 'TINYMCE_DIR', plugin_dir_path( __FILE__ ) .'tinymce' );
define( 'VISUAL_DIR', plugin_dir_path( __FILE__ ) .'visual' );
include( TINYMCE_DIR . '/shortcodes-config.php' );
require_once( TINYMCE_DIR . '/shortcodes-popup.php' );
require_once( VISUAL_DIR . '/visual.php' );
}
简码-config.php:
$shortcodes['video_section'] = array(
'no_preview' => true,
'params' => 'xxx',
'shortcode' => '[sc1][/sc1]',
'popup_title' => __('Video Section', THEME_NAME),
'shortcode_icon' => __('li_video')
);
$shortcodes['image_section'] = array(
'no_preview' => true,
'params' => 'yyy',
'shortcode' => '[sc2][/sc2]',
'popup_title' => __('Image Section', THEME_NAME),
'shortcode_icon' => __('li_image')
);
然后在其他一些文件中,我需要使用$shortcodes 从数组中获取一些值。
visual.php:
require( TINYMCE_DIR . '/shortcodes-config.php' );// if don't requiered it's no working?
$icon = $shortcodes['video_section']['shortcode_icon'];
$title = $shortcodes['video_section']['popup_title'];
$icon = "<i class='fa ". $icon ."'></i>";
$icon .= "<span class='element-title'>". $title ."</span>";
return $icon;
简码-popup.php:
add_action('wp_ajax_display', 'display_shortcode_list_callback');
function display_shortcode_list_callback() {
require( TINYMCE_DIR . '/shortcodes-config.php' );
$title = $shortcodes['video_section']['popup_title'];
}
我不明白如何正确加载我的 php 文件然后使用我的数组值。 事实上,如果我多次加载我的 shortcodes-config.php,它就无法正常工作......
我只能使用 file1 或 file2 使其工作一次。
包含一个 php 文件来声明某个变量而不是在之后获取它的正确方法是什么?
【问题讨论】:
-
你为什么会多次加载它
-
因为之后我无法再访问它了...我认为这是因为我在 ajax 中使用过一次,然后在正常情况下再次使用它...
-
你需要调试这个添加
ini_set('display_errors', 1);和error_reporting(E_ALL);到你的文件