• Hello I seem to have issue well in my plugin it setup post types via config array which is attached via filter

    add_action( 'init', 'headlines_register_post_type');
    function headlines_register_post_type()
    {
    	$post_types = apply_filters( 'headlines_post_types', array() );
    	foreach ( $post_types as $post_type )
    	{
    		new Headlines_Post_Type( $post_type );
    	}
    }

    but as soon as I call my class function for

    add_action( 'init', array( $this, 'register_post_type' ) );

    it stops working but if I change the priory for

    add_action( 'init', 'headlines_register_post_type', 5);

    it works how can I use the default priory ? as I sure this is not good way to code plugins changing the priory as it could conflict other plugins maybe …

    Stephen

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Are you sure it’s the priority? Could it be being called as a class function that is the problem? If your class in instantiated after ‘init’ or if the class function is called after ‘init’, it’s too late to register posts.

    If you add to the ‘init’ action when your plugin loads (well before ‘init’), outside of your class, it shouldn’t matter which priority is used unless there is a name conflict.

    Thread Starter dazzlesoftware

    (@dazzlesoftware)

    well it is a priority issue but I changed the hook to use add_action( ‘plugins_loaded’, ‘headlines_register_taxonomy’);

    then my init calls once framework receives calls too the hook via filter

    here is the files for the current version

    https://github.com/dazzlesoftware/wordpress-headlines

    as I currently adding meta fields support not sure what I doing wrong maybe this is better way not sure….

    Moderator bcworkz

    (@bcworkz)

    ‘plugins_loaded’ fires earlier than ‘init’. What happens in between would determine whether using that action will work or not. They are both in wp-settings.php, see for yourself. Once concern I have related to registering post types is the global rewrite object is not yet created, causing the post type rewrites to possibly not be recorded correctly.

    In the case of the headlines post type, I don’t see why ‘init’ would be a problem. If the default priority 10 fails but 5 works, I’m inclined to believe there is a plugin conflict somewhere already. People don’t normally have any issues registering post types with ‘init’, you seem to be “special” 🙂

    I believe there is a larger problem with adding more user post types by way of a class. Unless the class object is instantiated and the register post type method is called before ‘init’ (or worse, the even earlier ‘plugins_loaded’) it will do no good, since the action you’re adding the callback to has already fired.

    I’m not sure where you’re storing these added user post types. Where ever it is, something needs to get post type data from there and add the register call before the associated action actually fires.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘plugin only works after I change priority’ is closed to new replies.