Title: Spanning Class Across Files?
Last modified: August 30, 2016

---

# Spanning Class Across Files?

 *  [Dave Mackey](https://wordpress.org/support/users/davidshq/)
 * (@davidshq)
 * [11 years ago](https://wordpress.org/support/topic/spanning-class-across-files/)
 * I’m developing a plugin. I started out with one PHP file (my-plugin.php) containing
   all the code, but it is becoming unwieldy so I moved various functions into other
   files (my-post-types.php and my-metaboxes.php).
 * Now I’m using require_once to include the files in my main PHP file but I’d like
   for these functions to still be within the main class (MyClass) used in my original
   PHP file (my-plugin.php).
 * I assumed at first that they would be, but don’t think this is true b/c when 
   I moved them into separate files I began getting errors regarding the way I’d
   setup add_action. Specifically, before when everything was in one file I had 
   the following:
 * `add_action( 'init', array( $this, 'register_custom_post_type_series' );`
 * And this was necessary in order for the add_action to operate within the class.
   But after I moved them into their own files I had to treat them as if they were
   outside of the class in my add_action, like so:
 * `add_action( 'init', 'register_custom_post_type_series' );`
 * If I shouldn’t be using a single class here, I’m open to hearing about that too…
   or being directed to articles which help explain how I should be doing this. 
   Any help is appreciated!
 * Thanks,
    Dave

The topic ‘Spanning Class Across Files?’ is closed to new replies.

## Tags

 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [oop](https://wordpress.org/support/topic-tag/oop/)

 * 0 replies
 * 1 participant
 * Last reply from: [Dave Mackey](https://wordpress.org/support/users/davidshq/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/spanning-class-across-files/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
