Software Engineering in WordPress, PHP, and Backend Development

Tag: JavaScript (Page 11 of 12)

Articles, tips, and resources for JavaScript-based development.

Remove JavaScript Tags From WordPress Input Fields

When building custom functionality into WordPress, it’s important to make sure that you’re properly sanitizing data. WordPress provides an array of utility functions for doing this.

But there are times when completely sanitizing the input may be too much. For example, say you’re working on a widget that has a text field and you’re comfortable with allowing the user to input styles and markup but want to remove any JavaScript. Using strip_tags and strip_slashes is overkill, obviously. These would reduce the input into nothing but the raw text.

Here’s a simple way to removing JavaScript tags from input fields while still supporting inline CSS and HTML markup:

Continue reading

Reroute Chrome’s alert() Dialog to the Console

I spend the majority of my time working in Chrome. Whenever I’m working with a lot of JavaScript, I tend to print information to the console for review.

The thing is, typing alert() is much faster than typing console.log() but alert() is exceptionally more annoying. For those of you that want to save a few keystrokes, copy this simple script into a file and include it before any other JavaScript on your site:

Continue reading

Dynamically Creating Anchor Attributes

I was recently tasked with setting up a payment form that would span across two pages. The second form was dependent on information from the first so I needed to pass some data via the query string in order to update the second form.

After completing the first page of the form, the user would click an anchor and then be directed to the second form. Continue reading

Creating an Overlay Element with jQuery

I occasionally have the need to display an overlay element whenever I want to display some time of dialog in the context of my project.

Unfortunately, most plugins or third-party options are a little heavy for having to add a simple overlay. Here’s a function I’ve been using in the past couple of projects: Continue reading

« Older posts Newer posts »

© 2024 Tom McFarlin

Theme by Anders NorenUp ↑