Automate Global IP Banning with Defender and The Hub (for Free!)

Featured Imgs 13

Our new Global IP Banning feature saves you loads of time securing sites. Simply create your IP block and allowlist once, then automatically sync to some or all of your WordPress sites with a few clicks.

A global IP allowlist and blocklist feature has been a top Defender security request for a while. So now…

“I logged into a client site this morning and saw a notification about the new global IP list-banning feature that allows us to sync our IP ban lists across Hub sites. I have raised this request in previous topics with Support and I am sooooooo happy that it has been made live. You guys rock!”

Andre – WPMU DEV Member

It’s here, free to use, and managed directly from your Hub! As you’ll see, it’s easy to quickly apply the same allowlist and blocklist IPs to all of your sites in bulk.

This article will cover:

So, let’s show you how it’s done! First though…

Why Block and Allow IPs?

Just to touch on it quickly, there are many reasons for configuring a WordPress site to allow or block IPs.

For example, maybe you want to monitor online behavior (e.g. to restrict specific web platforms from accessing an educational site). Or, to protect your website from attacks. Also, you may not want a particular country or place to access your online information.

So, there are practical scenarios (like not allowing access to unwanted sites) and security protocols (preventing unwanted or harmful sites or servers from connecting with your network or computer).

Whatever the purpose, allowing and banning IPs should be in your control. With Defender, they are.

Let’s show you how our Defender security plugin makes it easy.

IP Banning and Allowing From The Hub

The Hub makes it easy and simple to create and manage IP Banning.

You can block and allow IP addresses from this area and automatically sync those lists with all or several of your WordPress sites.

The IP Banning section is located in the My Sites menu area.

IP Banning from the Hub.
IP Banning is a click away whenever you need to access it in The Hub.

In this section, you can see your Global Blocklist and Global Allowlist, where you’ll add your IPs.

Global block and allowlist areas.
These are the sections where all of the IPs will be entered.

Simply insert one IP address per line and keep in mind that IPv4 and IPv6 are supported. Plus, IP ranges are also accepted in CIDR or hyphenated format.

The entered IPs.
Once you have your IPs added, click ‘Save.’

Ever want to edit? It’s no problem. You can add and remove IPs at any time!

Selecting Sites to Block and Allow IPs

It’s up to you to determine what sites of yours you want IPs blocked or allowed. So, before syncing IPs with sites, decide what sites you want to associate with IP block and allow lists.

Head to Activate on Site(s) to pick what site you want to include.

Where all of your sites are listed.
All of your sites will be listed here.

After clicking, you’ll see all the available sites to activate global IP banning.

You’ll also be able to see any website that doesn’t have Defender activated and any other issues that would affect syncing.

The sites that can be activated for IP syncing.
Select all in one-click or individually.

If you want, you can search with Filters & Labels when browsing through your websites. There are options for filtering by ‘Hosted with us,’ ‘Hosted elsewhere,’ favorites/non-favorites, and labels.

Plus, you can enter a site title and search relevant sites.

Filters to search by.
Want just sites hosted with us? Click that option to filter and browse those.

When your sites are selected, tap Activate – and that’s it! It takes just a few moments for the sites to be included.

With that being said, it’s time to…

Sync IPs with WordPress Sites

It takes one click to sync your IPs with your WordPress sites. Just tap on the bright blue Sync IPs with Sites, and all the selected sites will be synced.

IPs to sync.
After listing all your IPs, click ‘Save’ before syncing.

A message informing you of what is about to take place will pop up to ensure you’d like to proceed.

Sounds good to still sync? Then click Continue.

Message for syncing.
Click ‘Continue’ will get the sync started.

After hitting Continue, you can sit back and relax as all of your chosen sites are synced with IPs on your blocklist and allowlist! It takes just a few moments.

Global IPs From Defender’s Dashboard

Now that you know how to set up global IPs from The Hub, you can also monitor and sync IPs from Defender’s dashboard.

It’s all accessible by going to Firewall, and IP Banning while in the WordPress admin and Defender.

Defender dashboard for IPs.
You’ll see it synced up here as long as the Block/Allow Global IPs are activated.

After syncing, all the IPs you have entered in The Hub will be in a list.

One thing to note is that you can’t add new IPs from Defender’s dashboard. Simply add them in The Hub and re-sync – and that’s it!

It’s also an area where you can enable and disable the global IP feature anytime.

Allow and Block Global IPs with Ease

As you can see, allowing and blocking global IPs can be done in just a few clicks with Defender and The Hub. It’s never been simpler to control global IPs across any number of sites simultaneously!

