title: WordPress: Why Can't get_terms() See Custom Taxonomy Registered inside Class?
body: <h1>Background</h1>
  <p>I register a custom post type and custom taxonomy inside a class. Inside the WP admin, I see both the post type, and I see the taxonomy.</p>
  <h3>Simplified Code:</h3>
  <pre><code>class Custom_Post_Type {
  
      function __construct($init_data) {
  
          if ( is_admin() ) {
  
              add_action( 'init', array( $this, 'create_ctp' ) );
              add_action( 'admin_head', array( $this, 'create_ctp_icons' ) );
              add_action( 'save_post', array( $this, 'save_ctp_custom_metadata' ), 1, 2 );
  
          }
  
      }
  
      function create_ctp_taxonomy() {
              register_taxonomy(
                  $post_type.'_type',
                  $post_type,
                  array(
                      'labels' =&gt; array(
                          'name' =&gt; $taxonomy_label,
                          'add_new_item' =&gt; 'Add New '.$taxonomy_label
                      ),
                      'public' =&gt; true,
                      'show_ui' =&gt; true,
                      'show_tagcloud' =&gt; true,
                      'hierarchical' =&gt; true,
                      'show_in_nav_menus' =&gt; true,
                      'show_admin_column' =&gt; true
                  )
              );
  
              register_post_type($post_type_slug,
                  array(
                      'labels' =&gt; array(),
                      'public' =&gt; true,
                      'has_archive' =&gt; false,
                      'supports' =&gt; $this-&gt;supports,
                      'register_meta_box_cb' =&gt; array( $this, 'create_ctp_custom_metaboxes' ),
                      'taxonomies' =&gt; array( $taxonomy_slug ),
                  )
              );
      }
  
  }
  </code></pre>
  <p>Again, this works inside the admin area. I can add posts, and I can see the taxonomy and add terms.</p>
  <hr />
  <h1>Problem</h1>
  <p>On the front end, <code>get_taxonomies()</code> doesn't see the new custom taxonomy, and <code>get_terms()</code> doesn't see the terms inside it.</p>
  <p>I tried several examples of of <code>register_taxonomy</code>, and when I used it outside of the class, it appears on the front end. However, when I moved the examples into my internal create_ctp_taxonomy function, they are suddenly invisible to <code>get_taxonomies</code>.</p>
  <p>Any ideas why this would be occurring?</p>
  <hr />
  <h2>Edit</h2>
  <p>I've been playing around with different things and I think the issue here is the timing of the <code>init</code> action. When I call the setup function direction from the <code>__construct</code> function, rather than adding an action, then things start working. Example:</p>
  <pre><code>class Custom_Post_Type {
  
      function __construct($init_data) {
  
          if ( is_admin() ) {
  
              //add_action( 'init', array( $this, 'create_ctp' ) );
              add_action( 'admin_head', array( $this, 'create_ctp_icons' ) );
              add_action( 'save_post', array( $this, 'save_ctp_custom_metadata' ), 1, 2 );
          }
  
          $this-&gt;create_cpt();
  
      }
  
  }
  </code></pre>
  <p>By doing this, I skip using <code>init</code> at all. However, this seems to violate standard practice. Is there a downside that anyone knows of for doing it this way?</p>