Extending Uni CPO

It is possible to extend Uni CPO plugin by adding new options and settings. This article includes the related information and guides.

Adding new options

New option must be a class that follow specific naming convention and extends abstract 'Uni_Cpo_Option' class and implements the same interface as other option related classes. The easiest solution would be to make a copy of one of the existing classes and modify it according to your needs.

The naming convention examples:

  • if option type is 'fantasy_option' then its class must be called 'Uni_Cpo_Option_Fantasy_Option'

  • if option type is 'radio_special_links' then its class must be called 'Uni_Cpo_Option_Radio_Special_Links'

Filters

uni_cpo_option_types

This filter accepts one argument - an array of unique option names.

Example of using:

add_filter( 'uni_cpo_option_types', 'my_option_types', 10, 1 )
function my_option_types($types) {
        $types[] = 'fantasy_option';
        return $types;
}

------------------------

uni_cpo_option_classes / uni_cpo_option_classes_pro

This filter accepts one argument - an array of paths to php file with class of the option. The filter prefixed with 'pro' will be used only in PRO version of the plugin.

Example of using:

add_filter( 'uni_cpo_option_classes', 'my_option_classes', 10, 1 )
function my_option_classes($pathes) {
        $pathes[] = $this->plugin_path() . '/inc/class-uni-cpo-option-fantasy-option.php';
        return $pathes;
}

Adding new settings

Similar to new option class name, setting class name follows the same naming convention and extends one of the abstract classes. The easiest way would be to make a copy of existing setting class and then modify it.

Filters

uni_cpo_setting_types

This filter accepts one argument - an array of unique setting names.

Example of using:

add_filter( 'uni_cpo_setting_types', 'my_settings_types', 10, 1 )
function my_settings_types($types) {
        $types[] = 'super_setting';
        return $types;
}

------------------------

uni_cpo_settings_classes / uni_cpo_settings_classes_pro

This filter accepts one argument - an array of paths to php file with class of the setting. The filter prefixed with 'pro' will be used only in PRO version of the plugin.

Example of using:

add_filter( 'uni_cpo_settings_classes', 'my_settings_classes', 10, 1 )
function my_settings_classes($pathes) {
        $pathes[] = $this->plugin_path() . '/inc/class-uni-cpo-setting-super-setting.php';
        return $pathes;
}

Last updated