Attach a private function at a hook?

I have a class with some private & public functions. The thing is that I don’t want some of the functions to be able to be called outsite of the class, so I want to make them private. But I need to hook them at particular hooks and the hooks cannot call them if they are private. Is there some workaround for that?

Solutions Collecting From Web of "Attach a private function at a hook?"

No that’s impossible. When WordPress calls a method it has to be public public. You could write a public method that is called on the hook which calls a private method inside.
Not sure if that makes sense though …

Here is an example;

add_action( 'template_redirect', array( 'someClass', 'init' ));

class someClass {

    protected static $content = 'oh yeah, private!';    

    public static function init() {
        $class = __CLASS__;
        new $class;

    private function __construct() {
        add_filter('the_content', array(&$this, 'get_this_function'));

    public static function get_this_function(){
         return self::my_funk_she_on();

    private static function my_funk_she_on(){
        return self::$content;


In this example I am filtering the_content by passing a private function which gets its value from a private variable. Now since you can’t call this directly my get_this_function is what will return what’s private and that’s what I pass into my constructor that adds the appropriate filter upon template_redirect.

You don’t need to use static methods by the way, some recommend against it, but do as you please.