Forum Replies Created

Viewing 28 posts - 1 through 28 (of 28 total)
  • Author
    Posts
  • in reply to: Polylang / Enfold incompatibility inserts custom_class= #1492613

    Thanks Ismael,

    You said that you manually cleaned up the code, so when I added it to the live site, I was seeing the same issues as before.

    I am now just testing the following, which appears to be working, but did break the nav builder when I first ran it, so filtered this so it would only work on pages and posts.

    I will update as to if it works fully.

    Thanks

    
    /**
     * ============================================================================
     * POLYLANG + ENFOLD CUSTOM_CLASS ISSUE FIXES
     * ============================================================================
     * 
     * Problem: When Polylang duplicates/translates pages, it incorrectly converts
     * custom_class attributes into id="custom_class" or id="custom_class=" in HTML output.
     * 
     * Solution: Multiple filters at different points in the translation/save process
     * to catch and fix the issue wherever it occurs.
     */
    
    /**
     * Solution 1: Fix content after Polylang processes it (Primary Fix)
     * This runs after Polylang has translated the content but before it's saved
     * 
     * CRITICAL FIX: Handles unclosed custom_class=' attributes that break Enfold's parser
     * IMPORTANT: Excludes nav_menu_item to prevent menu structure issues
     */
    add_filter('pll_filter_translated_post', 'fix_polylang_custom_class_issue', 20, 4);
    function fix_polylang_custom_class_issue($tr_post, $source_post, $target_language, $data) {
        if (!$tr_post instanceof WP_Post) {
            return $tr_post;
        }
        
        // Exclude menu items - they don't contain Enfold shortcodes
        if ($tr_post->post_type === 'nav_menu_item') {
            return $tr_post;
        }
        
        $content = $tr_post->post_content;
        $original_content = $content;
        
        // Fix 1: Remove malformed id="custom_class=" or id="custom_class" in HTML
        $content = preg_replace(
            '/\s+id=["\']custom_class(?:=["\'])?/i',
            '',
            $content
        );
        
        // Fix 2: Fix unclosed custom_class=' attributes (THE MAIN ISSUE)
        // Pattern: custom_class=' followed by space, closing bracket, or end of shortcode
        // Replace with custom_class='' (properly closed empty attribute)
        $before_fix2 = $content;
        $content = preg_replace(
            "/custom_class='(?=\s|'|])/i",
            "custom_class=''",
            $content
        );
        $fix2_count = substr_count($before_fix2, "custom_class='") - substr_count($content, "custom_class='");
        
        // Fix 3: Also handle custom_class=" (double quotes, unclosed)
        $before_fix3 = $content;
        $content = preg_replace(
            '/custom_class="(?=\s|"|])/i',
            'custom_class=""',
            $content
        );
        $fix3_count = substr_count($before_fix3, 'custom_class="') - substr_count($content, 'custom_class="');
        
        // Fix 4: Remove custom_class='' or custom_class="" if they appear as standalone (no value)
        // This cleans up empty attributes that might cause issues
        $before_fix4 = $content;
        $content = preg_replace(
            "/\s+custom_class=['\"]{2}/i",
            '',
            $content
        );
        $fix4_count = (substr_count($before_fix4, "custom_class=''") + substr_count($before_fix4, 'custom_class=""')) - 
                      (substr_count($content, "custom_class=''") + substr_count($content, 'custom_class=""'));
        
        // Fix 5: Fix in shortcode attributes - sometimes custom_class becomes id in shortcodes
        $before_fix5 = $content;
        $content = preg_replace(
            '/\[([a-z_]+)([^\]]*?)\s+id=["\']custom_class(?:=["\'])?([^\]]*?)\]/i',
            '[$1$2$3]',
            $content
        );
        $fix5_count = substr_count($before_fix5, 'id="custom_class') - substr_count($content, 'id="custom_class');
        
        // Debug logging (only if WP_DEBUG is enabled)
        if (defined('WP_DEBUG') && WP_DEBUG && $content !== $original_content) {
            error_log(sprintf(
                '[POLYLANG FIX] Post ID %d: Fixed %d unclosed custom_class=\' attributes, %d unclosed custom_class=", %d empty custom_class, %d id="custom_class" issues',
                $tr_post->ID,
                $fix2_count,
                $fix3_count,
                $fix4_count,
                $fix5_count
            ));
        }
        
        $tr_post->post_content = $content;
        return $tr_post;
    }
    
    /**
     * Solution 2: Clean content when post is saved (Backup Fix)
     * This catches the issue at save time as a safety net
     * 
     * CRITICAL: Fixes unclosed custom_class=' attributes
     * IMPORTANT: Excludes nav_menu_item to prevent menu structure issues
     */
    add_filter('wp_insert_post_data', 'clean_custom_class_on_save', 10, 2);
    function clean_custom_class_on_save($data, $postarr) {
        // Exclude menu items - they don't contain Enfold shortcodes and menu structure is in postmeta
        if (!isset($data['post_type']) || $data['post_type'] === 'nav_menu_item') {
            return $data;
        }
        
        if (!isset($data['post_content'])) {
            return $data;
        }
        
        $content = $data['post_content'];
        
        // Fix 1: Remove id="custom_class=" or id="custom_class" from content
        $content = preg_replace(
            '/\s+id=["\']custom_class(?:=["\'])?/i',
            '',
            $content
        );
        
        // Fix 2: Fix unclosed custom_class=' attributes
        $content = preg_replace(
            "/custom_class='(?=\s|'|])/i",
            "custom_class=''",
            $content
        );
        
        // Fix 3: Fix unclosed custom_class=" (double quotes)
        $content = preg_replace(
            '/custom_class="(?=\s|"|])/i',
            'custom_class=""',
            $content
        );
        
        // Fix 4: Remove empty custom_class='' or custom_class="" attributes
        $content = preg_replace(
            "/\s+custom_class=['\"]{2}/i",
            '',
            $content
        );
        
        $data['post_content'] = $content;
        return $data;
    }
    
    /**
     * Solution 3: Clean content right after Polylang duplication
     * This runs immediately after Polylang creates a sync post
     * 
     * CRITICAL: Fixes unclosed custom_class=' attributes that break Enfold
     * IMPORTANT: Excludes nav_menu_item to prevent menu structure issues
     */
    add_action('pll_created_sync_post', 'clean_enfold_content_after_duplication', 5, 4);
    function clean_enfold_content_after_duplication($post_id, $tr_id, $lang, $strategy) {
        $post = get_post($tr_id);
        if (!$post) {
            return;
        }
        
        // Exclude menu items - they don't contain Enfold shortcodes
        if ($post->post_type === 'nav_menu_item') {
            return;
        }
        
        $content = $post->post_content;
        $original = $content;
        
        // Fix 1: Remove malformed id="custom_class" issues
        $content = preg_replace('/\s+id=["\']custom_class(?:=["\'])?/i', '', $content);
        
        // Fix 2: Fix unclosed custom_class=' attributes (THE MAIN ISSUE)
        // Replace custom_class=' (unclosed) with custom_class='' (properly closed)
        $before_fix2 = $content;
        $content = preg_replace(
            "/custom_class='(?=\s|'|])/i",
            "custom_class=''",
            $content
        );
        $fix2_count = substr_count($before_fix2, "custom_class='") - substr_count($content, "custom_class='");
        
        // Fix 3: Fix unclosed custom_class=" (double quotes)
        $before_fix3 = $content;
        $content = preg_replace(
            '/custom_class="(?=\s|"|])/i',
            'custom_class=""',
            $content
        );
        $fix3_count = substr_count($before_fix3, 'custom_class="') - substr_count($content, 'custom_class="');
        
        // Fix 4: Remove empty custom_class='' or custom_class="" attributes entirely
        // Enfold doesn't need empty custom_class attributes
        $before_fix4 = $content;
        $content = preg_replace(
            "/\s+custom_class=['\"]{2}/i",
            '',
            $content
        );
        $fix4_count = (substr_count($before_fix4, "custom_class=''") + substr_count($before_fix4, 'custom_class=""')) - 
                      (substr_count($content, "custom_class=''") + substr_count($content, 'custom_class=""'));
        
        // Fix 5: Ensure custom_class attributes with values are properly formatted
        $content = preg_replace_callback(
            '/\[([a-z_]+)([^\]]*?)\s+custom_class=([^\s"\']+)([^\]]*?)\]/i',
            function($matches) {
                // Ensure custom_class has quotes if missing
                $value = trim($matches[3]);
                if (!preg_match('/^["\'].*["\']$/', $value)) {
                    $value = '"' . esc_attr($value) . '"';
                }
                return '[' . $matches[1] . $matches[2] . ' custom_class=' . $value . $matches[4] . ']';
            },
            $content
        );
        
        // Debug logging (only if WP_DEBUG is enabled)
        if (defined('WP_DEBUG') && WP_DEBUG && $content !== $original) {
            error_log(sprintf(
                '[POLYLANG FIX] Post ID %d (from %d): Fixed %d unclosed custom_class=\', %d unclosed custom_class=", %d empty custom_class attributes',
                $tr_id,
                $post_id,
                $fix2_count,
                $fix3_count,
                $fix4_count
            ));
        }
        
        if ($content !== $original) {
            wp_update_post(array(
                'ID' => $tr_id,
                'post_content' => $content
            ));
        }
    }
    
    /**
     * Solution 4: Clean content on frontend display (Final Safety Net)
     * This ensures broken content doesn't display even if it got into the database
     */
    add_filter('the_content', 'remove_custom_class_id_from_html', 999);
    function remove_custom_class_id_from_html($content) {
        // Remove id="custom_class=" (malformed with extra equals)
        $content = preg_replace('/\s+id=["\']custom_class=["\']?/i', ' ', $content);
        
        // Remove id="custom_class" (literal value only)
        $content = preg_replace('/\s+id=["\']custom_class["\']/i', ' ', $content);
        
        return $content;
    }
    
    in reply to: Polylang / Enfold incompatibility inserts custom_class= #1492558

    Thank you Ismael for looking into this. It is certainly a mystery as to why this custom_class is being added.
    I have checked your changes and unfortunately when moving this function to live (and flushing the cache) the issue remains and the pages appear broken. So I don’t think this is filtering. The page you prepared was down to manually removing the custom_class in every page element.
    Can you suggest any further ways we can look into this, as obviously having to go through every page element to remove custom_class in the ID is not practical going forward. Any thoughts you have are appreciated…?

    Many thanks

    in reply to: Polylang / Enfold incompatibility inserts custom_class= #1492527

    Thank you Ismael. How strange it was on an older version as I use the Theme update function. I have manually re-uploaded to the latest version and the same problem exists.

    in reply to: Polylang / Enfold incompatibility inserts custom_class= #1492457
    This reply has been marked as private.
    in reply to: Polylang / Enfold incompatibility inserts custom_class= #1492404

    thank you, I have sent details below in private content.

    in reply to: remove container wrappers around code widget #1473487

    Thank you very much indeed for this. I will have a look at your code. I see yours is working on Safari. Are you contactable on the info@ address on your website demo?

    in reply to: remove container wrappers around code widget #1473453

    Thank you so much for this. I have started implementing but need to debug it as the video in my example (and your demo) doesn’t seem to scrub forward and backward with the scroll. I will have another look tomorrow.

    in reply to: remove container wrappers around code widget #1473441

    Thank you Guenni007 for your reply. It is actually within other alb elements as it may happy at various places on the page, rather than the first child of main. I like your filter thinking though. The code you have to insert is the correct code.

    I am using the following CSS, but it seems that when these div.holder and section.vid are within the surrounding tags then we end up with the large blank space below because the height of section.vid is 3000px (which is tied to the scroll action).

    Are there any other filters you know of which can help? I have tried selecting on the code block widget: Deactivate schema.org markup
    Output the code without any additional wrapper elements. (not recommended). But that doesn’t help.

    section.vid {
    height: 3000px !important; /* Maintain desired scrolling height */
    }

    section.vid div.holder {
    position: sticky !important;
    top: 0 !important;
    }

    section.vid video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    }

    in reply to: remove container wrappers around code widget #1473329

    Hello Ismael – yes I added that code, as per the code I posted to you, you can see it in the first line. What I am trying to do is create a video scrubber scrolling effect. This requires the container to be at that height, so the scroll is tied to the video position (see rest of code). Then to remove the height so it works similarly to parallax then we use section.vid div.holder {position:sticky!important; top:0!important;}. Making the screen stick to enable the scrolling video. However the problem is that Enfold automatically generates container tags around a code block. Therefore these div containers are also being set at that height of the section.vid box. My original question was how do we insert code without the container tags being generated, which would be the cleanest method. If that is not possible, then is there another solution to make the container tags also the same size? Any ideas appreciated. Thanks, Philip.

    in reply to: remove container wrappers around code widget #1473248
    This reply has been marked as private.
    in reply to: remove container wrappers around code widget #1473247
    This reply has been marked as private.
    in reply to: Enfold 5.6 #1406352

    Hello Yigit, thank you very much indeed for looking into this. Bizarrely I have gone to take a screenshot and it is all working again. Very confused as I spent a good 30 mins going through server settings and disabling plugins etc. It wasn’t just this machine either, it got reported by a client also on Safari that the front end news items on the homepage were missing. However, as it stands it all seems to be working fine. Can we keep this open for a day or so and see if it re-materialises? Thanks

    in reply to: Issues updating to Enfold 5.6 #1406320

    I am having the same issue whereby certain elements such as images and certain builder elements don’t work. Seems to be down to a Jquery issue. Have installed Jquery migrate helper (as found on an old thread) but this hasn’t fixed it. Disabled all plugins, cache etc and still the same. Currently unable to access the Enfold settings panel either as seems to be powered by jQuery. Site works fine on Chrome, currently Safari seems to be causing the issues.

    in reply to: Different main nav menus for site section #1398837

    Mike – thanks so much for that, it worked perfectly.

    Much appreciated.

    Philip.

    in reply to: Different main nav menus for site section #1398335

    Thanks Yigit – unless I have misunderstood – your solution just looks at having different menus (Main nav, top nav, footer etc). This creates a different MAIN Nav for a section based on the conditions of where the page is in the hierarchy.

    I am currently trying to hook into the very top nav to do the same. (header_secondary_menu) which I see you have avf_execute_avia_meta_header

    You define this as avia2 in the helper-main-menu.php (lines 62-64)

    //display the small submenu
          $avia_theme_location = 'avia2';
    			                $avia_menu_class = $avia_theme_location . '-menu';

    So I have modified the following but it doesn’t appear to work. What am I missing?

    Thanks

    function my_custom_wp_nav_menu_args( $args = '' ) {
    
    if($args['theme_location'] === 'avia2') 
    	if ( is_child( 'HCP Home' ) ) {
    		  $args['menu'] = 'Top Menu HCP'; 
    	} elseif ( is_child( 'Patient Home' ) ) {
    		  $args['menu'] = 'Top Menu Patient'; 		
    	} else {
    		//* otherwise set the default as defined in the enfold-child theme as Secondary Menu
    		$args['menu'] = 'avia2';
    	}
    return $args;
    in reply to: Different main nav menus for site section #1398322

    ***SOLVED****
    Further to this, for anyone wanting to solve this challenge of having conditional man navigation menus based on the site section, the below set of functions:

    1. Setup specific menus for your audiences (Patient and HCP in this example)
    2. Creates an is_child function that determines if the page has a parent page called something specific (you can also do this by page ID or page slug of the parent but I want to re-use it for other sites so using the page name)
    3. Provides the conditional swap logic “my_custom_wp_nav_menu_args” to swap out the main nav and defaults to the Enfold Main Nav otherwise.

    So to set this up:

    Create the following in the child theme functions.php
    Create your section home pages
    Create your sub-pages and then set their parent page as the section home page

    I hope this helps someone.

    function register_my_menus() {
    register_nav_menus(
    array(
    ‘patient-menu’ => __( ‘Patient Menu’ ),
    ‘HCP-menu’ => __( ‘HCP Menu’ )
    )
    );
    }
    add_action( ‘init’, ‘register_my_menus’ );

    /**
    * Child page conditional
    * @ Accept’s page ID, page slug or page title as parameters
    * https://sridharkatakam.com/useful-functions-checking-pages-sub-pages-wordpress/
    */
    function is_child( $parent = ” ) {
    global $post;
    $parent_obj = get_page( $post->post_parent, ARRAY_A );
    $parent = (string) $parent;
    $parent_array = (array) $parent;
    if ( in_array( (string) $parent_obj[‘ID’], $parent_array ) ) {
    return true;
    } elseif ( in_array( (string) $parent_obj[‘post_title’], $parent_array ) ) {
    return true;
    } elseif ( in_array( (string) $parent_obj[‘post_name’], $parent_array ) ) {
    return true;
    } else {
    return false;
    }
    }

    add_filter( ‘wp_nav_menu_args’, ‘my_custom_wp_nav_menu_args’ );

    /**
    * CManu switch based on page/parent relationship for HCP, Patient or others
    * @ Accept’s page ID, page slug or page title as parameters
    * PJE – RESOLVE
    */

    function my_custom_wp_nav_menu_args( $args = ” ) {

    if($args[‘theme_location’] === ‘avia’)
    if ( is_child( ‘HCP Home’ ) ) {
    $args[‘menu’] = ‘HCP’;
    } elseif ( is_child( ‘Patient Home’ ) ) {
    $args[‘menu’] = ‘Patient’;
    } else {
    //* otherwise set the default as defined in the enfold-child theme as Main Menu
    $args[‘menu’] = ‘avia-menu’;
    }
    return $args;
    }

    Hello. If anybody also wants to know this, I managed to get it working

    #header .logo {
    left: 50%;
    transform: translateX(-50%);
    z-index:999;
    }
    #header .logo img {
    top: 50%;
    transform: translateY(-50%);
    max-width: 410px;
    }
    .avia-menu {float:right;}

    Hope that helps.

    Hi – anybody there?

    Hello, reply in private.

    Hi. Could anyone let me know on the above please? Thanks

    Hi Rikard, thanks for your reply. I cannot currently post a link to the site as as it is a staging site and the DNS isn’t available to change just yet to make it public. I am therefore accessing via changing my hosts file. I can send you a visual if you need, and let me know how to get it to you.

    But yes, centred logo, but burger menu to the right of the page and then when opened the burger menu full screen.
    Currently your config allows for centred logo and menu below (or above) but not to have the burger menu on the right hand side of the page. The CSS to do that would be appreciated.

    Many thanks

    Philip.

    Great. But how long do you anticipate and is there a temporary work around in the meantime? Otherwise I am having to re-produce a bunch of videos to join them all together, which of course had knock-on ramifications.

    Many thanks

    Hi – was there ever a followup to this as I am having the same problem

    • This reply was modified 5 years, 9 months ago by philipe.
    in reply to: Envato private token doesn't work #1059049

    Hi – further to my message below yesterday and Rikard’s response, I tested again before I re-opened a new thread on this.

    The token process now works ( having not changed anything ).

    I can only assume that either there was a caching issue when I originally tried to validate, or there was a connection problem between the servers which has now been fixed, or perhaps the permissions on the token setup were taking time to propagate. Anyway, wait 24 hours or so and tried again and it all works with no changes.

    Thanks.

    in reply to: Envato private token doesn't work #1058524

    HI there. Could someone please help.
    I have manually updated via FTP. I have generated an Envato token. I have (after many attempts) decided to set the token permissions to all. I have tried incognito mode (Private Browsing in Safari). I have deleted the old tokens and then saved, logged out, logged back in, added the token, saved, validated.

    I still get the same errors: (personal details removed and replaced with XXXXX)

    Thanks, Phil.

    Last time we checked the token we were not able to connected to Envato:

    Purchases could not be accessed
    Your username: XXXXX
    Your E-Mail: XXXXX
    Following errors occured:

    Purchases: Errorcode 403 returned by Envato: Forbidden:
    – response_code: 403
    – reason: scope-missing
    Purchases: A problem occured accessing your purchases. Unable to check for updates.

    in reply to: Hide content shorcode #171512

    Thanks for the response Peter.

    How would i therefore do this for other ‘objects’ say the icon list object? – there is no ability to add pre and post text on these, so the only option is to put a text block above and a text block below.

    Any ideas?

    in reply to: Enfold – Insert into Page button not working #171226

    Hi Ismael

    Sorry for the slow response.
    Seems like there is a clash with CMB Metabox framework https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress
    Whenever that is enabled, the ‘add media’ function seems to bug out.
    Looks like a JS error, so probably a clash of JQuery or something.
    I will investigate further and update this if i find a solution.

    thanks

    in reply to: Enfold – Insert into Page button not working #167532

    Hi

    Futher to this i have manged to get some output from Safari error logs (Firefox/Firebug crash out).

    After insert into post is pressed, the following is returned:
    avia_media.js:141RangeError: Maximum call stack size exceeded.

    It would seem that there is a clash with AVIA and the cmb_metabox framework on
    https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress

    as if i disable the function to init the framework, the WP functionality then works to insert a post.

    Part of the init.php function is to call the following

    function cmb_scripts( $hook ) {
    if ( $hook == ‘post.php’ OR $hook == ‘post-new.php’ OR $hook == ‘page-new.php’ OR $hook == ‘page.php’ ) {
    wp_register_script( ‘cmb-scripts’, CMB_META_BOX_URL.’jquery.cmbScripts.js’, array( ‘jquery’,’media-upload’,’thickbox’ ) );
    wp_enqueue_script( ‘jquery’ );
    wp_enqueue_script( ‘jquery-ui-core’ ); // Make sure and use elements form the 1.7.3 UI – not 1.8.9
    wp_enqueue_script( ‘media-upload’ );
    wp_enqueue_script( ‘thickbox’ );
    wp_enqueue_script( ‘cmb-scripts’ );
    wp_enqueue_style( ‘thickbox’ );
    wp_enqueue_style( ‘jquery-custom-ui’ );
    add_action( ‘admin_head’, ‘cmb_styles_inline’ );
    }
    }

    Could this be the source of the conflict do you think?

    Many thanks for any guidance.

    Phil.

Viewing 28 posts - 1 through 28 (of 28 total)