Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maxsherlock/9866a68ece71a9617f0df8b16d8c7404 to your computer and use it in GitHub Desktop.
Save maxsherlock/9866a68ece71a9617f0df8b16d8c7404 to your computer and use it in GitHub Desktop.
For a WP plugin I've been developing I needed to change a plugin's value in functions.php (I'm thinking along the lines of a child theme), opposed to hard coding the actual plugin, to try and avoid issues on future updates. I just did it for an online dating company's gallery, which also increased load time speed.

Welcome!

So I'm focusing on the apply_filters method instead of changing core plugin code, this is what I did for the dating site's plugin.

// I use apply_filters() to allow a general override of values... public static function loop_shop_per_page() { $value = get_option( 'posts_per_page' ); return apply_filters('filter_loop_shop_per_page', $value); } Then, in WP functions.php (in the child theme), I'm able to select the value on for that by adding the necessary filter:

add_filter('filter_loop_shop_per_page', 'mytheme_loop_shop_per_page');

function mytheme_loop_shop_per_page($value){ return -1; }

===

Some examples of this in action:

In this case, setting the plugin's value globally, I could have also updated the database value for the plugin galley with update_option('images_per_page', -1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment