Ben Rothman - WordPress Developer Ben Rothman, Author at ©2023 Ben Rothman, Web Developer - Page 4 of 6

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
Website WordPress

WordPress: WPOptimize

This life-saver plugin adds a button to the dashboard when installed that allows the administrator of the website to perform certain site optimization tasks such as removing old post revisions, minifying images, removing trashed comments and lots more from the comfort of their own dashboard.

Want to optimize the tables in your database? No problem, just install this handy plugin and with no configuration required you can do that with just the click of a button. If you have a WordPress site and want a boost in performance, as long as the issue(s) causing the slowness are not very uncommon and strange, this is the plugin for you.

Categories
WordPress

WordPress 5.4 “Adderly”

Categories
Travel WordCamp WordPress

WordCamp Montreal 2019

This was the last WordCamp I attended before COVID and little did I know but it was just under the wire. I went to this event with my friend Evan who goes with me to many of the fun WordCamp events.

This event was held right nearby where I was staying at the John Molson School of Business building at Concordia University. Aside from having a nice venue, there were interesting talks about the UX, generating revenue, the JAM Stack and much more.

It was cool to visit another country and then to also learn about WordPress, the thing I love. We had friends who lived in the area who knew of some great places to eat and visit. I had a great time, and I hope all of my future WordCamp experiences are that great.

Categories
Project WordPress

Hosted WordPress Site on raspberry pi

I know this is a deviation from my normal posts but I had to say something because I enjoyed this exciting project.

I used a raspberry pi to host a WordPress website on my local network. Granted, this would have been a better announcement if the website was available everywhere, but I just wanted to set up a headless installation of Ubuntu on Raspberry pi, SSH in from one of my other computers and host a website on the pi.

To be honest, technologically this was nothing special I suppose because it was not a complex website but the site I made was not a complex site, but this was an interesting project.

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.

Categories
Project Web Development WordPress

Introducing ChatPress!

Hey everyone! ChatPress is a plugin that I am working on that creates chatrooms on any page that they are put on in a WordPress website. I did not put this in the plugin repository because it is more of a personal project, but it was a lot of fun to create.

The plugin uses asynchronous javascript calls to PHP functions to get every message from the server, separate out the messages for other chatrooms and then post all of those that are left. I definitely recommend checking out this plugin, and it is also on my github if you want to see the code or contribute a new feature!

Categories
Web Development Website WordPress

How to Add a Custom Taxonomy to Users in WordPress

Last Tested: 2/5/2022

This will guide you through setting up a custom taxonomy that you can add to and change whenever you are looking at the profile of a user, it has functions to register, display and save the changes to the taxonomy. In our example we are going to assign each user a department or departments, to later use to give them access to the page or pages for the given department.

/* Step 1 Register the Taxonomy */
Register the taxonomy by placing the function below in your functions.php file or in your plugin file depending on your preference:

function custom_user_taxonomy() {

  $labels = array(
    'name'                       => _x( 'Departments', 'Departments Name', 'text_domain' ),
    'singular_name'              => _x( 'Department', 'Department Name', 'text_domain' ),
    'menu_name'                  => __( 'Departments', 'text_domain' ),
    'all_items'                  => __( 'All Departments', 'text_domain' ),
    'parent_item'                => __( 'Parent Department', 'text_domain' ),
    'parent_item_colon'          => __( 'Parent Department:', 'text_domain' ),
    'new_item_name'              => __( 'New Department Name', 'text_domain' ),
    'add_new_item'               => __( 'Add Department', 'text_domain' ),
    'edit_item'                  => __( 'Edit Department', 'text_domain' ),
    'update_item'                => __( 'Update Department', 'text_domain' ),
    'view_item'                  => __( 'View Department', 'text_domain' ),
    'separate_items_with_commas' => __( 'Separate department with commas', 'text_domain' ),
    'add_or_remove_items'        => __( 'Add or remove departments', 'text_domain' ),
    'choose_from_most_used'      => __( 'Choose from the most used', 'text_domain' ),
    'popular_items'              => __( 'Popular Departments', 'text_domain' ),
    'search_items'               => __( 'Search Departments', 'text_domain' ),
    'not_found'                  => __( 'Not Found', 'text_domain' ),
    'no_terms'                   => __( 'No departments', 'text_domain' ),
    'items_list'                 => __( 'Departments list', 'text_domain' ),
    'items_list_navigation'      => __( 'Departments list navigation', 'text_domain' ),
  );
  $args = array(
    'labels'                     => $labels,
    'hierarchical'               => true,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
    'show_tagcloud'              => true,
  );
  register_taxonomy( 'departments', 'user', $args );

}
add_action( 'init', 'custom_user_taxonomy', 0 );

Step 2: Add the Admin page for the custom Taxonomy by adding the code below to your functions.php file or to a plugin file. We will add this page as a sub-item of the Users menu on the WordPress dashboard. This page will allow us to define the different more specific departments that will be options in our custom taxonomy like ‘Sales’ and ‘IT’. Don’t forget to actually add those departments to the taxonomy or no choices will be rendered:

/**
* Admin page for the 'departments' taxonomy
*/
function cb_add_departments_taxonomy_admin_page() {

 $tax = get_taxonomy( 'departments' );

 add_users_page(
esc_attr( $tax->labels->menu_name ),
esc_attr( $tax->labels->menu_name ),
$tax->cap->manage_terms,
'edit-tags.php?taxonomy=' . $tax->name
 );

}
add_action( 'admin_menu', 'cb_add_departments_taxonomy_admin_page' );

/* Step 3 */

As the next step we are going to add the code below to… you guessed it, the functions.php file or a plugin file. The code below is going to add the taxonomy we defined in the previous steps to the profile of every user so that we can set each user’s department.

function cb_edit_user_department_section( $user ) {
  global $pagenow;

  $tax = get_taxonomy( 'departments' );

  /* Make sure the user can assign terms of the departments taxonomy before proceeding. */
  if ( !current_user_can( $tax->cap->assign_terms ) )
    return;

  /* Get the terms of the 'departments' taxonomy. */
  $terms = get_terms( 'departments', array( 'hide_empty' => false ) ); ?>

  <h3><?php _e( 'Departments' ); ?></h3>

  <table class="form-table">

    <tr>
      <th><label for="departments"><?php _e( 'Allocated Departments' ); ?></label></th>

      <td><?php

      /* If there are any departments terms, loop through them and display checkboxes. */
      if ( !empty( $terms ) ) {
          echo cb_custom_form_field('departments', $terms, $user->ID);
      }

      /* If there are no departments terms, display a message. */
      else {
        _e( 'There are no departments available.' );
      }

      ?></td>
    </tr>

  </table>
<?php }

add_action( 'show_user_profile', 'cb_edit_user_department_section' );
add_action( 'edit_user_profile', 'cb_edit_user_department_section' );
add_action( 'user_new_form', 'cb_edit_user_department_section' );

/* Step 4 */
Define the function for saving the custom taxonomy by putting this code into… well the functions.php file or a plugin file. You probably get that by now but the code below does define that function:

/**
 * @param int $user_id The ID of the user to save the terms for.
 */
function cb_save_user_department_terms( $user_id ) {

  $tax = get_taxonomy( 'departments' );

  /* Make sure the current user can edit the user and assign terms before proceeding. */
  if ( !current_user_can( 'edit_user', $user_id ) && current_user_can( $tax->cap->assign_terms ) )
    return false;

  $term = $_POST['departments'];
  $terms = is_array($term) ? $term : (int) $term; // fix for checkbox and select input field

  /* Sets the terms (we're just using a single term) for the user. */
  wp_set_object_terms( $user_id, $terms, 'departments', false);

  clean_object_term_cache( $user_id, 'departments' );
}

add_action( 'personal_options_update', 'cb_save_user_department_terms' );
add_action( 'edit_user_profile_update', 'cb_save_user_department_terms' );
add_action( 'user_register', 'cb_save_user_department_terms' );

That was it! Four steps to add this awesome functionality. This data stored per user is very useful for having different types or tiers of users that have access to special content that is hidden from everyone else. Happy WordPressing!

Categories
Travel WordCamp WordPress

WordCamp US 2018

Nashville Part II

Nashville is awesome, this is the second year that I have been able to come here for WordCamp US. I was here for the event last year but this year my friend Evan came with me and it was a lot of fun. There were some great talks on Gutenberg and ARIA which I found very interesting. Obviously this is not how I SHOULD be judging this event but the food they gave for lunch was simply amazing.

In addition to the WordCamp which was very cool and interesting, being in Nashville was fun. The people are nice there and the food was amazing. I have to give a shout out to Hattie B’s (not that they even need shoutouts because they offer such a great product) but I went there and got hot chicken, a nice cold beer and some mac and cheese that would amaze even someone who doesn’t like that stuff.

The State of the Word (delivered every year by one of the founders of WordPress, Matt Mullenweg, was great as usual and instructed us to continue learning more about Gutenberg and the cool functionality it brings.

Categories
WordPress

WordPress 5.0 “Bebo”

Say Hello to the New Editor

https://youtube.com/watch?v=72xdCU__XCk%3Fversion%3D3%26rel%3D1%26showsearch%3D0%26showinfo%3D1%26iv_load_policy%3D1%26fs%3D1%26hl%3Den-US%26autohide%3D2%26wmode%3Dtransparent

We’ve made some big upgrades to the editor. Our new block-based editor is the first step toward an exciting new future with a streamlined editing experience across your site. You’ll have more flexibility with how content is displayed, whether you are building your first site, revamping your blog, or write code for a living.