Code snippets? Why?
WP Customer Area has many options that you can set in the settings panel. But this does not end here! We have many filters and WordPress actions (available in Customer Area -> Status -> Hooks and Filters
), which allow you to use code snippets, customize or change the behaviour of your favourite plugin!
The list of hooks and filters will give you a good overview of the elements on which you can act directly. Otherwise, you can check out our page of code snippets examples.
The code snippets allow us not to overload the options pages while leaving you the possibility of modifying some features. This documentation will explain where to insert these code snippets for the purpose of making them functional.
How do we use it?
Some code snippets will work if they are inserted into your theme’s functions.php
file, but some others will have no effect because the filters or actions could have already been executed when your theme has been loaded.
We, therefore, recommend in any case to insert these code snippets into a plugin. To do this, follow the steps below:
- Create a folder named
wpca-custom-tweaks
into theplugins
folder of your WordPress installation. - In this folder, create a file named
wpca-custom-tweaks.plugin.php
and insert the code shown below.
Note: the filename does not matter.
Warning: If you choose another Plugin Name, make sure to choose one that would start by WPCA to make it listed after the WP Customer Area plugin and its add-on on your site plugins page. This is because you will need the WP Customer Area plugins and their PHP classes to be already executed if you want to access some of them.<?php /* Plugin Name: WPCA Custom Tweaks Plugin URI: Description: Just an example of a simple WP plugin that can be use to add code snippets for WP Customer Area Version: 1.0.0 Author: Thomas Lartaud Author URI: https://wp-customerarea.com License: GPL2 License URI: https://www.gnu.org/licenses/gpl-2.0.html */ defined('ABSPATH') or die('Nope, not accessing this'); /** * Code snippet example * Remove the description field from the profile page * * @see https://wp-customerarea.com/code-snippets/ for more snippet examples * * @param $fields array Profile fields * * @return mixed array Modified profile fields */ function remove_some_profile_fields( $fields ) { unset($fields[ 'description' ]); return $fields; } add_filter('cuar/core/user-profile/get_profile_fields', 'remove_some_profile_fields');
- Save the file and activate the WPCA Custom Tweaks extension.
- Check that the code fragment attached to this plugin works. Here, the plugin already includes a sample code snippet that has the effect of deleting the “Biography” field on the “My Account” and “Account Details” pages of WP Customer Area.
- You are now ready to add your own code snippets! Delete the
code snippet example
function and its filter, and add yours!
Have fun!