title: Dynamic function name in php
body: <p>I would like to simplify the creation of "Custom Post Types" in WordPress as it is tedious to go through the same script and change all the custom post type name instances manually over and over.</p>
  
  <p>It's quite simple to achieve by creating a variable containing the CPT name and use it everywhere it is needed. This way, All I have to do is declare the variable in the beginning of the script and that should take care of the rest.</p>
  
  <p>The only issue is that, to make it work, I also need to prefix the CPT name in front of every function inside the script and it seems that using a variable in a function name is not easy or even recommended in PHP.</p>
  
  <p>So how could I solve this?</p>
  
  <p>Here is an example below to make it clear:</p>
  
  <pre><code>$prefix = 'news';
  
  function news_custom_type_init()
  {
      global $prefix;
  
      register_post_type($prefix, array(
      'labels' =&gt; array(
            'name' =&gt; $prefix,
            'singular_label' =&gt; $prefix,
            'add_new' =&gt; 'Add',
            ...
          ));
  
          register_taxonomy_for_object_type( 'category', $prefix );
  }
  add_action('init', $prefix.'_custom_type_init');
  </code></pre>
  
  <p>This is almost fine and could be standardized if only I could dynamically rename the function in order not to have to write the word "news" in front of it but use the "$prefix" instead.</p>
  
  <p>This could have been nice but just doesn't work:</p>
  
  <pre><code>$prefix = 'news';
  
  $functionName= $prefix."_custom_type_init";
  
  function $functionName()
  {
      global $prefix;
  
      register_post_type($prefix, array(
      'labels' =&gt; array(
            'name' =&gt; $prefix,
            'singular_label' =&gt; $prefix,
            'add_new' =&gt; 'Add',
            ...
          ));
  
          register_taxonomy_for_object_type( 'category', $prefix );
  }
  add_action('init', $prefix.'_custom_type_init');
  </code></pre>
  
  <p>Having to name manually the function kinda defeat the original purpose of my attempt (especially when the script embeds dozens of functions like this one).</p>
  
  <p>What would be the best way to do this?</p>
  
  <p>PS: I googled and "stackoverflowed" a lot about this but didn't find any working solution that fit my needs and doesn't generate a WordPress error message.</p>
  
  <p>Thank you.</p>