• Ik heb een thema-child aangemaakt van thema ‘ReadLine’ met het bestand ‘functions.php’:

    <?php
      add_action('wp_enqueue_scripts', 'child_enqueue_styles', 99);
      function child_enqueue_styles(){
        $parent_style = 'parent-style';
        wp_enqueue_style($parent_style,
                         get_template_directory_uri() . '/style.css');
        wp_enqueue_style('child-style',
                         get_stylesheet_directory_uri() . '/style.css',
                         array($parent_style));
      }
      if(get_stylesheet() !== get_template()){
        add_filter('pre_update_option_theme_mods_' . get_stylesheet(),
                   function($value, $old_value){
                     update_option('theme_mods_' . get_template(), $value);
                     return $old_value; // prevent update to child theme mods
                   }, 10, 2
                  );
        add_filter('pre_option_theme_mods_' . get_stylesheet(),
                   function($default){
                     return get_option('theme_mods_' . get_template(), $default);
                   }
                  );
      }
      /*----------------------------- Initialize globald data -------------------*/
      $GLOBALS['bbl_aaa'] = 'xxx';
      $GLOBALS['bbl_bbb'] = 'yyy';
      $GLOBALS['bbl_ccc'] = 'zzz';
      /*----------------------------- Allow web query parameters 'bkc' and 'chp' */
      function add_query_vars_filter($vars){
        $vars[] = 'bkc';
        $vars[] = 'chp';
        return $vars;
      }
      add_filter( 'query_vars', 'add_query_vars_filter' );
      get_query_var('bkc');
      get_query_var('chp');
    ?>
    

    En het ‘XYZ PHP code’-bestand ‘bbl-bkx-001’:

    <?php
    /*=== File 'bbl-bkx-001.php' ===  Create bible book page (part 001) =========*/
    /*------------------------------- Initialize data ---------------------------*/
    echo   'Global data: '
         . $GLOBALS['bbl_aaa']
         . ', '
         . $GLOBALS['bbl-bbb']
         . ' and '
         . $GLOBALS['bbl_ccc'];
    echo '<br>Query argument "bkc": '. get_query_var('bkc');
    echo '<br>Query argument "chp": '. get_query_var('chp');
    echo '<br>';
    ?>

    Maar het werkt niet vanwege:

    Warning: Undefined array key "bbl_aaa" in /...../wordpress/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(100) : eval()'d code on line 6
    .......
    Global data: , and
    Query argument "bkc":
    Query argument "chp": 

    Waar zou ik iets verkeerds gedaan hebben?

  • Het onderwerp ‘$GLOBALS in thema child’ is gesloten voor nieuwe reacties.