A font-display setting for slow connections

Featured Imgs 25

Me, I really dislike FOUT. I like that it’s an option, because not displaying text quickly on the web is no good. I know font-display: swap; is popular because it’s good for performance, but that FOUT stuff pains me. Matt Hobbs:

If there’s one thing I’d like readers to take away from this post it’s that font-display: swap is a very good option for users with a fast internet connection. But its infinite swap period could be frustrating for users on very slow and unstable connections. If you have users viewing your site under these conditions (I’m pretty certain you will at some point in time), then it may be worth considering font-display: fallback or even font-display: optional.

Seeeee, I told ya. I like how font-display: optional; totally stops FOUT. The font is either applied super fast, or isn’t used at all (but still downloaded async). Chances are, on the next page load, the font is loaded and cached and will be used.

Note this is about slow connections, not necessarily connections where the user would prefer as little data usage as possible. If that’s the case, check out some of the recent posts we linked up in Responsible, Conditional Loading.


And boy howdy, the Web Performance Calendar this year was just loaded in great articles.

Direct Link to ArticlePermalink


The post A font-display setting for slow connections appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.

GMT time conversion to Unix epoch

558fe5180e0e8fc922d31c23ef84d240

I am trying to convert the GMT time into unix epoch (starting from 1970), looks like there is a small bug
in code , i could not get and exhausted.

I see following difference

Non leap years
Expected output: Jan 20 19:00:01 2019 GMT = 1548010801
Actual output: 1548097201 (which is Jan 21 19:00:01 2019 GMT, 1 day difference)

Leap Year
Expected output: Dec 27 14:52:30 2020 GMT = 1609080750

Actual output: 1609253550 (which is Dec 29 14:52:30 2020 GMT, 2 days difference)

I really appreciate any help in finding the problem.

`
#include <stdio.h>
#include <string.h>
#include <time.h>

#define BASE_YEAR 1970

void print_time_readable_format(struct tm tm);
int convert_gmt_date_time_to_tm_format(char* gmt_time_fmt);
int check_year_is_leap_or_normal(int year);
int get_number_of_leap_years_from_base_year(int start_year, int end_year);
int convert_gmt_to_epoch(struct tm tm);

int main()
{
    int epoch = 0;
    //char gmt_time_fmt[] = "Jan 20 19:00:01 2019 GMT";
    //char gmt_time_fmt[] = "Dec 27 14:52:30 2020 GMT";
    char gmt_time_fmt[] = "Jan 01 00:00:00 1970 GMT";
    epoch = convert_gmt_date_time_to_tm_format(gmt_time_fmt);
    printf("time in GMT = %s and epoch is %d\n", gmt_time_fmt, epoch);

    return 0;
}

int convert_gmt_date_time_to_tm_format(char* gmt_time_fmt)
{
    struct tm tm;
    char tm_time_fmt[255];

    //set tm struture to 0
    memset(&tm, 0, sizeof(struct tm));
    // convert gmt_time_fmt to format required by 'tm' structure
    strptime(gmt_time_fmt, "%B %d %H:%M:%S %Y GMT", &tm);

    strftime(tm_time_fmt, sizeof(tm_time_fmt), "%s", &tm);
    printf("tm_time_fmt = %s\n", tm_time_fmt);

    print_time_readable_format(tm);

    return convert_gmt_to_epoch(tm);

    return 0;
}

int convert_gmt_to_epoch(struct tm tm)
{
    int days_by_month [2][12] = {
        /* normal years */
        { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
        /* leap years */
        { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
    };

    int current_year = tm.tm_year+1900;

    printf("current_year =%d\n", current_year);

    int total_years_passed = current_year - BASE_YEAR;

    printf("total_years_passed =%d\n", total_years_passed);

    int nleap_years_passed = get_number_of_leap_years_from_base_year(BASE_YEAR, current_year);

    int normal_years = total_years_passed - nleap_years_passed;

    printf("normal_years =%d\n", normal_years);

    int total_days_passed = (normal_years*365 + nleap_years_passed*366 );

    printf("total_days_passed =%d\n", total_days_passed);

    total_days_passed += days_by_month[check_year_is_leap_or_normal(current_year)][tm.tm_mon];

    printf("total_days_passed after adding month =%d\n", total_days_passed);

    total_days_passed += tm.tm_mday;

    printf("total_days_passed after adding day =%d\n", total_days_passed);

    total_days_passed  = total_days_passed*24 + tm.tm_hour;
    total_days_passed  = total_days_passed*60 + tm.tm_min;
    total_days_passed  = total_days_passed*60 + tm.tm_sec;

    printf("total_days_passed final =%d\n", total_days_passed);

    return total_days_passed;

}

int get_number_of_leap_years_from_base_year(int start_year, int end_year)
{
    int leap_year_count = 0;
    int year = start_year;

    while( year <= end_year)
    {
        if(check_year_is_leap_or_normal(year))
            leap_year_count++;
        year++;
    }

    printf("leap_year_count = %d\n", leap_year_count);

    return leap_year_count;
}

int check_year_is_leap_or_normal(int year)
{
    if( ( year%4 == 0 ) && ( ( year%400 == 0 ) || ( year%100 != 0)))
         return 1;
    else
        return 0;
}

void print_time_readable_format(struct tm tm)
{
    printf("tm.tm_year = %d ", tm.tm_year);
    printf("tm.tm_mon = %d ", tm.tm_mon);
    printf("tm.tm_mday = %d ",tm.tm_mday);
    printf("tm.tm_hour = %d ", tm.tm_hour); 
    printf("tm.tm_min = %d ", tm.tm_min );
    printf("tm.tm_sec = %d\n", tm.tm_sec );
}
`

