Ben Rothman - WordPress Developer Web Development Archives - Page 2 of 4 - ©2023 Ben Rothman, Web Developer

Blog

My blog is dedicated to sharing my expertise, recommendations, and tutorials on WordPress. If you're interested in developing with WordPress, my blog is a valuable resource that you won't want to miss.

Categories
Plugin Web Development Website WordPress

WordPress: Cloudflare Plugin

Obviously not all WordPress sites use cloudflare, in fact many of them don’t. BUT, if you have a WordPress site and you happen to be one of the people who uses Cloudflare with the site like I do from time to time then you need the Cloudflare plugin.

Why do we need the plugin? We can control everything by logging into Cloudflare and changing the configuration there. That is true, but things like purging the server cache or turning on “development mode” (a great feature) are possible without leaving the comfort of the site if you have the Cloudflare plugin installed and configured.

Just because I know any readers are wondering, “Development Mode” suspend Cloudflare’s edge caching, minification, Polish and Railgun features for three hours so that changes to images, CSS files or Javascript files can immediately be seen by users of the site. Although the site will not load as fast, development mode is good for development since the developer is constantly changing those files and using cached versions would be silly and cause the developer to think there are problems with the new code when there are none.

Categories
Web Development WordPress

Publishing failed. The response is not a valid JSON response.

After a site migration I got this error. Don’t panic, this was an easy fix, go to Settings > Permalinks and choose ‘Post name’ then press the save button. Easy right? Happy WordPressing!

Categories
Web Development WordPress

WordPress 5.9 “Joséphine”

Introducing 5.9, “Joséphine”. Named in honor of acclaimed international jazz singer Joséphine Baker, this latest, most versatile WordPress release is here: download it or update it directly from your dashboard.

As a lifelong civil rights campaigner, Joséphine Baker believed that all people could live in harmony together, just as different instruments in a jazz band blend together to make a whole piece. Turn on a playlist from your favorite music service and enjoy her famous renditions of “You are the greatest love”, “Sans Amour”, and “Love is a Dreamer” as you discover all the features of this brand-new WordPress release. 

Categories
Web Development WordPress

Adding User-Specific Content to a WordPress page

There are many ways to go about this but in this post I will be focusing on using php in your WordPress page template to add content that can only be seen by users who are logged into administrator accounts.

Let’s say we have a secret message for administrators “The prize is behind door number 2”. We don’t want to share this invaluable, secret message with just anyone, we only want our friends who have administrator accounts on our website to be able to see the message.

We can create this functionality easily with WordPress using some of it’s many defined PHP functions. All we have to do are the three lines of code below:

if ( is_admin() ) {
     echo 'The prize is behind door number 2';
}

We can also use this same method with a different function to require the user to be logged in to see the message:

if ( is_user_logged_in() ) {
     echo 'The prize is behind door number 2';
}

We can even use this technique to show the message to a specific user and no one else, for a personalized message or something using the code below:

if ( '3' == get_current_user_id() ) {
     echo 'The prize is behind door number 2.';
}

I hope these three short examples demonstrate to you how powerful WordPress custom code using the pre-defined functions can be. Using a relatively small amount of code, I can extend this functionality to add some really useful new features to my website and so can you. Happy WordPressing!

Categories
Plugin Web Development WordPress

Fixed ChatPress

I installed ChatPress on a website with a new theme today and it looked squished and strange. It was still legible and everything but the whole appearance just looked a little sloppy to me. I’m sure some people would have told me the plugin looked fine and that whether it works or not (which it always did) was more important.

Functionality alone is not enough for me, so I went to work diagnosing the problem and creating a fix. I found that the problems were CSS-related so I went to my scss files, made the changes and recompiled my scss into css so that I could use them for the plugin and voila, it was fixed!

Categories
Web Development

How to Control a Youtube Video with javascript

Last Tested: 11/21/2020

Sometimes a web developer needs to perform this very important control/monitoring functionality. Whether you need to play a video, see if a video has been watched in its entirety or just integrate the embedded youtube video’s functionality into your code for another reason, it can all be done using the youtube API.

The first important (albeit basic) part of using the Youtube API for these functions is that although the video on your page will look like an embed, you are actually putting an empty div on your page with HTML and the Javascript calls the API and replaces that div with the video you specify.

  1. Put the following in the code of your HTML page:
<div id="video-placeholder"></div>

2. Include a javascript file with the following content (but change videoId to the ID of your video):

var player;

function onYouTubeIframeAPIReady() {
    player = new YT.Player('video-placeholder', {
        width: 600,
        height: 400,
        videoId: 'Xa0Q0J5tOP0',
        playerVars: {
            color: 'white',
            playlist: 'taJ60kskkns,FG0fTKAqZ5g'
        },
        events: {
            onReady: initialize
        }
    });
}