If you aren’t using The Hub yet, sign up for free. The same goes for Defender, which also doesn’t cost a thing from wp.org.

And now, blocking and allowing IPs is a breeze!

An Overview of SQL Server Joins

Featured Imgs 23

In this article, we are going to learn about SQL Joins. Also, we will learn the SQL IntelliSence feature and how it is useful. Moreover, I will explain how Devart SQL Complete works and how it is useful to developers who write SQL queries.

The SQL Joins populate the data from different tables by joining them using the common column. There are four types of joins.

Holiday Snowtacular 2022

Category Image 052

We’ve got ourselves a real holiday treat! Join host Alex Trost from the Frontend Horse community for the Holiday Snowtacular 2022 this Friday, December 16.

There’s a lineup of 12 awesome speakers — including Chris Coyier, Cassidy Williams, Kevin Powell, and Angie Jones — each discussing various front-end and web dev topics. It’s like the 12 days of Christmas, but wrapped up in a four-hour session for web nerds like us.

It’s a real good cause, too. The event is free, but includes fundraising Doctors Without Borders with a goal of reaching $20,000. You can donate here any time and anything you give will be matched by the event’s sponors. So, come for the front-end fun and help a great cause in the process.

To Shared LinkPermalink on CSS-Tricks


Holiday Snowtacular 2022 originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

Move An Element from Any Website to CodePen

Category Image 052

Say you like how a particular element on a website looks and interacts. You can pluck it right off that site, HTML and CSS included, and pop it over to CodePen using the plugin CSS Pro. Watch me try it here:

The browser extension is not free, so you’d better be sure you’d use it! Exporting to CodePen is just one of many features. It seems like the core of it is more front-end developer-friendly inspection and alteration of sites.

There used to be a DevTools extension that would do this called SnappySnippet, but that appears to be dead now, so long live CSS Pro!

The post Move An Element from Any Website to CodePen appeared first on CodePen Blog.

A Few Times Container Size Queries Would Have Helped Me Out

Category Image 091

CSS Container Queries are still gaining traction and many of us are getting our hands wet with them, even if it’s for little experiments or whatnot. They’ve got great, but not quite full, browser support — enough to justify using them in some projects, but maybe not to the extent where we might be tempted to start replacing media queries from past projects with shiny new container size queries.

They sure are handy though! In fact, I’ve already run into a few situations where I really wanted to reach for them but just couldn’t overcome the support requirements. If I had been able to use them, this is how it would have looked in those situations.

All of the following demos will be best viewed in Chrome or Safari at the time of this writing. Firefox plans to ship support in Version 109.

Case 1: Card grid

You kind of had to expect this one, right? It’s such a common pattern that all of us seem to run into it at some point. But the fact is that container size queries would have been a huge time-saver for me with a better outcome had I been able to use them over standard media queries.

Let’s say you’ve been tasked with building this card grid with the requirement that each card needs to keep it’s 1:1 Aspect ratio:

A four-by-three grid of card elements as a grayscale mockup.

It’s tougher than it looks! The problem is that sizing a component’s contents on the viewport’s width leaves you at the mercy of how the component responds to the viewport — as well the way any other ancestor containers respond to it. If, for example, you want the font size of a card heading to reduce when the card hits a certain inline size there’s no reliable way to do it.

You could set the font size in vw units, I suppose, but the component is still tied to the browser’s viewport width. And that can cause problems when the card grid is used other in contexts that may not have the same breakpoints.

In my real-world project, I landed on a JavaScript approach that would:

  1. Listen for a resize event.
  2. Calculate the width of each card.
  3. Add an inline font size to each card based on its width.
  4. Style everything inside using em units.

Seems like a lot of work, right? But it is a stable solution to get the required scaling across different screen sizes in different contexts.

Container queries would have been so much better because they provide us with container query units, such as the cqw unit. You probably already get it, but 1cqw is equal to 1% of a container’s width. We also have the cqi unit that’s a measure of a container’s inline width, and cqb for a container’s block width. So, if we have a card container that is 500px wide, a 50cqw value computes to 250px.

If I had been able to use container queries in my card grid, I could have set up the .card component as a container:

.card { 
  container: card / size;
}

Then I could have set an inner wrapper with padding that scales at 10% of the .card‘s width using the cqw unit:

.card__inner { 
  padding: 10cqw; 
} 

That’s a nice way to scale the spacing between the card’s edges and its contents consistently no matter where the card is used at any given viewport width. No media queries required!

Another idea? Use cqw units for the font size of the inner contents, then apply padding in em units:

.card__inner { 
  font-size: 5cqw; 
  padding: 2em;
} 

5cqw is an arbitrary value — just one that I settled on. That padding is still equal to 10cqw since the em unit is relative to the .card__inner font size!

Did you catch that? The 2em is relative to the 5cqw font size that is set on the same container. Containers work different than what we’re used to, as em units are relative to the same element’s font-size value. But what I quickly noticed is that container query units relate to the nearest parent that is also a container.

For example, 5cqw does not scale based on the .card element’s width in this example:

.card { 
  container: card / size; 
  container-name: card; 
  font-size: 5cqw; 
}

Rather, it scales to whatever the nearest parent that’s defined as a container. That’s why I set up a .card__inner wrapper.

Case 2: Alternating layout

I needed yet another card component in a different project. This time, I needed the card to transition from a landscape layout to a portrait layout… then back to landscape, and back to portrait again as the screen gets smaller.

Showing four states of a card element changing between portrait and landscape layouts at various breakpoints.

I did the dirty work of making this component go to portrait at those two specific viewport ranges (shout out to the new media query range syntax!), but again, the problem is that it is then locked to the media queries set on it, its parent, and anything else that might respond to the viewport’s width. We want something that works in any condition without worrying about wondering where the content is going to break!

Container queries would have made this a breeze, thanks to the @container rule:

.info-card {
  container-type: inline-size;
  container-name: info-card;
}

@container info-card (max-width: 500px) {
  .info-card__inner {
    flex-direction: column;
  }
}

One query, infinite fluidity:

But hold on! There’s something you might want to watch out for. Specifically, it could be difficult to use a container query like this within a prop-based design system. For example, this .info-card component could contain child components that rely on props to change their appearance.

Why’s that a big deal? The card’s portrait layout might require the alternate styling but you can’t change JavaScript props with CSS. As such, you risk duplicating the required styles. I actually touched on this and how to work around it in another article. If you need to use container queries for a significant amount of your styling, then you may need to base your entire design system around them rather than trying to shoehorn them into an existing design system that’s heavy on media queries.

Case 3: SVG strokes

Here’s another super common pattern I’ve recently used where container size queries would have resulted in a more polished product. Say you have an icon locked up with a heading:

<h2>
  <svg>
    <!-- SVG stuff -->
  </svg> 
  Heading
</h2>

It’s pretty straightforward to scale the icon with the title’s size, even without media queries. The problem, though, is that the SVG’s stroke-width might get too thin to be noticed all that well at a smaller size, and perhaps catch too much attention with a super thick stroke at a larger size.

I’ve had to create and apply classes to each icon instance to determine its size and stroke width. That’s OK if the icon is next to a heading that’s styled with a fixed font size, I guess, but it’s not so great when working with fluid type that constantly changes.

A lockup of a hexagon icon and heading at three different sizes, from large to small.

The heading’s font size might be based on the viewport’s width, so the SVG icon needs to adjust accordingly where its stroke works at any size. You could make the stroke width relative to the heading’s font-size by setting it in em units. But if you have a specific set of stroke sizes that you need to stick to, then this wouldn’t work because it otherwise scales linearly — there’s no way to adjust it to a specific stroke-width value at certain points without resorting to media queries on the viewport width.

But here’s what I would have done if I had the luxury of container queries at that time:

.icon {
  container: icon / size; 
  width: 1em; 
  height: 1em; 
}

.icon svg {
  width: 100%; 
  height: 100%; 
  fill: none; 
  stroke: #ccc; 
  stroke-width: 0.8; 
}

@container icon (max-width: 70px) {
  .icon svg {
    stroke-width: 1.5; 
  }
}
@container icon (max-width: 35px) {
  .icon svg {
    stroke-width: 3;
  }
}

Compare the implementations and see how the container query version snaps the SVG’s stroke to the specific widths I want based on the container’s width.

Bonus: Other types of container size queries

OK, so I haven’t actually run into this on a real project. But as I was combing through information on container queries, I noticed that there are additional things we can query on a container that are related to the container’s size or physical dimensions.

Most examples I’ve seen query the width, max-width, and min-width, height, block-size, and inline-size as I’ve been doing throughout this article.

@container info-card (max-width: 500px) {
  .info-card__inner {
    flex-direction: column;
  }
}

But MDN outlines two more things we can query against. One is orientation which makes perfect sense because we use it all the time in media queries. It’s no different with container queries:

@media screen (orientation: landscape) { 
  .info-card__inner {
    /* Style away! */
  }
} 

@container info-card (orientation: landscape) { 
  .info-card__inner {
    /* Style away! */
  }
} 

The other? It’s aspect-ratio, believe it or not:

@container info-card (aspect-ratio: 3/2) { 
  .info-card__inner {
    /* Style away! */
  }
} 

Here’s an editable demo to play around with both examples:

I haven’t really found a good use case for either of these yet. If you have any ideas or feel like it could’ve helped you in your projects, let me know in the comments!


A Few Times Container Size Queries Would Have Helped Me Out originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

How to vectorize and speed-up double for-loop for pandas dataframe when doi

558fe5180e0e8fc922d31c23ef84d240

I have the following dataframe:

d_test = {
    'name' : ['South Beach', 'Dog', 'Bird', 'Ant', 'Big Dog', 'Beach', 'Dear', 'Cat', 'Fish', 'Dry Fish'],
    'cluster_number' : [1, 2, 3, 3, 2, 1, 4, 2, 2, 2]
}
df_test = pd.DataFrame(d_test)

I want to identify similar names in name column if those names belong to one cluster number and create unique id for them. For example South Beach and Beach belong to cluster number 1 and their similarity score is pretty high. So we associate it with unique id, say 1. Next cluster is number 2 and three entities from name column belong to this cluster: Dog, Big Dog, Cat, 'Fish' and 'Dry Fish'. Dog and Big Dog have high similarity score and their unique id will be, say 2. For Cat unique id will be, say 3. Finally for 'Fish' and 'Dry Fish' unique id will be, say 4. And so on.

I created a code for the logic above:

# pip install thefuzz
from thefuzz import fuzz

df_test = df_test.sort_values(['cluster_number', 'name'])
df_test.reset_index(drop=True, inplace=True)

df_test['id'] = 0

i = 1
for index, row in df_test.iterrows():
    row_ = row
    index_ = index

    while index_ < len(df_test) and df_test.loc[index, 'cluster_number'] == df_test.loc[index_, 'cluster_number'] and df_test.loc[index_, 'id'] == 0:
        if row['name'] == df_test.loc[index_, 'name'] or fuzz.ratio(row['name'], df_test.loc[index_, 'name']) > 50:
            df_test.loc[index_,'id'] = i
            is_i_used = True
        index_ += 1

    if is_i_used == True:
        i += 1
        is_i_used = False

Code generates expected result:

    name         cluster_number  id
0   Beach               1        1
1   South Beach         1        1
2   Big Dog             2        2
3   Cat                 2        3
4   Dog                 2        2
5   Dry Fish            2        4
6   Fish                2        4
7   Ant                 3        5
8   Bird                3        6
9   Dear                4        7

Computation runs for 210 seconds for dataframe with 1 million rows where in average each cluster has about 10 rows and max cluster size is about 200 rows. I am trying to understand how to vectorize the code.

Also thefuzz module has process function and it allows to process data at once:

from thefuzz import process
out = process.extract("Beach", df_test['name'], limit=len(df_test))

But I don't see if it can help with speeding up the code.

How to Hire a Proofreader for Your Blog

Fotolia Subscription Monthly 4685447 Xl Stock
hire a proofreaderIf you run a blog, it's always a good idea to have a second set of eyes look over articles before you publish them. In this article, we're going to talk about what proofreading involves and when you should consider hiring someone to help you do it. Then, we'll go over some steps to help you hire a proofreader for your blog.

Ukrainian Online Dating – How to Choose a good Site

Featured Imgs 23
Ukrainian online dating sites is a great option for those who are trying to meet solo Slavic women. It has a enormous user base and well-made advantages that will make your dating knowledge unforgettable. There are numerous Ukrainian girls on the web who are curious about finding all their perfect man and want to begin […]

Engineering Manager: Resolving Intrapersonal Conflicts

Featured Imgs 23

In this article, a follow-up to the engineering manager series, we will talk about conflicts, common scenarios, and some tips on how to manage them in a professional environment. Conflict management is a complex topic and we will address it in a series of three articles, the first of which is this one.

People's conflicts are common in the professional day-to-day, some people might even say that conflict is not professional behavior, but of course, it is, as we are human so conflicts are inevitable. What makes the difference is how we manage these situations

Stow: Alacritty

Featured Imgs 23

I’ve been working on Mac for many years with the same terminal: iTerm2. It is well known by the Mac community and not for less, a terminal is not that it has much work to do but the little it has to do, it does it very well (tabs, tmux integration, customization).

The problem comes when we go to another operating system. I recently had the pleasure (and it’s not ironic) of working with the Windows environment and its WSL2, and I went crazy to find something similar.

Secure Shell Protocol: Everything You Need to Know

Featured Imgs 23

Secure shell is a common term often used when studying computer networks. In simple terms, SSH secure shell refers to a secured network protocol that helps access remote computers securely in a network. However, it is much more complicated than it sounds.

So in this blog, we will study all about secure shell protocol. Also, we will explore its working, its concepts, and the mechanisms it leverages for safe remote access. Let us start!

How to Add Custom Code to WordPress

Category Image 091

There are many books and tutorials that share useful code snippets for WordPress. For example, you can find hundreds of custom functions right here at DigWP.com. You can also find them in my WordPress books, tutorials, and code snippets. For many code snippets and custom functions, the usage instructions will say something like:

Add this code to your theme (or child theme’s) functions.php file, or add the code via simple custom plugin.

So what does that actually mean? Let’s take a closer look. First we’ll go through how to add custom code via the functions.php file. Then we’ll explain how to add code by making a simple custom plugin. Finally we’ll wrap things up by explaining the difference between the two methods and how to go further.

Contents

Add custom code via theme functions.php

Every WordPress theme can have a file named functions.php. If present in a theme, the functions file must be located in the root directory of the theme:

/wordpress/
	/wp-content/
		/themes/
			/my-theme/
				functions.php

If the functions file does not exist, create it. Then open the file in a code or text editor and add your custom code. Save the file, upload to the server, and done. It is very straightforward. Just make sure to test any new code on a private/test site before adding to a live production site.

Learn more about building themes in my book, WordPress Themes In Depth.

Add custom code via simple custom plugin

With WordPress, plugins add functionality, and themes display content. There is some overlap (and grey area), but in general the best way to add functionality to WordPress is with a plugin. That’s one reason why there are over 50,000 plugins in the WordPress Plugin Directory.

Plugins range in complexity. They can be very advanced, comprising many files and lots of code. Or they can be very simple, made with one file and a few lines of code. To add a custom code snippet, a simple plugin will suffice.

How to make a simple custom plugin

To make a simple custom plugin, follow these steps:

  1. Create a new PHP file
  2. Name the file whatever makes sense, can be any alphanumeric string (plus dashes and underscores if needed)
  3. Open the file and add the header code provided below
  4. Save the file and done

After creating this file, it is ready for your custom code snippet(s). To save you some time, I’ve created an example plugin that you can download below. It’s ready to go for any custom code that you want to add.

Download a simple custom plugin

Download a copy of our simple custom plugin, ready for your custom code.

Download Simple Custom Plugin (ZIP file < 1 KB)

Usage: Download and unzip the file. Open simple-custom-plugin.php and customize the file header as explained below. Then add your custom code snippet, save changes and done.

Plugin file header

At the beginning of your plugin file, add the following lines:

<?php 
/*
	Plugin Name: Simple Custom Plugin
	Plugin URI: https://digwp.com/2022/02/simple-custom-plugin/
	Description: This is a simple plugin template for adding custom code to WordPress.
	Author: Jeff Starr
	Author URI: https://plugin-planet.com/
	Requires at least: 5.9
	Tested up to: 5.9
	Version: 1.0
*/

if (!defined('ABSPATH')) die();

// add custom code snippets below this line..

You can customize the header lines with your actual information. As our simple plugin is meant only for your site and will not be distributed publicly, the file header can be much simpler than what’s required for plugins destined for the WP Plugin Directory. Learn more about plugin file headers at WordPress.org.

Also: notice this line:

if (!defined('ABSPATH')) die();

That line is included to prevent direct access to the file. It basically checks if WordPress is loaded; if not, the script simply exits. This is a basic security measure to help prevent anyone from meddling with your custom code.

Remember to use code snippets only from trusted sources. And then test the code on a private site before going live.

What’s the difference?

What’s the difference between adding code via theme functions vs. simple plugin? The main difference is scope. When code is added via your theme template, it will run only when the theme is active. So for example, say we add a custom code snippet that displays social media buttons on posts. If we change themes, the custom code will not run, and the buttons will not be displayed.

Contrast that with adding custom code via simple plugin. As long as the plugin is active, the custom code will run always, regardless of which theme you’re using. Going the plugin route also benefits in terms of things like extensibility and maintainability. Managing custom code via plugins generally is easier than burying it within the theme’s functions file.

So which is best? Neither. The two methods are just different. Which one is best for any given code snippet depends on various factors. Most importantly whether or not the custom code is theme specific or global in scope.

For an easy, no-fuss way to add custom code snippets, check out WPCodeBox.

Going further..

The above simple plugin example is the most basic possible. To go further with plugin development, visit the Plugin Developer Handbook at WordPress.org.

Questions and comments welcome! :)