Top 10 APIs for Museums

Featured Imgs 23

It seems that almost every discipline imaginable is undergoing a digital transformation these days. That includes the art, science, and culture world of museums.

Connecting 2 outers to the same CPU

Category Image 041

Hi, the DSL had intermittent problem. The service provider came and fixed the problem.

As a result of the brief problem, my Netgear N600 WIFI Range Extender ceased connecting to the Internet via WIFI DSL modem (internet light won't turn on). I have done all the requirements including factory reset, power off, etc. to no avail. My other wireless devices(cell phones) which use to operate normally with the Netgear are unable to communicate to the Netgear either.

My Desktop CPU has only 1 Ethernet port which I currectly use to connect the CPU to the DSL. I am unable to connect the Netgear to the CPU as well.

Please advise. Thank you.

A Calendar in Three Lines of CSS

Category Image 052

This article has no byline and is on a website that is even more weirdly specific than this one is, but I appreciate the trick here. A seven-column grid makes for a calendar layout pretty quick. You can let the days (grid items) fall onto it naturally, except kick the first day over to the correct first column with grid-column-start.

Thoughts:

  • I’d go with an <ol> rather than a <ul> just because it seems like days are definitely ordered.
  • The days as-a-list don’t really bother me since maybe that makes semantic sense to the content of the calendar (assuming it has some)
  • But… seeing the titles of the days-of-the-week as the first items in the same list feels weird. Almost like that should be a separate list or something.
  • Or maybe it should all just be a <table> since it’s sort of tabular data (it stands to reason you might want to cross-reference and look at all Thursdays or whatever).

Anyway, the placement trickery is fun.

Here’s another (similar) approach from our collection of CSS Grid starter templates.

Direct Link to ArticlePermalink


The post A Calendar in Three Lines of CSS appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.

How to Add Additional User Profile Fields in WordPress Registration

Category Image 091

Do you want to add extra profile fields for users to fill in when they register on your WordPress website?

Maybe you want to allow users to submit their social media profiles. Or you might want them to submit their business phone number when registering. This can all be done by adding additional profile fields.

In this article, we will show how to easily add additional user profile fields in WordPress registration forms.

Adding additional user profile fields in WordPress registration

Why Add Additional User Profile Fields in WordPress Registration?

By adding more user profile fields to your WordPress website’s registration form, you can collect extra information from users to improve your marketing campaigns, personalize content, or simply learn more about your audience.

For example, you can ask your users to provide their phone numbers or social media profiles when registering on your WordPress site.

This way, you will be able to send targeted SMS messages to your users or can ask them to promote your WordPress blog on their social media accounts.

All of these extra fields can be handy if you run a membership website or allow users to sign up as subscribers to your blog. They can also be helpful if you want to store extra contact information for the other writers on your multi-author blog.

That being said, let’s see how to easily add additional user profile fields in WordPress. For this tutorial, we will be discussing two methods, and you can use the links below to jump to the method of your choice:

Method 1: Add Custom User Profile Fields Using Advanced Custom Fields (Recommended)

The best way to add extra user profile fields in WordPress is to use the Advanced Custom Fields plugin. It lets you choose from multiple fields and customize them to fit your needs.

First, you need to install and activate the Advanced Custom Fields plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, you need to head to the ACF » Field Groups page from the WordPress admin sidebar and click the ‘+ Add Field Group’ button.

Click the Add Field Group button

This will take you to a new page where you can start by typing a name for the field group.

Keep in mind that this will be the name of the entire field group and not the individual user’s field.

Type field group name

After that, scroll down to the ‘Fields’ section and choose a field type from the dropdown menu.

For example, if you want users to provide their phone number upon registration, then you can choose the ‘Number’ option. Alternatively, if you want users to provide their social media profiles, then you can pick the ‘Text’ option.

Choose a field type from the dropdown menu

Once you have done that, just type the name of your field into the ‘Field Label’ option. For instance, if you want users to provide their Twitter handle before registering, then you can enter that into the field.

The plugin will then automatically generate a field name according to your label name.

Add field name and label

Next, you must switch to the ‘Validation’ tab from the top. From here, you can make the field required by toggling on the switch. This way, users won’t be able to register on your WordPress site without filling in the additional field.

After that, you can even set a character limit for your custom field.

Toggle the Required switch for the additional field

Now, switch to the ‘Presentation’ tab from the top.

Once you are there, you can add placeholder text, instructions, and wrapper attributes for your additional user profile field.

Configure the Presentation settings

Next, scroll down to the ‘Settings’ section and make sure that the ‘Location Rules’ tab is selected. From here, you must set up conditional logic for your custom field so that it will only be displayed for your WordPress site registration.

To do this, select the ‘User Form’ option from the dropdown menu in the left corner of the screen. After that, choose the ‘Register’ option from the dropdown menu in the right corner.

Add conditional logic for the additional user field

Finally, click the ‘Save Changes’ button at the top of the screen to store your settings.

If you want to add another additional field, then you can also click the ‘+ Add Field’ button.

Save the additional field

Now visit your user registration page to view the additional user profile field in action.

This is how it looked on our demo website.

Preview for additional user profile field

Method 2: Add Additional User Profile Fields With Profile Extra Fields (Easy & Simple)

This method allows you to quickly and easily add extra fields to user profiles and user registration forms in WordPress. It is a little less flexible, but it gets the job done.

First, you need to install and activate the Profile Extra Fields plugin. If you are not sure how to do this, then you can check out our full guide on how to install a WordPress plugin.

Once the plugin is activated, it’s time to create some additional user profile fields to use on your registration forms.

We are going to create a phone number field as an example, but you can add as many of these fields as you want.

First, visit the Profile Extra Fields » Add New page from the WordPress admin sidebar. From here, type the name of the field next to the ‘Name’ option.

For example, if you are creating a field for users to submit their phone number, then you can type ‘Phone Number’ as the field name.

After that, select a field type from the dropdown menu. If you are adding a social media profile field, then you can use the ‘Text Field’ option.

However, if you want a field for phone numbers, then you need to select that option from the dropdown menu.

Add field name and type

After that, you can also type a pattern for your phone number field or add a description for it.

Next, scroll down to the ‘Field Properties’ section and check the boxes for the user roles that you want this field to be displayed for.

For instance, if you want this field to be displayed for all the authors registering on your WordPress site, then you can check the box next to this user role.

You can choose as many user roles as you want.

Configure field properties

Next, you can also check the ‘Required’ box if you don’t want users to register without filling in this field in the form. Make sure that the ‘Always Show in User Registration Form’ box is checked so that your user field will be displayed in the form.

Finally, click the ‘Save Changes’ button to store your settings.

Check the box to show the field in user registration form

Now, you will need to go into your WordPress dashboard to change some settings for new registrations.

Head to the Settings » General page in your WordPress admin area and then check the membership box so that anyone can register on your website.

Next, you need to make sure that the default role is set to the role which you have added extra fields for. After that, click the ‘Save Changes’ button to store your settings.

Set user default role

This way, you can control the level of access new users have, and this will force the registration form to show the fields you selected earlier in this tutorial.

Here’s what the default registration form looked like on our demo website.

Preview for the user field in registration form

Bonus: Make a Custom User Registration Form in WordPress

The methods in this tutorial have shown you how to add extra user profile fields to the default WordPress registration form.

However, if you would like to create a custom user registration form in WordPress, then you can also easily do that by using the WPForms plugin.

It is the best WordPress form plugin that allows you to design your own user registration form using drag and drop. It also integrates seamlessly with plugins like Advanced Custom Fields, so you can easily insert additional user profile fields.

Edit user registration form

For detailed instructions, please follow our tutorial on how to create a custom user registration form in WordPress.

We hope this tutorial helped you learn how to add additional user profile fields in WordPress registration. You may also want to see our beginner’s guide on how to create a custom WordPress login page and our comparison of the best WordPress membership plugins to create and sell courses.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Add Additional User Profile Fields in WordPress Registration first appeared on WPBeginner.

“Yes or No?”

Category Image 052

Sara Soueidan digs into this HTML/UX situation. “Yes” or “no” is a boolean situation. A checkbox represents this: it’s either on or off (uh, mostly). But is a checkbox always the best UX? It depends, of course:

Use radio buttons if you expect the answer to be equally distributed. If I expect the answer to be heavily biased to one answer I prefer the checkbox. That way the user either makes an explicit statement or just acknowledges the expected answer.

If you want a concrete, deliberate, explicit answer and don’t want a default selection, use radio buttons. A checkbox has an implicit default state. And the user might be biased to the default option. So having the requirement for an explicit “No” is the determinig factor.

So you’ve got the checkbox approach:

<label>
  <input type="checkbox">
  Yes?
</label>

Which is nice and compact but you can’t make it “required” (easily) because it’s always in a valid state.

So if you need to force a choice, radio buttons (with no default) are easier:

<label>
  <input type="radio" name="choice-radio">
  Yes
</label>
<label>
  <input type="radio" name="choice-radio">
  No
</label>

I mean, we might as well consider another a range input too, which can function as a toggle if you max it out at 1:

<label class="screen-reader-only" for="choice">Yes or No?</label>
<span aria-hidden="true">No</span>
<input type="range" max="1" id="choice" name="choice">
<span aria-hidden="true">Yes</span>

Lolz.

And I suppose a <select> could force a user choice too, right?

<label>
  Yes or no?
  <select>
    <option value="">---</option>
    <option value="">Yes</option>
    <option value="">No</option>
  </select>
</label>

I weirdly don’t hate that only because selects are so compact and styleable.

If you really wanna stop and make someone think, though, make them type it, right?

<label>
  Type "yes" or "no"
  <input type="text" pattern="[Yy]es|[Nn]o">
</label>

Ha.


The post “Yes or No?” appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.

Voice Search and What It Means for Your WordPress Site

Featured Imgs 26

From as early as 2016, experts have been predicting that voice searches will eventually make up a significant percentage of Google searches worldwide. Now that more people are using smart devices such as Google Home, Alexa, and Siri at home, voice search capability is becoming less of a novelty and more of a must-have for […]

The post Voice Search and What It Means for Your WordPress Site appeared first on WPExplorer.

​Sendbird Announces Chat Platform Enhancements

Featured Imgs 23

Sendbird, a chat and messaging services provider, has announced several updates to its chat offerings that the company hopes will allow developers to better adapt to a communication environment that has been reshaped by COVID-19. These Updated include new partitioning options for Open Channels, IP whitelisting, and message threading.