| 1 |
<?php |
| 2 |
/** |
| 3 |
* Cooked Elementor Support |
| 4 |
* |
| 5 |
* @package Cooked |
| 6 |
* @subpackage ELementor Support |
| 7 |
* @since 1.5.3 |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly |
| 11 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 12 |
|
| 13 |
/** |
| 14 |
* Cooked_Elementor Class |
| 15 |
* |
| 16 |
* This class handles Elementor support. |
| 17 |
* |
| 18 |
* @since 1.5.3 |
| 19 |
*/ |
| 20 |
class Cooked_Elementor { |
| 21 |
|
| 22 |
public function __construct() { |
| 23 |
add_action( 'plugins_loaded', [&$this, 'init'] ); |
| 24 |
} |
| 25 |
|
| 26 |
public function init() { |
| 27 |
// Check if Elementor installed and activated |
| 28 |
if ( did_action( 'elementor/loaded' ) ) { |
| 29 |
add_filter( 'cooked_recipe_content_filter', [&$this, 'elementor_filter'], 15, 4 ); |
| 30 |
add_filter( 'cooked_should_update_post_content', [&$this, 'should_update_content'], 10, 2 ); |
| 31 |
// Deprecated. Now handled in pre_do_shortcode_tag filter in class.cooked-shortcodes.php. |
| 32 |
// add_action( 'elementor/element/before_section_start', [&$this, 'elementor_is_editing'], 10, 3 ); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
// Load the recipe_settings when needed so we can display shortcode content in the editor. |
| 37 |
/* public function elementor_is_editing( $element, $section_id, $args ) { |
| 38 |
$post_id = get_the_ID(); |
| 39 |
|
| 40 |
if ( !isset($recipe_settings) || isset($recipe_settings) && !isset($recipe_settings['author']) ) { |
| 41 |
if ( get_post_type( $post_id ) === 'cp_recipe' ) { |
| 42 |
global $recipe_settings; |
| 43 |
$recipe_settings = Cooked_Recipes::get_settings( $post_id ); |
| 44 |
} else { |
| 45 |
// We are in the editor but not on a recipe post type. Maybe a single recipe template? |
| 46 |
// Uses the first recipe found in the database as a sample. |
| 47 |
$recipe_settings = Cooked_Recipes::get( false, true ); |
| 48 |
} |
| 49 |
} |
| 50 |
} */ |
| 51 |
|
| 52 |
public function elementor_filter( $recipe_content, $og_content, $recipe_id, $layout_content = null ) { |
| 53 |
$elementor_page = get_post_meta( $recipe_id, '_elementor_edit_mode', true ); |
| 54 |
|
| 55 |
if ( $elementor_page ) { |
| 56 |
$og_content = (string) $og_content; |
| 57 |
if ( Cooked_Recipes::recipe_has_fullscreen( $recipe_id, $layout_content ) ) { |
| 58 |
global $recipe_settings; |
| 59 |
$og_content .= Cooked_Recipes::get_fsm_markup( $recipe_id, $recipe_settings ); |
| 60 |
} |
| 61 |
return $og_content; |
| 62 |
} |
| 63 |
|
| 64 |
return $recipe_content; |
| 65 |
} |
| 66 |
|
| 67 |
public function should_update_content( $should_update, $recipe_id ) { |
| 68 |
$elementor_page = get_post_meta( $recipe_id, '_elementor_edit_mode', true ); |
| 69 |
|
| 70 |
if ( $elementor_page ) { |
| 71 |
return false; |
| 72 |
} |
| 73 |
|
| 74 |
return $should_update; |
| 75 |
} |
| 76 |
|
| 77 |
} |
| 78 |
|