class-llms-blocks-page-builders.php 3.26 KB
Newer Older
cyrille's avatar
cyrille committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
<?php
/**
 * Adds support for page builder plugins..
 *
 * @package  LifterLMS_Blocks/Classes
 * @since    1.2.0
 * @version  1.3.4
 */

defined( 'ABSPATH' ) || exit;

/**
 * LLMS_Blocks_Page_Builders class..
 */
class LLMS_Blocks_Page_Builders {

	/**
	 * Constructor.
	 *
	 * @since    1.2.0
	 * @version  1.2.0
	 */
	public static function init() {

		add_action( 'init', array( __CLASS__, 'add_filters' ) );

	}

	/**
	 * Add filters to support various page builder plugins.
	 *
	 * @return  void
	 * @since   1.2.0
	 * @version 1.3.4
	 */
	public static function add_filters() {

		if ( defined( 'FL_BUILDER_VERSION' ) ) {
			add_filter( 'llms_blocks_is_post_migrated', array( __CLASS__, 'check_for_beaver' ), 15, 2 );
		} elseif ( defined( 'ELEMENTOR_VERSION' ) ) {
			add_filter( 'llms_blocks_is_post_migrated', array( __CLASS__, 'check_for_elementor' ), 15, 2 );
		} elseif ( defined( 'ET_BUILDER_VERSION' ) ) {
			add_filter( 'llms_blocks_is_classic_enabled_for_post', array( __CLASS__, 'check_for_divi_classic' ), 15, 2 );
			add_filter( 'llms_blocks_is_post_migrated', array( __CLASS__, 'check_for_divi' ), 15, 2 );
		}

	}

	/**
	 * Add support for Beaver Builder.
	 * If the builder is enabled for the post LifterLMS should treat the post as not migrated (actions are not removed).
	 *
	 * @param   bool $val default value of the migration status.
	 * @param   int  $post_id WP_Post ID.
	 * @return  bool
	 * @since   1.2.0
	 * @version 1.2.0
	 */
	public static function check_for_beaver( $val, $post_id ) {

		// If Beaver Builder is enabled for the post, don't remove actions.
		if ( FLBuilderModel::is_builder_enabled( $post_id ) ) {
			$val = false;
		}

		return $val;

	}

	/**
	 * Add support for Beaver Builder.
	 * If the builder is enabled for the post LifterLMS should treat the post as not migrated (actions are not removed).
	 *
	 * @param   bool $val default value of the migration status.
	 * @param   int  $post_id WP_Post ID.
	 * @return  bool
	 * @since   1.2.0
	 * @version 1.2.0
	 */
	public static function check_for_elementor( $val, $post_id ) {

		// If Elementor builder is enabled for the post, don't remove actions.
		if ( 'builder' === get_post_meta( $post_id, '_elementor_edit_mode', true ) ) {
			$val = false;
		}

		return $val;

	}

	/**
	 * Add support for Divi (ET) Builder.
	 * If the builder is enabled for the post LifterLMS should treat the post as not migrated (actions are not removed).
	 *
	 * @param   bool $val default value of the migration status.
	 * @param   int  $post_id WP_Post ID.
	 * @return  bool
	 * @since   1.2.0
	 * @version 1.2.0
	 */
	public static function check_for_divi( $val, $post_id ) {

		// If Divi builder is enabled for the post, don't remove actions.
		if ( 'on' === get_post_meta( $post_id, '_et_pb_use_builder', true ) ) {
			$val = false;
		}

		return $val;

	}

	/**
	 * If the Divi "Enable Classic Editor" builder setting is enabled then classic is enabled for our purposes.
	 *
	 * @param   bool  $val  default value.
	 * @param   mixed $post WP_Post or WP_Post ID.
	 * @return  bool
	 * @since   1.3.4
	 * @version 1.3.4
	 */
	public static function check_for_divi_classic( $val, $post ) {

		if ( 'on' === et_get_option( 'et_enable_classic_editor', 'off' ) ) {
			$val = true;
		}

		return $val;

	}

}

return LLMS_Blocks_Page_Builders::init();