• Resolved Marco

    (@marcosal2020)


    Hi Jose,
    first of all I would like to compliment you on the app. It seems very useful and well made. I think I will purchase the pro version very soon.

    I’ve a code snippet format custom post rating number.
    It works fine on a page where post are in grids.
    You can see in: Economia – WeYourConsult

    But when I open the post the number is show as:
    Rating: [format-currency num=”1.020” sym=””]

    La Contabilità in breve – WeYourConsult

    If I disable FreeSoul it works fine, and also if I activate all plugins for pages or CPT, results doesn’t change.

    In order to call the function I use Avada subtitle layout: https://avada.com/documentation/category/layouts/

    With Avada builder I insert a Text block like:

    {!{wpv-conditional if="( $(wpcf-overall-cust-ea-postrat) gt '0' )"}!}
    Rating: [format-currency num="{!{types field='overall-cust-ea-postrat' format='FIELD_VALUE'}!}{!{/types}!}" sym=""] {!{/wpv-conditional}!}

    Here below the function I use:

    function format_my_number($atts)
    {
        $atts = shortcode_atts(
            array(
            'num' => '',
            'sym' => '',
        ),
            $atts
        );
    			
    	if ($atts['num'] == 0 || $atts['num'] == '0' || $atts['num'] == 'NULL' || $atts['num'] == NULL)
    	   {
    		  $atts = shortcode_atts(
    		     array(
    		       'num' => 1,
    		       'sym' => '@',
    			      ),
    			  $atts
    			  );
    		  return $atts['sym'] .$atts['num'];
    	   }
    	else
    	   {
    		  $num = $atts['num'];
    	      return $atts['sym'].' '.number_format($num - 0.05, 1, ',', '.') ;
    
    	   }
    }
    add_shortcode('format-currency', 'format_my_number');

    I tried to see forum, documents and resources for developers, disabled lazy loading, but I havent’t found an answer. Do you have any suggesiton about what to check?

    Many thanks, Marco.

    • This topic was modified 1 year, 4 months ago by Marco.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Jose

    (@giuse)

    Hi @marcosal2020

    thank you for your kind words.

    I suggest you enable the debug in wp-config.php by adding the following lines of code before the comment /* That’s all, stop editing! Happy publishing. */:

    define( 'WP_DEBUG', true );
    define( 'WP_DEBUG_DISPLAY', false );
    define( 'WP_DEBUG_LOG', true );

    Then please, add exactly this code to the function of your shortcode?:

    	if( isset( $GLOBALS['fdp_all_plugins'] ) && is_array( $GLOBALS['fdp_all_plugins'] ) ) {
    		$log = '******* FDP Debug Start *******';
    		$log .= PHP_EOL . 'Globally active plugins: ';
    		$log .= PHP_EOL . print_r( array_map( 'sanitize_text_field', $GLOBALS['fdp_all_plugins'] ), true );
    		if( isset( $GLOBALS['eos_dp_debug'] ) ) {
    			$log .= PHP_EOL . 'FDP Debug Info:';
    			$log .= PHP_EOL . print_r( json_decode( sanitize_text_field( wp_json_encode( $GLOBALS['eos_dp_debug'] ) ), true ), true );
    		}
    		$log .= '******* FDP Debug End *******';
    		error_log( $log );
    	}

    Your code should become:

    function format_my_number($atts)
    {
    	if( isset( $GLOBALS['fdp_all_plugins'] ) && is_array( $GLOBALS['fdp_all_plugins'] ) ) {
    		$log = '******* FDP Debug Start *******';
    		$log .= PHP_EOL . 'Globally active plugins: ';
    		$log .= PHP_EOL . print_r( array_map( 'sanitize_text_field', $GLOBALS['fdp_all_plugins'] ), true );
    		if( isset( $GLOBALS['eos_dp_debug'] ) ) {
    			$log .= PHP_EOL . 'FDP Debug Info:';
    			$log .= PHP_EOL . print_r( json_decode( sanitize_text_field( wp_json_encode( $GLOBALS['eos_dp_debug'] ) ), true ), true );
    		}
    		$log .= '******* FDP Debug End *******';
    		error_log( $log );
    	}
        $atts = shortcode_atts(
            array(
            'num' => '',
            'sym' => '',
        ),
            $atts
        );
    			
    	if ($atts['num'] == 0 || $atts['num'] == '0' || $atts['num'] == 'NULL' || $atts['num'] == NULL)
    	   {
    		  $atts = shortcode_atts(
    		     array(
    		       'num' => 1,
    		       'sym' => '@',
    			      ),
    			  $atts
    			  );
    		  return $atts['sym'] .$atts['num'];
    	   }
    	else
    	   {
    		  $num = $atts['num'];
    	      return $atts['sym'].' '.number_format($num - 0.05, 1, ',', '.') ;
    
    	   }
    }
    add_shortcode('format-currency', 'format_my_number');

    Then visit the same page where you have the ophane shortocode, and let me know what you find in wp-content/debug.log between the lines ******* FDP Debug Start ******* and ******* FDP Debug End *******

    Have a great day!

    Jose

    Thread Starter Marco

    (@marcosal2020)

    Hi Jose,
    many thanks for your reply.

    I’ve updated wp-config.php and PHP code but I receive this message:

    Snippet automatically deactivated due to an error on line 5:
    Syntax error, unexpected token ";", expecting ")".

    line 5 is the following second line ( $log ):

    	if( isset( $GLOBALS['fdp_all_plugins'] ) && is_array( $GLOBALS['fdp_all_plugins'] ) ) {
    		$log = '******* FDP Debug Start *******';
    

    Many thanks.

    ….

    Sorry, maybe I’ve found the reason… email has converted [ with

    -&#091:-

    I try again

    • This reply was modified 1 year, 4 months ago by Marco.
    • This reply was modified 1 year, 4 months ago by Marco.
    • This reply was modified 1 year, 4 months ago by Marco.
    • This reply was modified 1 year, 4 months ago by Marco.
    • This reply was modified 1 year, 4 months ago by Marco.
    • This reply was modified 1 year, 4 months ago by Marco.
    Thread Starter Marco

    (@marcosal2020)

    Hi Jose,
    this is the debug content.log:

    [16-Oct-2023 16:24:15 UTC] ******* FDP Debug Start *******
    Globally active plugins: 
    Array
    (
        [0] => freesoul-deactivate-plugins/freesoul-deactivate-plugins.php
        ...
        LIST OF 113 plugin
        [113] => s
    )
    
    FDP Debug Info:
    Array
    (
        [info] => Array
            (
                [0] => Evaluated Singles Settings. ID: 7731. Post type: groups
                [1] => Plugins disabled according to the Post Types settings. Post type: groups.
            )
    
        [log] => Array
            (
            )
    
        [error] => Array
            (
            )
    
    )
    ******* FDP Debug End *******
    Plugin Author Jose

    (@giuse)

    Thank you @marcosal2020

    It seems FDP is disabling the plugins according to the row Groups of the Post Types settings.
    Is this what you expected? If it’s not so, let me know and we will try to understand why FDP is looking at Post Types => Groups to disable the plugins on the page where you have the orphane shortcode.

    On the contrary, if this is what you expected, then activate a plugin after the other in Post Types => Groups until the issue is solved.
    You may find out that Avada needs one of the plugins that you deactivated in Post Types => Groups to display the output of your shortcode. I would start with the plugins that are suggested by Avada.

    As a side note, the URL of your page is https://weyourconsult.com/?econ-aziendale-ks=la-contabilita-in-breve&v=cd32106bcb6d that is nothing else than the URL of the homepage + the query arguments.
    Theoretically, if you didn’t touch anything in Custom URLs => Frontend URLs, FDP had to evaluate the Singles Settings => ID: 25, which should be the ID of your homepage. At least, this is what I see if I inspect the homepage.
    For me, it’s strange that FDP on https://weyourconsult.com/?econ-aziendale-ks=la-contabilita-in-breve&v=cd32106bcb6d evaluates the Singles Settings => ID: 7731 and disables the plugins according to the Post Types settings, Post type: groups.

    As I see on the frontend, 7731 is the ID of a single post-type Group, but it’s not clear what it has to do with https://weyourconsult.com/?econ-aziendale-ks=la-contabilita-in-breve&v=cd32106bcb6d

    I don’t exclude you have a permalinks structure that disorients FDP.

    In any case, I would investigate step by step. First, please, answer these questions:

    • Is it normal for you that FDP evaluates the Singles Settings => ID: 7731 and then disables the plugins according to the Post Types settings Groups?
    • If you enable all the plugins in Post Types => Groups, do you still have the same issue?

    Depending on your answers I will give you more suggestions to find out the root cause of this issue.

    Have a great day!

    Jose

    Thread Starter Marco

    (@marcosal2020)

    … I’ve also found that ID 7731 it’s about LearnDash Group and I can see them in your plugin as post type.

    I’ve checkd FPD Single Settings for Groups and there ins’t any custom setting.
    Pages you can see in link have nothing in common with LearDash Groups, and yes, it’is very strange.

    I tried to enable all plugins forn Post Types => Groups (and also for Single => Group = Economia and Economy) but without results.
    Also enabling all plugins for https://weyourconsult.com/?econ-aziendale-ks=la-contabilita-in-breve&v=cd32106bcb6d, but it doesn’t resolve.

    Finally I tried to update permalink from WP setting.

    Many thanks for your support, Marco

    • This reply was modified 1 year, 4 months ago by Marco.
    Thread Starter Marco

    (@marcosal2020)

    Hi Jose,
    I’ve made another check with a MySql query:

    SELECT ID, post_title, post_name, guid, post_type FROM wp_posts
    WHERE post_name LIKE ('%econom%')
    AND post_type IN ('page', 'groups', '%econom%')
    AND post_status = 'publish';

    I’ve found that there are two posts in db with same slugs (is it possible in WP?): ID 4996 (WP page) and ID 7731 (LearnDash Group)

    So I changed manually slugs to:
    economia-ldg for LearDash Group
    economia-all for Economia Page

    Than I’ve made a debug and now there’s no array info about Plugins disabled, but now in all pages, number format does’t works and you can see for example: Rating:?[format-currency num=”1.360″ sym=””]

    Finally, if I deactivate FDP format number works ??

    Thanks for your patience, Marco.

    Thread Starter Marco

    (@marcosal2020)

    Hi Jose,
    seems my problem has been resolved. I’ve changed the function to:

    <?php
    function display_number_onedecimal( $atts ) {
      $atts = shortcode_atts( array(
        'num' => ''
      ), $atts );
      $num = $atts['num'];
    	      return number_format($num - 0.05, 1, ',', '.') ;
    }
     add_shortcode('show-number-onedecimal', 'display_number_onedecimal');
    

    And added this shorcode for custom field:

    [show-number-onedecimal num="[types field='overall-cust-ea-postrat'][/types]"]

    Thanks for your support,
    Marco.

    Plugin Author Jose

    (@giuse)

    Hi Marco.

    Perfect! Thank you very much for the information. I’m very happy that it’s solved.

    Have a great day!

    Jose

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Custom Function doesn’t works on Avada Layout’ is closed to new replies.