PHPackages                             stevegrunwell/one-time-callbacks - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. stevegrunwell/one-time-callbacks

ActiveWordpress-muplugin[Utility &amp; Helpers](/categories/utility)

stevegrunwell/one-time-callbacks
================================

Enable WordPress actions and filter callbacks to be called exactly once.

v1.0.0(8y ago)6847.4k3MITPHPPHP &gt;=5.3

Since Feb 17Pushed 8y ago2 watchersCompare

[ Source](https://github.com/stevegrunwell/one-time-callbacks)[ Packagist](https://packagist.org/packages/stevegrunwell/one-time-callbacks)[ RSS](/packages/stevegrunwell-one-time-callbacks/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

One-Time Callbacks
==================

[](#one-time-callbacks)

[![Build Status](https://camo.githubusercontent.com/1781f8b8021fdea0b872fc145894945153750a676d3dc5058cca57c753e93f7b/68747470733a2f2f7472617669732d63692e6f72672f73746576656772756e77656c6c2f6f6e652d74696d652d63616c6c6261636b732e7376673f6272616e63683d646576656c6f70)](https://travis-ci.org/stevegrunwell/one-time-callbacks)[![Coverage Status](https://camo.githubusercontent.com/8dac586f4726012e1c054b0366822f80b7eaf1e74a767658ee422684226054db/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f73746576656772756e77656c6c2f6f6e652d74696d652d63616c6c6261636b732f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/github/stevegrunwell/one-time-callbacks?branch=develop)[![GitHub release](https://camo.githubusercontent.com/ba600592af65334108624e93a41a5addfae837a3c8511294887f1bbd9832e2b7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f73746576656772756e77656c6c2f6f6e652d74696d652d63616c6c6261636b732e737667)](https://github.com/stevegrunwell/one-time-callbacks/releases)

The [The WordPress plugin API](https://codex.wordpress.org/Plugin_API) is a fantastic way for third-party scripts to be able to inject themselves into the WordPress lifecycle. Thanks to WordPress actions and filters (collectively "hooks"), theme and plugin developers can introduce all sorts of new functionality.

Occasionally, however, the "all or nothing" mentality of WordPress hooks can put developers in a pinch, since they *only* want their callback to run once. For example, maybe your theme has a simple `add_top_story_class()` function, which appends `.top-story` to a list of classes. If you only wanted to apply it to the first post in a loop, you might find yourself writing code like this:

```
