Skip Navigation

[Closed] error uploading code snippet

This support ticket is created 2 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 7.51 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 15 replies, has 2 voices.

Last updated by Shane 2 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#2317621

When I hit activate on my custom code that I was helped with it gives me an error and makes my site go critical error.

#2317687

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jason,

Thank you for getting in touch.

What we recommend doing here is to enable the wordpress debugging functions to understand the error being thrown.

To enable the wordpress debugging you will either need to log into your website using FTP or using your Host's CPanel's file manager.

From there you will need to edit the wp-config file by adding the following.

// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );

If the define( 'WP_DEBUG', true ); function already exists you will need to change 'false' to 'true'

Once you've done this please revisit the page with the issue and let me know what the issue is.

Thanks,
Shane

#2318973

I did what you said but I did not see any error log pop up, it still just says error updating code snippets

#2318975

this pops up Deprecated: Non-static method OWA_Block::register_widget_sidebar() should not be called statically in /var/web/site/public_html/wp-includes/class-wp-hook.php on line 307

#2319499

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jason,

What is the code snippet that you're using ?

There seems to be an error in the actual code itself.

Thanks,
Shane

#2320805

<?php
/**
*Get file name instead of url.
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Add Shortcode
function trim_urlbasename( $atts ) {

// Attributes
$atts = shortcode_atts(
array(
'url' => '',
),
$atts
);

return basename($atts['url']).PHP_EOL;

}
?>
add_shortcode( 'trim_urlbasename', 'trim_urlbasename' );

#2320813

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jason,

Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this one for you?

I've enabled the private fields for your next response.

Thanks,
Shane

#2320945

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jason,

The issue was with the function name.

I had to change the function name to get_filefromurl and change the shortcode name itself to [get_filefromurl] so you should be ok now.

Using the new shortcode should work as well your function is now saving correctly.

Thanks,
Shane

#2324601

Okay now that I have the code right how would I use it to trim the urls of my custom field call upload-file

here is the custom function you made
<?php
/**
* New custom code snippet (replace this with snippet description).
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment
// Add Shortcode
function get_filefromurl( $atts ) {

// Attributes
$atts = shortcode_atts(
array(
'url' => '',
),
$atts
);

return basename($atts['url']).PHP_EOL;

}
add_shortcode( 'get_filefromurl', 'get_filefromurl' );

I want to trim the url of upload-file in a repeating field

#2325071

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jason,

As described in one of our previous tickets. To do this you will need to format the shortcode like below.

<ol>[wpv-for-each field="wpcf-upload-file"]
 
<li><a href="[types field='upload-file' output='raw']> [get_filefromurl url="[types field='upload-file' output='raw']"]</a></li>
 
[/wpv-for-each]</ol>

Please let me know if this helps.
Thanks,
Shane

#2326353

After I insert that code I just get the number but nothing shows up like the files name as it should

#2326905

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jason,

Could you send me a link to the page where you're displaying the fields with the code?

Thanks,
Shane

#2326927

I can’t send a link because when I try and it doesn’t work I have to revert back to what I need to be showing because it’s on an active template on the site. So any property page with file uploads would have it for example and if it’s broke I can’t publish that on the page

#2326939

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jason,

The issue should now be resolved. The problem was that anytime you copy and paste the code from our forums it will break the formatting when you paste it onto your site.

I had to manually type the shortcode and html structure on your site for it to work correctly.
hidden link

If you check the very bottom of this page you will see the file name being displayed.

Thanks,
Shane

#2328847

I see that the file is being displayed but when I try to put it in the repeating field nothing works it shows "] or ir shows types but not the actual url

The topic ‘[Closed] error uploading code snippet’ is closed to new replies.