Creating New Dynamic Datapoints In Oxygen

If you’ve ever wanted to create your Dynamic Datapoint in Oxygen, it’s really simple. Oxygen has a built-in filter called oxygen_custom_dynamic_data that you can utilize:

add_filter( 'oxygen_custom_dynamic_data', 'name_of_your_function', 10, 1 );

It is through this filter that we can register new dynamic datapoints to be used in Oxygen.

Understanding the Filter Settings:

To use the oxygen_custom_dynamic_data filter, you’ll need a function that has some of the following information:

  • $properties variable (optional)
  • $field_data: This provides details on what the dynamic datapoint is called and where it is shown in Oxygen.
    • name: The Name of the datapoint field, you can add translation support as needed.
    • mode: What type of data the field will return. Available modes are: content, custom-field, link, image.
    • position: Where the datapoint field shows up in dynamic data options. Default options are Post, Author, User, Featured Image, Current User, Archive, Blog Info
    • data: The slug/id of the dynamic datapoint.
    • handler: The function that determines what content is returned from the datapoint.
    • properties: Any additional properties regarding field data.
  • $dynamc_data[]: returns the field data into Oxygen’s dynamic data

Basic Dynamic Datapoint Example

You can see a basic example of all these in action here:

<?php

add_filter( 'oxygen_custom_dynamic_data', 'lx_dynamic_data_function', 10, 1 );


function lx_dynamic_data_function( $dynamic_data ) {
 global $post;

 $properties = '';

 $field_data = array(
  'name' => __( 'New Dynamic Field', 'oxygen-custom' ),
  // Name of the field as it displays in Oxygen
  'mode' => 'content',
  // Available modes: 'content', 'custom-field', 'link' and 'image'
  'position' => 'Post',
  // Available positions: 'Post', 'Author', 'User', 'Featured Image', 'Current User', 'Archive' 'Blog Info'
  'data' => 'field_name',
  // Slug of the field in Oxygen, will render as 'custom_field_name
  'handler' => 'lx_dynamic_data_content',
  // Must be a function callback
  'properties' => $properties
 );
 $dynamic_data[] = $field_data;
 // Add the field to Dynamic Data

 return $dynamic_data;
}

function lx_dynamic_data_content($atts) {
 return 'success';
 // Add additional functionality for populating the results here. 
}
?>

This example adds a new dynamic datapoint to Oxygen for content-based fields under the Post position called “New Dynamic Field”, and runs a function that returns the text “success”. It’s a basic example, but it is useful in understanding how to make this filter work.

More ExaMPLES of Dynamic Datapoints

Another example of how to use this filter is to add ACF data for archive fields since Oxygen’s built-in ACF integration only works for singular post types.

A screenshot that shows where the ACF Archive Field Dynamic Datapoint shows up in Oxygen's Dynamic Data Popup

You can access this code for this dynamic datapoint here with the ACF Archive Dynamic Data CodeBitt.

A second example would be adding datapoints for WooCommerce Product Category information to be used on an archive field. This CodeBitt allows you to display the Product Category image on an archive page.

This datapoint uses the image mode and only works with the Image URL for the Image field. Unfortunately, it doesn’t work with the Media Library option (at this time). You can see the complete code for this datapoint with the Product Category Dynamic Datapoint CodeBitt.

A screenshot showing where to select the Product Category Image dynamic datapoint in Oxygen's Dynamic Data popup

These are two more useful examples of how to use the oxygen_custom_dynamic_data filter, and you can use this to add as many additional datapoints as you wish.

Advanced Examples of Dynamic Datapoints

Now, there are more advanced things you can do to add more dynamic datapoints, and some of the best examples can be seen in the code Oxygen uses to integrate ACF, Meta Box, and Toolset. You can find those examples within Oxygen’s code:

  • /oxygen/component-framework/includes/acf/oxygen-acf-integration.php
  • /oxygen/component-framework/includes/metabox/oxygen-metabox-integration.php
  • /oxygen/component-framework/includes/toolset/oxygen-toolset.php

These are the most advanced examples that we are aware of at this time, aside from the integrations for Oxygen that were created by Pods and ACPT.

The main caveat we’ve found so far is that it isn’t possible to add new dynamic datapoints for Galleries and Repeaters as those are more manually coded within Oxygen’s core files, and they aren’t as easy to add new datapoints. This isn’t to say it isn’t possible, just we haven’t found a way yet.

Hails and Resources:

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    © 2020-2024 Luxibay
    Name(Required)
    Please let us know what's on your mind. Have a question for us? Ask away.
    This field is for validation purposes and should be left unchanged.