Perhaps the company I was writing this for was acquired by a British company and now we want to change our cookies to biscuits, we only need to worry about where users can see the text. But we've inadvertently removed the protection of the function_exists call If another plugin uses the same function name, we might have a collision even though I think I'm protected. If I typo line three, the function_exists check, in my local testing this will probably be fine. I want to highlight a common pain point, strings and typos. Again, we've avoided function in collision and handled collision gracefully if the function already exists. Moving along to our custom taxonomy, it should look really similar to the custom post type registration. In fact, I'd argue that once someone is familiar with the concept of custom post types this is a very simple and readable file, but I should probably still add some comments at some point. Our function is prefixed, cookie_plugin, and we confirm that it doesn't already exist to prevent collision in the not function_exists. Looking at the CPT registration we can immediately see the defensive posture required to work in the global name space. Because we are requiring these files, the PHP interpreter executes them in the order they are included. We are including a few files that are clearly named, indicating their responsibilities. This includes name, description, author, and in this case I'm setting a minimum PHP version of 7.4. Our plugin index file has the required header. It registers a custom post type, adds a custom taxonomy, adds some fields to the custom post type, and maybe a few other features. Before we dive into object-oriented architecture, let's take a moment to review some common patterns and WordPress plugins.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |