functions-llms-blocks.php 1.6 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
<?php
/**
 * Serverside block compononent registration
 *
 * @package  LifterLMS_Blocks/Functions
 * @since    1.3.0
 * @version  1.3.3
 */

defined( 'ABSPATH' ) || exit;

/**
 * Determine if the Classic Editor is enabled for a given post.
 *
 * @param   mixed $post WP_Post or WP_Post ID.
 * @return  boolean
 * @since   1.3.0
 * @version 1.3.3
 */
function llms_blocks_is_classic_enabled_for_post( $post ) {

	$ret = false;

	if ( class_exists( 'Classic_Editor' ) ) {

		// Users can choose which editor.
		if ( 'allow' === get_option( 'classic-editor-allow-users', 'disallow' ) ) {

			// check the postmeta to determine which editor we're using.
			$post = get_post( $post );
			if ( $post ) {
				$ret = ( 'classic-editor' === get_post_meta( $post->ID, 'classic-editor-remember', true ) );
			}

			// Uses same editor for all posts.
		} else {

			$ret = ( 'classic' === get_option( 'classic-editor-replace', 'classic' ) );

		}
	}

	return apply_filters( 'llms_blocks_is_classic_enabled_for_post', $ret, $post );

}

/**
 * Determine if a post is migrated
 *
 * @param   mixed $post WP_Post or WP_Post ID.
 * @return  boolean
 * @since   1.3.1
 * @version 1.3.1
 */
function llms_blocks_is_post_migrated( $post ) {

	$post_id = null;
	$ret     = false;

	$post = get_post( $post );
	if ( $post ) {

		$post_id = $post->ID;

		// Classic editor is being used for this post.
		if ( llms_blocks_is_classic_enabled_for_post( $post_id ) ) {
			$ret = false;
		} else {
			$ret = llms_parse_bool( get_post_meta( $post_id, '_llms_blocks_migrated', true ) );
		}
	}

	return apply_filters( 'llms_blocks_is_post_migrated', $ret, $post_id );

}