function initialize(){

    // Update the controls on load
    updateTimerDisplay();
    updateProgressBar();

    // Clear any old interval.
    clearInterval(time_update_interval);

    // Start interval to update elapsed time display and
    // the elapsed part of the progress bar every second.
    time_update_interval = setInterval(function () {
        updateTimerDisplay();
        updateProgressBar();
    }, 1000)

}

3. Include this code in your html page to get the current duration of the video automatically updated:

// This function is called by initialize()
function updateTimerDisplay(){
    // Update current time text display.
    $('#current-time').text(formatTime( player.getCurrentTime() ));
    $('#duration').text(formatTime( player.getDuration() ));
}

function formatTime(time){
    time = Math.round(time);

    var minutes = Math.floor(time / 60),
    seconds = time - minutes * 60;

    seconds = seconds < 10 ? '0' + seconds : seconds;

    return minutes + ":" + seconds;
}

4. Include this code in your HTML page to add a play button for the video:

$('#play').on('click', function () {

    player.playVideo();

});

5. Include this code in your HTML page to add a pause button for the video:

$('#pause').on('click', function () {

    player.pauseVideo();

});

Disclaimer: I do not work for youtube and so had no involvement whatsoever in the creation of Youtube or it’s excellent API. For more information about using the youtube embed API visit the site listed in my sources for a more in-depth explanation.

Source(s):

  1. https://tutorialzine.com/2015/08/how-to-control-youtubes-video-player-with-javascript
Categories
Web Development

[HowTo] Install Atom, Brew and Node (npm and npx) on Mac

Ok, lets start by saying that I know the title is a lot. It is not just one or two tools that this guide helps you install, it’s all of those tools listed above, plus a few more that are required to run those tools.

But Ben, why not break this guide into several easier-to-manage guides that install one or two tools at a time? Well, I am writing this guide to help with all of those installations, BUT you can start this guide from anywhere and just pick and choose the tools you want.


First, Atom. The atom editor is the easiest of the bunch to install, just go to https://www.atom.io and download it. The website will automatically detect your OS (unless you are on a crazy one or have some kind of unusual configuration). Easy, one step


Next we will go on to installing Brew. At the time of writing this guide, the terminal command to execute is:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

but if that is not working for some reason or you want to troubleshoot, you can go to https://www.brew.sh . Wow, another one-stepper, I guess this guide is shorter than you thought.


Next we will install Node which as noted in the title will allow you to use both the npm and npx commands. For this installation I recommend using a package manager such as Brew and fortunately I just showed you how to install one above. All we have to do for this one is run the command:

brew install node

and you will now be able to use npm, npx and node packages in general. If you want to confirm that node is in fact installed on you computer you can run node -v.


We are just flying through this guide! Next, we will install composer. To be honest, you may not have to use this tool much after today, but let’s just install it anyway because it is a great tool and a requirement for the next step which is installing valet.

Categories
Project Web Development Website

Park Picker

This project is written with PHP, HTML/CSS and JQuery with some light javascript in there too.

I was given a list of parks, tags that relate to them (like dogpark, pond and bike path), the park’s website and a picture of that park; I made all of that information into a JSON file. All of the tags of every park are all listed all together each one time and the user chooses the tags for their ideal park, something that has all of or as many of the tags as possible.

The JQuery then immediately rebuilds the page (without a page refresh) and lists the parks in order of how many tags it has that match the tag criteria as well as gives a grade to each park that shows how many tags.

It’s not a terribly complex project, but it gets an important job done and solves a problem in away that is relatively easy to maintain.

This project can be found on my GitHub at: https://github.com/brothman01/park-picker

Categories
Web Development

How to Install PHP_Codesniffer (phpcs)

Honestly, follow the instructions at this link for the best results: https://github.com/squizlabs/PHP_CodeSniffer

(but the executable path is /usr/bin/phpcs on linux)

I recommend you have composer already to install this but as you can see from their instructions, you can get by without composer (it is just not as simple).

An overview of what you are doing in the instructions:

  1. downloading the phar files.
  2. Using composer to make the codesniffer available globally.
  3. Adding the new phpcs to your PATH system variable
Categories
Web Development WordPress

Introducing WPMonitor!

WP Monitor is a plugin I made to solve a common issue that I had at one of my jobs (and yes this is on the WordPress public repository). WPMonitor is the quick and easy way to manage multiple sites from the dashboard.

WP Monitor makes a dashboard widget that uses javascript libraries and color indicators, creates an at-a-glance health check for your site, telling you how many plugin updates, theme updates, core updates, PHP version, SSL, and lots of other key information for maintaining a WordPress website! The best part is that with a single click you can create a print out or pdf (for a paperless option) to get reports on all 20 of the sites you manage in 2 minutes.

The plugin is free and, as I said, solved a common issue I had at work. Never again spend your time looking for each vital statistic on your WordPress website for maintainance, just use WP Monitor to get the information quickly and easily.