Add Settings Pages

Saber Commerce extensions should use the same method that core components use to register settings pages. This is easy enough to do using the filter sacom_setting_page_register. The filter callback provides 1 argument, the array of settings pages.

Using an anonymous function callback the filter usage looks like this:

add_filter( 'sacom_setting_page_register', function( $pages ) {
  // Add page(s) to the array.
}

A more full example below shows how we can create a page object using \stdClass (or stdClass if in a non-namespaced environment). This page object is then added to the array and returned.

add_filter( 'sacom_setting_page_register', function( $pages ) {

  $page = new \stdClass;
  $page->key       = 'tax';
  $page->title     = __( 'Taxes', 'saber-commerce' );
  $page->menuLabel = __( 'Taxes', 'saber-commerce' );

  $pages[] = $page;
  return $pages;

});

The sacom_setting_page_register filter should not be called before the “init” action hook.

In the example above we create only a blank page. The purpose of the setting page of course is to display settings fields that the user can interact with and save. There is a SettingsField class used for this purpose which extends Saber Commerce core Fields and has all of the same functionality.

Below is an example of defining a text field and adding it to our new settings page:

@TODO add example referenced above. SORRY 🙁

Powered by BetterDocs