Add Shortcodes Actions And Filters

Description

Add PHP Code to create your own Shortcodes, Actions and Filters.

Can import your shortcodes from Shortcode Exec PHP plugin (which is no longer supported).

Provides a place to add your code that is more convenient than putting it in your theme’s functions.php file.

Add your code in the Dashboard -> Tools -> Shortcodes, Actions and Filters
but this is only available to users with Administrator role.

Why this plugin?
Existing WordPress documentation suggests adding your own shortcodes, action and filters in the theme’s functions.php file.
This is not a good idea because:

  • If you upgrade your theme, this file can be overwritten and
  • if you change your theme then you need to add the same code to that theme as well.

Your code additions should not have to be artificially tied to your theme. This plugin frees you from that constraint.

Screenshots

  • Dashboard page for code listings
  • Dashboard page for editing a shortcode
  • Dashboard page for editing a filter
  • Dashboard page for editing an action
  • Dashboard page for import/export to/from file and import from Shortcode Exec PHP

Installation

  1. From the Dashboard:
  2. Plugins
  3. Add New
  4. Search “Add Shortcodes, Actions And Filters”
  5. Install Now
  6. Activate
  7. Go to Tools -> Shortcodes, Actions And Filters

FAQ

What happens when there is a syntax or other fatal error in one of my code items?

Typically you will see an error message on the page that is trying to execute the code.
The error will contain a link to edit the problem code item. It will look like this:

Shortcodes, Actions and Filters Plugin: Error in user-provided code item named “My Action”. Fix the code here

There are two cases where this plugin will not execute code.

  1. On this plugin’s own dashboard pages for displaying and editing code. This is so that you can always get back to the
    page to edit code despite any error in your code.
  2. On login/logout page (which is the same page) except when the “Allow Execution of Actions and Filters on Login/Logout pages”
    option is set to “true”.

You will not see any errors on this plugin’s dashboard pages for editing and listing the code. Therefore, you should
open a different page on your site where you can see the results (or errors) of your code execution.

By default, no code that you put in this plugin will run on login/logout pages.
This is to prevent the situation where your code causes a fatal error
that prevents you from being able to login to fix the problem. Consequently, any action or filters that you want run on
login/logout pages will not be run. However you can override this setting on the plugin’s Options page by setting
“Allow Execution of Actions and Filters on Login/Logout pages” to “true”. Do so at your own risk! Any code that you want
executed on login/logout pages should have “Execute also on Dashboard Pages” checked.

In certain cases, an error may cause you to be unable to access any pages your site, including dashboard pages.
However, you will be able to access this plugin’s dashboard pages so that you can edit or delete the problem code.
Enter the URL to the plugin’s dashboard page directly into your browser:

http://YOUR-SITE/wp-admin/admin.php?page=ShortcodesActionsFilters

Only administrator users (manage_options role) can access that page and edit code.

Worst-case scenario: if somehow your site is completely inaccessible, you can disable your code in via the database.
This can happen if you enabled the setting to run code on the login page and that code creates a fatal error. To recover,
find the wp_addactionsandfilters_plugin_usercode table. If you know the code item that is causing the problem, then set
its “enabled” value to 0.

Alternately, disable the problem code using the following query if you know the code’s ID number.
If the ID is 5, then you would execute:
UPDATE wp_addactionsandfilters_plugin_usercode SET enabled = 0 WHERE id = 5

Alternately, disable all code using the following query:
UPDATE wp_addactionsandfilters_plugin_usercode SET enabled = 0

What order are the code elements executed in?

They are executed in order by ID number, lowest to highest. Shortcode are registered but not executed until the
shortcode appears on a page.

Action and filter code can depend on code from a code item with a lower ID number. For example, if code item with
ID=1 defines a function, then all code items with ID>1 have the function defined. But if you deactivate
the code with ID=1, then active code items that depend on it will fail.

Why doesn’t my action code execute on login/logout pages?

The plugin will not execute code on these pages because an error in your code could cause you to be unable to log into
your site to fix the error. However, as stated above, you can override this setting (do so at your own risk!)

When I save the code, I get a 403 Forbidden error

You are probably using WordFence plugin and you must add this plugin to the whitelist.

Reviews

Love it!

I have been using this plugin and it has been working great so far.

Helped me add a necessary code tweak and maintain it even with my limited php knowledge.

Thanks to the developers for making this available and keeping it up to date!

I don't always leave reviews…

But when I do, it’s because it deserves 5-stars.

Hat’s off to the gentleman that originally wrote this plugin and had so many ignorant people discourage his continuation of supporting it… GLASS UP to the gentleman that took it over and made it even better. I love this so much. Nothing like a quick dirty way to write your own micro-plugins for, like… anything. It’s really great. Thanks.

Great Plugin

This is an excellent plugin. I’ve been wanting this functionality for a while and was putting off doing it myself and I’m glad I did.

I found it intuitive to use with a clean layout, makes it easy to dynamically add shortcodes, and filter/action hook right in the WP Admin.

Thanks!

Read all 18 reviews

Contributors & Developers

“Add Shortcodes Actions And Filters” is open source software. The following people have contributed to this plugin.

Contributors

“Add Shortcodes Actions And Filters” has been translated into 1 locale. Thank you to the translators for their contributions.

Translate “Add Shortcodes Actions And Filters” into your language.

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.

Changelog

2.0.9

  • Bug Fix: Was incorrectly stripping slashes from Short Code Exec PHP code on import.

2.0.8

  • Bug Fix: Code Editor now usable on RTL language sites. Forced code section to be LTR.

2.0.7

  • Bug Fix: Displaying code editor that had textarea tag in the code element it failed to display properly

2.0.6

  • Bug Fix: Import file operation was stripping out backslashes out of code

2.0.5

  • Minor performance improvement to options handling

2.0.4

  • Improved error handling/reporting for PHP 7+

2.0.3

  • Introduced option to permit code execution on login/logout pages
  • Minor improvement to error messages
  • Fix for minor issue on edit page when using PHP 7.0.

2.0.1

  • Fix for scenario where bad code is executing on admin pages that could cause the user to be unable to login to fix it.

2.0

  • Significant upgrade!
  • Re-designed administration panel allows you to separate out your code, and activate/deactivate them individually
  • Now can create shortcodes similar to (the no longer supported) PHP Shortcode Exec plugin
  • Can import your shortcodes from PHP Shortcode Exec plugin
  • Supports multisite

1.3

  • More graceful handling of PHP FATAL Errors introduced by user’s code

1.2

  • Fixed debug error message on admin page

1.1

  • Limiting access to only Administrators to avoid possible security exploit

1.0

  • Initial Revision