0

I have a php file that I need to load in order to declare some array:

main conf-file.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' );   
}

shortcodes-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')
);

Then in some other files I need to use $shortcodes to get some values from array.

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;

shortcodes-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'];
}

I don't understand how to correctly load my php file then to use my array value after. In fact If I load my shortcodes-config.php more than one time it's not working...

I can make it works only one times with file1 or file2.

What is the correct way to include a php file to declare some variable than to get it after?

3
  • wy do you load it more than once Commented Aug 3, 2014 at 16:30
  • Because I can't access to it any more after... I think it's because I use it once in ajax then another time normaly... Commented Aug 3, 2014 at 16:33
  • You need to debug this add ini_set('display_errors', 1); and error_reporting(E_ALL); to your file Commented Aug 3, 2014 at 16:35

1 Answer 1

1

Because you have initialy used require_once in main conf-file.php you are not allowed to require it again:

require_once( TINYMCE_DIR . '/shortcodes-popup.php' );

Solution is to use require or include

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.