Skip to content

Instantly share code, notes, and snippets.

@helgatheviking
Created May 9, 2020 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helgatheviking/69fb48e6edbeb22e37e2742579cb59cf to your computer and use it in GitHub Desktop.
Save helgatheviking/69fb48e6edbeb22e37e2742579cb59cf to your computer and use it in GitHub Desktop.
Custom themer module
<?php
/**
* @package KIA Subtitle
* @category Compatibility Class
* @version 3.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class KIA_Subtitle_BB {
/**
* Boot up Beaver Builder compat.
* @access public
* @return KIA_Subtitle
* @since 1.0
*/
public static function init() {
// Add Beaver Builder Module.
add_action( 'wp', array( __CLASS__, 'register_bb_module' ) );
add_action( 'fl_page_data_add_properties', array( __CLASS__, 'add_bb_property' ) );
}
/*-----------------------------------------------------------------------------------*/
/* Block Editor Functions */
/*-----------------------------------------------------------------------------------*/
/**
* Register a custom module for Beaver Builder
*
* @since 3.1
* @return null
*/
public static function register_bb_module() {
if ( class_exists( 'FLThemeBuilderLoader' ) ) {
FLThemeBuilderLoader::load_modules( kia_subtitle::get_plugin_path() . '/includes/beaver-builder/' );
}
}
/**
* Add subtitle as a post property
*
* @since 3.1
* @return null
*/
public static function add_bb_property() {
FLPageData::add_post_property( 'kia_subtitle', array(
'label' => __( 'Post Subtitle', 'kia-subtitle' ),
'group' => 'posts',
'type' => 'string',
'getter' => 'get_the_subtitle',
'placeholder' => 'Lorem Ipsum Dolor',
) );
}
} // End class.
KIA_Subtitle_BB::init();
<?php
/**
* Beaver Builder Module
*
* @class KIA_Subtitle_Module
* @package KIA Subtitle/Classes
* @since 3.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Heading module alias for the post subtitle.
*/
FLBuilder::register_module_alias( 'kia-post-subtitle', array(
'module' => 'heading',
'name' => __( 'Post Subtitle', 'kia-subtitle' ),
'description' => __( 'Displays the subtitle for the current post.', 'kia-subtitle' ),
'category' => __( 'Post Modules', 'fl-theme-builder' ),
'enabled' => FLThemeBuilderLayoutData::current_post_is( 'singular' ),
'settings' => array(
'tag' => 'h2',
'connections' => array(
'heading' => (object) array(
'object' => 'post',
'property' => 'kia_subtitle',
'field' => 'text',
),
),
),
) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment