title: Passing arguments externally for a function in a PHP class
body: <p>I am trying to recycle the custom post type wordpress function and add_action hook. However I keep getting missing arguments for my function "cpt_function_name". At the bottom of this code I try to pass the arguments I need to pass into the class when instantiated. Help?</p>
  
  <pre><code>class classCPT
  {
    public $singular;
    public $plural;
    public $cpt_name;
    public $cpt_icon;
  
    public function __construct() {
      add_action( 'admin_init', array( $this, cpt_function_name ) );
    }
  
    public function cpt_function_name( $singular, $plural, $cpt_name, $cpt_icon ) {
  
      $labels = array(
          'name'                          =&gt; $plural,
          'singular_name'             =&gt; $singular,
          'add_name'                    =&gt; 'Add New',
          'add_new_item'              =&gt; 'Add New ' . $singular,
          'edit'                          =&gt; 'Edit',
          'edit_item'                   =&gt; 'Edit ' . $singular,
          'new_item'                    =&gt; 'New ' . $singular,
          'view'                          =&gt; 'View ' . $singular,
          'view_item'                   =&gt; 'View ' . $singular,
          'search_term'               =&gt; 'Search ' . $singular,
          'parent'                        =&gt; 'Parent ' . $singular,
          'not_found'                   =&gt; 'No ' . $plural . ' found',
          'not_found_in_trash'      =&gt; 'No ' . $plural . ' in Trash',
      );
  
      $args = array(
          'labels'                =&gt; $labels,
          'public'                        =&gt; true,
          'publicly_queryable'      =&gt; true, //part of WP query
          'exclude_from_search'     =&gt; false,
          'show_in_nav_menus'       =&gt; true,
          'show_ui'                       =&gt; true,
          'show_in_menu'              =&gt; true,
          'show_in_admin_bar'       =&gt; true,
          'menu_position'             =&gt; 20,
          'menu_icon'                   =&gt; $cpt_icon,
          'can_export'                  =&gt; true,
          'delete_with_user'        =&gt; false,
          'hierarchical'              =&gt; false,
          'has_archive'                 =&gt; true,
          'query_var'                   =&gt; true,
          'capability_type'           =&gt; 'post',
          'map_meta_cap'              =&gt; true,
        'taxonomies'            =&gt; array( '' ),
          'rewrite'                       =&gt;array( 'slug' =&gt; $cpt_name, 'with_front' =&gt; true, 'pages' =&gt; true, 'feeds' =&gt; true, ),
          'supports'                   =&gt;array( 'title', 'editor', 'thumbnail', ),
      );
  
      register_post_type( $cpt_name , $args);
    }
  
  }
  
  $newCPT = new classCPT( 'Safari', 'Safaris', 'safaris', 'dashicons-palmtree' );
  </code></pre>