true )
);
}
// Check if Elementor Pro is active
if ( ! did_action( 'elementor/loaded' ) || ! class_exists( 'ElementorPro\Plugin' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die(
esc_html__( 'This plugin requires Elementor Pro to be installed and active.', 'acf-repeater-for-elementor' ),
'Plugin Activation Error',
array( 'back_link' => true )
);
}
}
register_activation_hook( __FILE__, 'symp_conditional_plugin_activation_check' );
// Prevent plugin from running if dependencies are not met
function symp_conditional_plugin_dependency_check() {
if ( ! class_exists( 'ACF' ) || ! function_exists( 'acf_get_setting' ) || ! did_action( 'elementor/loaded' ) || ! class_exists( 'ElementorPro\Plugin' ) ) {
add_action( 'admin_notices', function() {
echo '
This plugin requires ACF Pro and Elementor Pro to be installed and active.
';
} );
deactivate_plugins( plugin_basename( __FILE__ ) );
}
}
add_action( 'admin_init', 'symp_conditional_plugin_dependency_check' );
// Add the ACF Repeater settings to Elementor widgets - use Elementor_ACF_Repeater_Settings class
$symp_arfe_elementor_settings = new Sympl_Elementor_ACF_Field_Settings();
add_action( 'elementor/widgets/register', function( $widgets_manager ) {
require_once __DIR__ . '/widgets/arfe-repeater-carousel.php';
$widgets_manager->register( new \SYMP_Repeater_For_Elementor\Widgets\SYMP_Repeater_Carousel() );
} );
add_action('elementor/frontend/container/before_render', 'symp_arfe_catch_output', 10, 1);
//add_action('elementor/frontend/container/before_render', 'arfe_handle_carousel', 10, 1);
add_action('elementor/frontend/column/before_render', 'symp_arfe_catch_output', 10, 1);
add_action('elementor/frontend/section/before_render', 'symp_arfe_catch_output', 10, 1);
function symp_arfe_catch_output( $section ) {
// Catch output
ob_start();
}
add_action('elementor/frontend/container/after_render', 'sympl_arfe_handle_wrapper', 10, 1);
add_action('elementor/frontend/column/after_render', 'sympl_arfe_handle_wrapper', 10, 1);
add_action('elementor/frontend/section/after_render', 'sympl_arfe_handle_wrapper', 10, 1);
// And then
function sympl_arfe_handle_wrapper( $section ) {
// Collect output
$content = ob_get_clean();
// Alter the output anyway you want, in your case wrapping
// it with a classed div should be something like this
// make sure to echo it
if($repeater_name = arfe_check_if_repeater_class_in_widget($section)) {
echo symp_arfe_prepare_content_by_repeater($content, $repeater_name); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Elementor-rendered HTML captured from the output buffer; repeater values are escaped in symp_arfe_replace_row().
} else {
echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Elementor-rendered HTML captured from the output buffer; repeater values are escaped in symp_arfe_replace_row().
}
}
function symp_arfe_prepare_content_by_repeater($content, $repeater_name) {
$repeater = get_field($repeater_name);
if(!is_array($repeater) || count($repeater) == 0) {
return "";
}
$new_view = '';
foreach($repeater as $row) {
// Process the row to translate values
$row = symp_arfe_process_repeater_row($row);
$single_content = $content;
$single_content = apply_filters('arfe_repeater_row_content', $single_content, $row); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- legacy public hook name kept for backward compatibility.
$new_view = $new_view.''.$single_content;
}
return $new_view;
}
add_action('arfe_repeater_row_content', 'symp_arfe_repeater_row_content_fn', 10, 2);
function symp_arfe_repeater_row_content_fn ($single_content, $row)
{
if (!is_array($row)) {
return $single_content;
}
// Translate string values, then substitute every #placeholder with context-aware escaping.
return symp_arfe_replace_row($single_content, symp_arfe_process_repeater_row($row));
}
/**
* Check if TranslatePress is active
*
* @return bool True if TranslatePress is active, false otherwise
*/
function symp_arfe_is_translatepress_active() {
return function_exists('trp_translate');
}
/**
* Translate text if TranslatePress is active
*
* @param string $text Text to translate
* @return string Translated text or original text if TranslatePress is not active
*/
function symp_arfe_translate_text($text) {
if (symp_arfe_is_translatepress_active()) {
return trp_translate($text, get_locale(), false);
}
return $text;
}
/**
* Process a row of repeater data and translate values
*
* @param array $row The repeater row data
* @return array The processed row with translated values
*/
function symp_arfe_process_repeater_row($row) {
if (!is_array($row)) {
return $row;
}
$processed_row = [];
foreach ($row as $key => $value) {
if (is_string($value)) {
$processed_row[$key] = symp_arfe_translate_text($value);
} else {
$processed_row[$key] = $value;
}
}
return $processed_row;
}
function symp_arfe_replace_content($content, $key, $value) {
// Translate the value if it's a string and TranslatePress is active
if (is_string($value)) {
$value = symp_arfe_translate_text($value);
}
return symp_arfe_replace_row($content, array($key => $value));
}
/**
* Attributes whose value is a URL. Values substituted into these are checked
* for dangerous protocols (javascript:, data:, ...) after substitution.
*
* @return string[]
*/
function symp_arfe_url_attributes() {
$attrs = array('href', 'src', 'action', 'formaction', 'poster', 'cite', 'data', 'xlink:href', 'background', 'longdesc', 'ping', 'codebase', 'manifest');
return (array) apply_filters('symp_arfe_url_attributes', $attrs);
}
/**
* HTML allowed inside repeater values that are placed in text context.
* Defaults to the same list WordPress allows in post content (no