PHP JavaScript Form Validation
Read more at https://www.phpclasses.org/package/11723-PHP-Output-form-validation-JavaScript-from-a-INI-file.html#2020-08-03-15:53:53
Often when working with a list, we only want to work with a subset of a list that meets some criteria. All non-zero values, for example, or all users that have a given role. The procedural way to do that is to stick an if
statement inside a foreach
loop:
<?php
foreach ($list as $value) {
If (!meets_criteria($value)) {
continue;
}
// ...
}
?>
That mixes up the filtering with the iteration, though. It also doesn't work if we're using `array_map()`.
Instead, we can make stripping down the list a separate operation called "filter." PHP offers the array_filter()
function for that purpose.
<?php
$criteria = fn(User $user): bool => $user->hasRole('moderator');
$filtered = array_filter($users, $criteria);
?>
Now we can work with the `$filtered` list, which has only the values we want. That could be a simple foreach
loop, or, better, it's now ideally suited for use with
array_map()
.
Want to know more about functional programming and PHP? Read the whole book on the topic: Thinking Functionally in PHP.
July was an action-packed month for the WordPress project. The month saw a lot of updates on one of the most anticipated releases – WordPress 5.5! WordCamp US 2020 was canceled and the WordPress community team started experimenting with different formats for engaging online events, in July. Read on to catch up with all the updates from the WordPress world.
July was full of WordPress 5.5 updates! The WordPress 5.5 Beta 1 came out on July 7, followed by Beta 2 on July 14, Beta 3 on July 21, and Beta 4 on July 27. Subsequently, the team also published the first release candidate of WordPress 5.5 on July 28.
WordPress 5.5, which is slated for release on August 11, 2020, is a major update with features like automatic updates for plugins and themes, a block directory, XML sitemaps, block patterns, and lazy-loading images, among others. To learn more about the release, check out its field guide post.
Want to get involved in building WordPress Core? Follow the Core team blog, and join the #core channel in the Making WordPress Slack group.
The core team launched Gutenberg 8.5 and 8.6. Version 8.5 – the last plugin release will be included entirely (without experimental features) in WordPress 5.5, introduced improvements to block drag-and-drop and accessibility, easier updates for external images, and support for the block directory. Version 8.6 comes with features like Cover block video position controls and block pattern updates. For full details on the latest versions on these Gutenberg releases, visit these posts about 8.5 and 8.6.
Want to get involved in building Gutenberg? Follow the Core team blog, contribute to Gutenberg on GitHub, and join the #core-editor channel in the Making WordPress Slack group.
The Community team made the difficult decision to suspend in-person WordPress events for the rest of 2020 in light of the COVID-19 pandemic. The team has also started working on reimagining online events. Based on feedback from the community members, the team decided to make changes to the current online WordCamp format. Key changes include wrapping up financial support for A/V vendors, ending event swag support for newer online WordCamps, and suspending the Global Community Sponsorship program for 2020. The team encourages upcoming online WordCamps to experiment with their events to facilitate an effective learning experience for attendees while avoiding online event fatigue. The team is currently working on a proposal to organize community-supported recorded workshops and synchronous discussion groups to help community members learn WordPress.
Want to get involved with the Community team? Follow the Community blog here, or join them in the #community-events channel in the Making WordPress Slack group. To organize a Meetup or WordCamp, visit the handbook page.
The organizers of WordCamp US 2020 have canceled the event in light of the continued pandemic and online event fatigue. The flagship event, which was originally scheduled for October 27-29 as an in-person event, had already planned to transition to an online event. Several WCUS Organizers will be working with the WordPress Community team to focus on other formats and ideas for online events, including a 24-hour contributor day, and contributing to the workshops initiative currently being discussed. Matt Mullenweg’s State of the Word (which typically accompanies WordCamp US) is likely to take place in a different format later in 2020.
After eleven years, WordPress now allows users to update plugins and themes by uploading a ZIP file, in WordPress 5.5. The feature, which was merged on July 7, has been one of the most requested features in WordPress. Now, when a user tries to upload a plugin or theme zip file from the WordPress dashboard by clicking the “Install Now” button, WordPress will direct users to a new screen that compares the currently-installed extension with the uploaded versions. Users can then choose between continuing with the installation or canceling. WordPress 5.5 will also offer automatic plugin and theme updates.
Have a story that we should include in the next “Month in WordPress” post? Please submit it here.
Latest PEAR Releases:
Web page speed and performance is very important to the user experience. If your site is too slow, you’ll not only be losing visitors, but also potential customers. Search engines like Google factor a website’s speed into account in search rankings, so when optimizing your site’s speed, you should take everything into consideration. Every millisecond counts.
Here are just a few basic and general suggestions for improving a site’s performance.
Ajax allows us to build web pages that can be asynchronously updated at any time. This means that instead of reloading an entire page when a user performs an action, we can simply update parts of that page.
We can use an image gallery as an example. Image files are big and heavy; they can slow down page-loading speeds of web pages. Instead of loading all of the images when a user first visits the web page, we can just display thumbnails of the images and then when the user clicks on them, we can asynchronously request the full-size images from the server and update the page. This way, if a user only wants to see a few pictures, they don’t have to suffer waiting for all of the pictures to download. This development pattern is called lazy loading.
Ajax/web development libraries like jQuery, Prototype, and MooTools can make deferred content-loading easier to implement.
When the user first loads your web page, the browser will cache external resources like CSS and JavaScript files. Thus, instead of inline JavaScript and CSS files, it’s best to place them in external files.
Using inline CSS also increases the rendering time of a web page; having everything defined in your main CSS file lets the browser do less work when rendering the page, since it already knows all the style rules that it needs to apply.
As a bonus, using external JavaScript and CSS files makes site maintenance easier because you only need to maintain global files instead of code scattered in multiple web pages.
If you find that your site is connecting to your database in order to create the same content, it’s time to start using a caching system. By having a caching system in place, your site will only have to create the content once instead of creating the content every time the page is visited by your users. Don’t worry, caching systems periodically refresh their caches depending on how you set it up — so even constantly-changing web pages (like a blog post with comments) can be cached.
Popular content management systems like WordPress and Drupal will have static caching features that convert dynamically generated pages to static HTML files to reduce unnecessary server processing. For WordPress, check out WP Super Cache (one of the six critical WordPress plugins that Six Revisions has installed). Drupal has a page-caching feature in the core.
There are also database caching and server-side scripts caching systems that you can install on your web server (if you have the ability to do so). For example, PHP has extensions called PHP accelerators that optimize performance through caching and various other methods; one example of a PHP accelerator is APC. Database caching improves performance and scalability of your web applications by reducing the work associated with database read/write/access processes; memcached, for example, caches frequently used database queries.
If an image is originally 1280x900px in dimension, but you need to have it be 400x280px, you should resize and resave the image using an image editor like Photoshop instead of using HTML’s width
and height
attributes (i.e. <img width="400" height="280" src="myimage.jpg" />
). This is because, naturally, a large image will always be bigger in file size than a smaller image.
Instead of resizing an image using HTML, resize it using an image editor like Photoshop and then save it as a new file.
Not only does text in an image become inaccessible to screen-readers and completely useless for SEO, but using images to display text also increases the load times of your web pages because more images mean a heavier web page.
If you need to use a lot of custom fonts in your website, learn about CSS @font-face to display text with custom fonts more efficiently. It goes without saying that you have to determine whether serving font files would be more optimal than serving images.
By picking the right image format, you can optimize file sizes without losing image quality. For example, unless you need the image transparency (alpha layers) that the PNG format has to offer, the JPG format often displays photographic images at smaller file sizes.
To learn more about how to decide between JPG, PNG, and GIF, read the following guides:
Additionally, there are many tools you can use to further reduce the file weights of your images. Check out this list of tools for optimizing your images.
Look around your source code. Do you really need all the tags you’re using or can you use CSS to help out on the display? For example, instead of using <h1><em>Your heading</em></h1>
, you can easily use CSS to make your headings italics using the font-style
property. Writing code efficiently not only reduces file sizes of your HTML and CSS documents, but also makes it easier to maintain.
It’s best if you have your scripts loading at the end of the page rather than at the beginning. It allows for the browser to render everything before getting started with the JavaScript. This makes your web pages feel more responsive because the way JavaScript works is that it blocks anything below it from rendering until it has finished downloading. If possible, reference JavaScript right before the closing <body>
tag of your HTML documents. To learn more, read about deferring the loading of JavaScript.
Your site’s speed is greatly affected by where the user’s location is, relative to your web server. The farther away they are, the more distance the data being transmitted has to travel. Having your content cached across multiple, strategically placed geographical locations helps take care of this problem. A CDN will often make your operating cost a little higher, but you definitely gain a speed bonus. Check out MaxCDN or Amazon Simple Storage Service (Amazon S3).
Along with using caching systems, you should create websites that utilize web caching as much as possible. Web caching is when files are cached by the web browser for later use. Things that browsers can cache include CSS files, JavaScript files, and images.
Aside from the basics, such as putting CSS and JavaScript code that are used in multiple pages in external files, there are many ways to make sure that you are caching your files in the most efficient way possible.
For example, you can set HTTP response headers such as Expires
and Last-Modified
to reduce the need of re-downloading certain files when the user comes back to your site. To learn more, read about caching in HTTP and leveraging browser caching.
To set up HTTP Expires
headers in Apache, read this tutorial on adding future expires headers.
The post 10 Tips for Optimizing Your Website’s Speed appeared first on WebFX Blog.
Among the first things you learn as a freelance web designer is that everybody wants a deal. Whether it’s a new client or an existing one, you’ll receive plenty of requests for discounted pricing. It’s almost as if they mistake a web design firm for a used car lot.
While haggling over price is as old as commerce itself, we still need to make a living. Thus, if we provided a discount every time one was requested, we’d probably starve (or at least be noticeably hungry).
That’s why full price should be the norm for most clients. Doing things this way has a number of benefits. For one, it keeps your bank account in better shape. Then, too it helps with predicting future revenue and also serves as a motivator. A case can also be made that it reduces one’s stress levels, as we’re not sweating in search of that next project.
Still, that doesn’t mean discounting your services is never a good move. There are some scenarios where it might make sense for your business. Here are a few times when a discount should be on the table.
A variety of industries offer discounted services to non-profit organizations. For example, anyone from internet providers to banks provide some money-saving deals for these types of outfits. Some see it as a moral obligation, while others may look at it as a chance to grab some good publicity.
For web designers, especially solo entrepreneurs, it can be a little more complicated. We don’t have the financial resources of bigger companies – deep discounts really can disrupt our revenues.
Therefore, perhaps the larger price cuts should be reserved for organizations who are close to your heart. A local charity with a tight budget is a prime example. That might be, among other things, a food bank, a homeless shelter or an animal rescue.
In those cases, you might find building a website to be a true labor of love. With that, money shouldn’t be the main object.
It is important to stay judicious about who gets those price breaks, however. You don’t want to get into a situation where you’re pouring in hours of work without fair compensation.
The truly lucky among us will have clients that stick with us for years. Not only are they a pleasure to work with, they also pay on time and make referrals.
These folks are the ones who help to keep your business going. Because of that, they deserve a special place on your client list. They are the VIPs.
Providing a small discount on a website redesign is both good business and a way of saying “thank you”. If they’ve brought you a good bit of revenue over time, any amount you can knock off the price really is worth it.
This helps to continue building good will in your relationship. In turn, you’ll know that you can count on their continued patronage and willingness to spread the good word about your business.
Inevitably, one or more of your clients will go through a difficult time when revenues are down. It could be part of a widespread crisis such as a pandemic, or something much more localized like a fire or bankruptcy.
Whatever the case may be, this might be an appropriate time to provide a discount. Again, it’s about helping to strengthen your relationship and demonstrate that you have your client’s back.
Beyond that, there’s also some practicality involved. If you charge recurring fees for maintenance packages or web hosting, it may be extremely difficult for a client to pay in such dire circumstances. By providing a discount or even breaking things down into multiple invoices, this might make the ultimate difference in whether you get paid.
Of course, this does depend at least somewhat on your past experience with a particular client. If they’re generally on time with payment and great to work with, this makes the decision easier.
The scenarios above are the exception. While the subject of discounted pricing will be broached by others, most often it’s better to say “no”.
When it comes to prospective clients, they may be shopping around for the best deal. That’s their prerogative, but web designers will not benefit from any sort of pricing war. Such a race to the bottom will make you regret ever taking on the project to begin with.
Then there are those who boldly proclaim that a discount now carries the promise of “more work” later on. This is truly one of the oldest tricks in the book – don’t give in. Unless some future revenue is guaranteed in writing, you’re unlikely to ever see those brighter days.
Existing clients are a bit more complex. As we mentioned earlier, it’s fine to provide discounts to your VIPs. They’ve more than made up for whatever break you offer.
But some people simply don’t want to pay for anything – and they expect others to bend to their demands. It can actually be the sign of a one-way relationship, where your experience and expertise aren’t being valued. It might be better to see them walk away in an angry heap than to feed their ego.
The lesson here is that just because someone asks for a discount, it shouldn’t make you more inclined to give one. You might even make the case that the opposite is true.
Those deserving a break include the non-profit organizations doing good or the loyal client who always pays you for your time. Their actions may move you to offer lower pricing without even being asked to do so.
Since it’s your web design business, you get to make those decisions. Choose wisely!
The post Should a Web Designer Ever Provide Discounts? appeared first on Speckyboy Design Magazine.