How to Disable Plugin Updates in WordPress and Why You Shouldn’t

Recently, one of our readers asked if it was possible to disable plugin updates in WordPress? Plugin updates can be disabled in WordPress, but there is no good reason to do that. In this article, we will show you how to disable plugin updates in… Read More »

The post How to Disable Plugin Updates in WordPress and Why You Shouldn’t appeared first on WPBeginner.

Recently, one of our readers asked if it was possible to disable plugin updates in WordPress? Plugin updates can be disabled in WordPress, but there is no good reason to do that. In this article, we will show you how to disable plugin updates in WordPress. We will also discuss why you shouldn’t do that and what could be the consequences of doing so.

How to Disable Plugin Updates in WordPress

Why You Shouldn’t Disable Plugin Updates in WordPress?

Many WordPress users think that plugin updates can break their site. If you are using the best WordPress plugins with a standard compliant WordPress theme, then chances of an upgrade breaking your site are very low.

See our beginner’s guide on how to choose the best WordPress plugins for your site. For themes, you may want to see our checklist of 9 things you should consider when selecting the perfect WordPress theme.

Plugin updates not only offer new features, they also patch security vulnerabilities, improve performance, and fix compatibility issues with latest or upcoming versions of WordPress.

By not updating plugins, you are intentionally compromising security and stability of your WordPress site.

Some developers want to disable plugin updates on clients sites to prevent them from breaking their websites. It is not a good reason in most cases because most client relationships don’t last forever. In that case you hand your clients a website susceptible to vulnerabilities in future.

We believe it’s simply better to educate your clients.

If you still must disable plugin updates on your site, then here is how you would do that.

Disable All Plugin Updates in WordPress

First thing you need to do is install and activate the Easy Updates Manager plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Dashboard » Update Options to manage plugin settings.

Click on the ‘General’ tab and scroll down to ‘All Plugin Updates’ option. Click on ‘Disabled’ to turn off all plugin updates.

Disable all plugin updates in WordPress

Don’t forget to click on the save changes button to store your settings.

Selectively Disable Updates for Specific Plugins in WordPress

You can also selectively disable updates for some WordPress plugins. This is a little better option than disabling all plugin updates.

You need to visit Dashboard » Update Options page and click on the ‘Plugins’ tab. There you will see a list of all installed plugins on your WordPress site.

Disallow updates for a specific plugin

You can just click on ‘Disallow Updates’ below a plugin to disable updates for that specific plugin.

Easy Updates Manager allows you to manage all WordPress updates including core, plugin, theme, and translation updates. See our guide on how to better manage automatic WordPress updates for detailed instructions.

We hope this article helped you learn how to disable plugin updates in WordPress and why you shouldn’t do that. You may also want to see our guide on how to hide unnecessary items from WordPress admin with Adminimize.

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 Disable Plugin Updates in WordPress and Why You Shouldn’t appeared first on WPBeginner.

Giveaway: Win a Free Copy of WPForms – WordPress Form Plugin

In the past, we have done several giveaways on WPBeginner and there’s been an overwhelming amount of requests from a lot of you to do more of them. Today, we’re proud to announce an amazing giveaway of our fast growing plugin, WPForms. This giveaway will… Read More »

The post Giveaway: Win a Free Copy of WPForms – WordPress Form Plugin appeared first on WPBeginner.

In the past, we have done several giveaways on WPBeginner and there’s been an overwhelming amount of requests from a lot of you to do more of them. Today, we’re proud to announce an amazing giveaway of our fast growing plugin, WPForms. This giveaway will allow 10 lucky users to win a Pro license of WPForms – drag & drop form builder (value $199).

Winners will be selected on Wednesday, July 6th, 2016.

What exactly do you win? (WPForms Pro)

WPForms

10 lucky users will win the pro license of WPForms – the most user friendly WordPress form plugin.

The pro license is worth $199 each and comes with:

Drag & drop form builder, pre-made form templates, smart conditional logic, powerful notification system, entry management system, file uploads, multi-page forms, and all available addons (User registration, MailChimp, AWeber, PayPal, Stripe, GetResponse, Campaign Monitor, etc).

See the list of all features.

Whether you want to create a contact form, donation form, or a newsletter form, you can do it with WPForms.

How to Win?

In the past, we have had many winners who enter the contest and never claim the prize. This is unfair to all those who really wanted to win.

To mitigate that issue, we’re trying a new concept, so only those who’re serious about using the plugin will win.

To enter the giveaway, you need to:

1. Install the WPForms Lite Plugin on your site (100% free).

2. Inside, you will see a notice directing you to the Rafflecopter widget for entering the giveaway.

If you accidentally dismiss the notice, you can access it by going to this link:

yoursite.com/wp-admin/admin.php?page=wpforms-giveaway

Simply replace yoursite.com with your own domain.

That’s all.

Winners will be selected on Wednesday, July 6th, 2016.

This new giveaway format will also allow you to try out WPForms to see why we believe it’s the most beginner friendly WordPress contact form plugin.

To learn more about WPForms, you can watch the overview video below:

All winners are chosen randomly using the Rafflecopter widget. We will notify the winners on July 6th, 2016 via email.

Thank you for following WPBeginner.

The post Giveaway: Win a Free Copy of WPForms – WordPress Form Plugin appeared first on WPBeginner.

.NET Core 1.0 is now released!

Code .NET in the Cloud!

I feel like it’s the culmination of all these years of work in .NET and Open Source. This is why I came to work at Microsoft; we wanted to open source as much as we could and build a community around .NET and open source at Microsoft. 15 years and the work of thousands of people later, today we released .NET Core 1.0.

Take a moment and head over to http://dot.net and check out the download page. It’s got a really nice place you can try out C# directly in the browser without having to install anything! There’s also a great C# Tutorial with interactive browser-based tools as well.

.NET Core 1.0 runs on Windows, Mac, and several flavors of Linux including RedHat Enterprise Linux and Ubuntu. It supports C#, VB, and F# and modern constructs like generics, Language Integrated Query (LINQ), async support and more. The Core Runtime, libraries, compiler, languages and tools are all open source on GitHub where contributions are accepted, tested and fully supported.

Getting started with .NET Core

What is .NET Core? Here’s some details from the .NET Blog:

.NET Core is a new cross-platform .NET product. The primary points of .NET Core are:

  • Cross-platform: Runs on Windows, macOS and Linux.
  • Flexible deployment: Can be included in your app or installed side-by-side user- or machine-wide.
  • Command-line tools: All product scenarios can be exercised at the command-line.
  • Compatible: .NET Core is compatible with .NET Framework, Xamarin and Mono, via the .NET Standard Library.
  • Open source: The .NET Core platform is open source, using MIT and Apache 2 licenses. Documentation is licensed under CC-BY. .NET Core is a .NET Foundation project.
  • Supported by Microsoft: .NET Core is supported by Microsoft, per .NET Core Support

.NET Core is composed of the following parts:

  • A .NET runtime, which provides a type system, assembly loading, a garbage collector, native interop and other basic services.
  • A set of framework libraries, which provide primitive data types, app composition types and fundamental utilities.
  • A set of SDK tools and language compilers that enable the base developer experience, available in the .NET Core SDK.
  • The ‘dotnet’ app host, which is used to launch .NET Core apps. It selects and hosts the runtime, provides an assembly loading policy and launches the app. The same host is also used to launch SDK tools in the same way.

Blogs

Here are the major blogs carrying the announcement.

We are also releasing .NET documentation today at docs.microsoft.com, the new documentation service for Microsoft. The documentation you see there is just a start. You can follow our progress at core-docs on GitHub. ASP.NET Core documentation is also available and open source.

Have fun!


Sponsor: Build servers are great at compiling code and running tests, but not so great at deployment. When you find yourself knee-deep in custom scripts trying to make your build server do something it wasn’t meant to, give Octopus Deploy a try.


© 2016 Scott Hanselman. All rights reserved.
     
Code .NET in the Cloud!

I feel like it's the culmination of all these years of work in .NET and Open Source. This is why I came to work at Microsoft; we wanted to open source as much as we could and build a community around .NET and open source at Microsoft. 15 years and the work of thousands of people later, today we released .NET Core 1.0.

Take a moment and head over to http://dot.net and check out the download page. It's got a really nice place you can try out C# directly in the browser without having to install anything! There's also a great C# Tutorial with interactive browser-based tools as well.

.NET Core 1.0 runs on Windows, Mac, and several flavors of Linux including RedHat Enterprise Linux and Ubuntu. It supports C#, VB, and F# and modern constructs like generics, Language Integrated Query (LINQ), async support and more. The Core Runtime, libraries, compiler, languages and tools are all open source on GitHub where contributions are accepted, tested and fully supported.

Getting started with .NET Core

What is .NET Core? Here's some details from the .NET Blog:

.NET Core is a new cross-platform .NET product. The primary points of .NET Core are:

  • Cross-platform: Runs on Windows, macOS and Linux.
  • Flexible deployment: Can be included in your app or installed side-by-side user- or machine-wide.
  • Command-line tools: All product scenarios can be exercised at the command-line.
  • Compatible: .NET Core is compatible with .NET Framework, Xamarin and Mono, via the .NET Standard Library.
  • Open source: The .NET Core platform is open source, using MIT and Apache 2 licenses. Documentation is licensed under CC-BY. .NET Core is a .NET Foundation project.
  • Supported by Microsoft: .NET Core is supported by Microsoft, per .NET Core Support

.NET Core is composed of the following parts:

  • A .NET runtime, which provides a type system, assembly loading, a garbage collector, native interop and other basic services.
  • A set of framework libraries, which provide primitive data types, app composition types and fundamental utilities.
  • A set of SDK tools and language compilers that enable the base developer experience, available in the .NET Core SDK.
  • The ‘dotnet’ app host, which is used to launch .NET Core apps. It selects and hosts the runtime, provides an assembly loading policy and launches the app. The same host is also used to launch SDK tools in the same way.

Blogs

Here are the major blogs carrying the announcement.

We are also releasing .NET documentation today at docs.microsoft.com, the new documentation service for Microsoft. The documentation you see there is just a start. You can follow our progress at core-docs on GitHub. ASP.NET Core documentation is also available and open source.

Have fun!


Sponsor: Build servers are great at compiling code and running tests, but not so great at deployment. When you find yourself knee-deep in custom scripts trying to make your build server do something it wasn't meant to, give Octopus Deploy a try.



© 2016 Scott Hanselman. All rights reserved.
     

How to Create a Multilingual WordPress Site with WPML

Do you want to make your website available in multiple languages? By default, WordPress does not come with features required to create a proper multilingual site. That’s why in this tutorial, we will show you how to create a multilingual WordPress site with the popular… Read More »

The post How to Create a Multilingual WordPress Site with WPML appeared first on WPBeginner.

Do you want to make your website available in multiple languages? By default, WordPress does not come with features required to create a proper multilingual site. That’s why in this tutorial, we will show you how to create a multilingual WordPress site with the popular WPML plugin.

Creating multilingual WordPress site with WPML

Why Create a Multilingual WordPress Site Using WPML?

You can use WordPress in any language that you want. It is super easy to create a website in any single language.

Most popular WordPress themes and plugins are also translation ready which makes it easy for anyone in the world to start a WordPress site in their language.

However, by default WordPress can support only one language at a time. What if you wanted to use multiple languages on a site to attact a much wider audience?

Governments, international businesses, and educational institutes often need to offer their website in multiple languages. While machine translations like Google Translate is an option, it’s often not acceptable for most professional organization.

One way to offer multiple language options is to install WordPress in subdomains for each language. This is a lot of hassle, as you will have to manage updates, and backup all those installations.

WPML (WordPress Multilingual Plugin) solves this problem by allowing your website to become multilingual. You can use the same WordPress installation to create content into many different languages.

It offers an easy to use interface for managing translations. It also adds language switching options for your users.

Having said that, let’s see how you can create a multilingual WordPress website with WPML in minutes.

Creating a Multilingual WordPress Site with WPML

First thing you need to do is install and activate the WPML (WordPress Multi-language) plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Note: WPML is a paid plugin, but it’s by far the most comprehensive option. There is a reason why over 400,000 websites use WPML for creating a multilingual WordPress site.

Upon activation, the plugin will add a new menu item labeled ‘WPML’ in your WordPress menu. Clicking on it for the first time will take you to plugin’s settings wizard.

WPML Setup - Choose primary language

WPML will automatically detect your WordPress site’s language. You can change it here now if you want.

Click on the next button to continue.

On the next screen, you will be asked to select the languages you want to enable on your site. Simply select the languages from the list that you want to add to your site.

Select languages

You can always add or remove languages later if you need. After selecting your site languages, click on the next button.

Now you will be asked to add a language switcher to your site. This language switcher will allow your users to choose a language to view content in their preferred language.

Language switcher

WPML allows you to automatically add content switcher as a sidebar widget, in your navigation menu, or display as a plain list.

Additionally, you can also choose to select flags or text for language switcher. Once you have made the choice, click on the next button.

As the final step, you will be asked to enter your site key. If you have not generated one yet, then you can click on ‘Generate a key for this site’ button.

Register site key to receive automatic updates

This will take you to WPML website, where you will be asked to add the site you are coming from to your WPML account.

Once your site is added, you can click on it to get to your site key. Copy and paste this key into your WordPress site.

That’s all you have successfully finished the WPML setup wizard. You can now click on the Finish button to exit the setup.

Adding Multilingual Content into WordPress with WPML

WPML makes it really easy to translate every area of your WordPress site into multiple languages.

You will be able to easily translate your WordPress posts, pages, tags, categories, and themes into as many languages as you like.

Adding Multilingual Posts and Pages

Simply click on the posts menu to view your existing posts. You will notice the languages columns next to your post titles.

Adding translation for posts

WPML assumes that your existing content is in your site’s primary language. It will show Add buttons for each language next to your posts. Click on the add button under a language to translate a post.

You can also manage translations by editing a post.

On the post edit screen, you will notice the new ‘Language’ meta box to manage translations.

managing translations from post edit screen in WordPress

You can add translated content yourself or you can add users and authors to your WordPress site and have them translate your content for you.

WPML also offers a better way to manage users who work as translators on your website. If you purchase their Multilingual CMS Plan, then you can use their translation management module.

Translation management module allows you to add users as translators regardless of what role they have on your WordPress site. You can even add subscribers as translators.

Adding translators using translator management module

Instead of editing posts, these translators will be able to add translations directly in WPML.

Adding Translations for Categories and Tags

WPML allows you to easily translate categories and tags, or any other custom taxonomies that you may be using.

Visit WPML » Taxonomy Translation and load the custom taxonomies you want to translate.

For example: in this screenshot we selected categories, and it displayed all categories from our example site.

Taxonomy translate

Click on the add button next to the taxonomy term to add the translation.

Translating Navigation Menus

WordPress comes with a robust navigation menu system. WPML allows you to translate it just like you would translate posts or taxonomies.

Visit Appearance » Menus page on your site. If you have more than one menus, then select the menu you want to translate.

In the right hand column, you will see your menu with links to translate into other languages enabled on your site.

Translate Menus in multilingual WordPress

Clicking on a language will create a new menu for that language. You will need to add the same menu items as in your primary language menu.

Translating a navigation menu

If you have your posts and pages in navigation menus, then you will first need to translate them. After that you can add them from the tabs on the left in edit menu screens.

Don’t forget to click on the save button to save your menu.

Translating Themes, Plugins, & Other Text with WPML

WPML multilingual CMS allows you to choose between official translations of themes and plugins or use its own string translator.

Go to WPML » Themes and plugins localization page.

Load locale files for themes and plugins

By default, you will see ‘Don’t use String Translation to translate the theme and plugins’ checked. Below it, you will see another checkbox to automatically load the theme’s .mo file using ‘load_theme_textdomain’.

You can check this box to see if there are any translation files available for your theme. This works only with themes downloaded from the WordPress.org theme directory.

This setting doesn’t work very well for most websites. Not all WordPress themes and plugins have translations available. In some cases the translations are not good or incomplete.

We recommend using WPML’s String Translation module to properly translate your theme and plugins for your own site.

This module will also allow you to translate custom fields, widgets, and other translatable strings generated by WordPress.

We hope this article helped you learn how to create a WordPress multilingual site with WPML. You may also want to see our list of 40 useful tools to manage and grow your WordPress blog.

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 Create a Multilingual WordPress Site with WPML appeared first on WPBeginner.

14 Best WordPress Magazine Themes of 2016

If you have a content rich website and you’re looking for a new theme, then you probably want a WordPress magazine theme. It gives you freedom to break the typical layout and showcase more of your articles, videos, and images. There are hundreds perhaps thousands… Read More »

The post 14 Best WordPress Magazine Themes of 2016 appeared first on WPBeginner.

If you have a content rich website and you’re looking for a new theme, then you probably want a WordPress magazine theme. It gives you freedom to break the typical layout and showcase more of your articles, videos, and images. There are hundreds perhaps thousands of magazine style WordPress themes in the market. In this article, we have hand-picked some of the best WordPress magazine themes available.

Best Magazine Themes for WordPress

Getting Started with a WordPress Magazine Theme

First thing you will need to run a WordPress site is a web hosting. Magazine sites are content rich, and you will need to choose a web hosting company that can handle your traffic.

If you are just starting out, then we recommend going with BlueHost. It is one of the best shared hosting company and also one of the official WordPress hosting providers.

If you can afford to spend a little more, then we would recommend you to go with WPEngine. It is a managed WordPress hosting service, which means they will handle everything technical for you.

For more information check our guide on how to choose the best WordPress hosting for your website.

Some of you may already have a WordPress site, and you may just want to switch to a magazine theme. Make sure you understand what happens when you switch your WordPress theme and follow our checklist of 15 things you must do before changing WordPress themes.

Having said that, let’s check out some of the best WordPress magazine themes you can use on your site.

1. Paperback

Paperback

Paperback is an elegant WordPress magazine theme with tons of awesome features. It is designed to beautifully display content in a magazine layout. It prominently uses featured images from your articles throughout the layout. It also comes with a built-in featured posts slider for the homepage.

It pays special attention to readability across devices, the typography looks equally great on mobile and desktop. It has a category mega menu which displays featured content from those categories beautifully.

Paperback offers multiple color choices, homepage layouts, and slick content discovery features.

2. ModernMag

ModernMag

Modern Mag is a beautiful and modern looking magazine theme for WordPress. It comes with color variations and custom templates to easily build your own custom magazine site with WordPress in minutes.

Modern Mag is SEO friendly by design and it is highly optimized for speed. Faster page loads means better search rankings. It comes with built-in integration of social media making it super easy for you to connect a magazine site to its social pages.

It comes with an easy to use theme customizer which allows you to setup your site with a live preview next to it. Unlike other magazine themes, Modern Mag is bloat free and does not confuse users with overly complicated theme options.

3. Baseline

Baseline

Baseline is a modern WordPress magazine style theme. It features large images on the homepage, which makes your content more visually stunning.

In the header section it has featured content carousel, a mega menu of categories with images, sliding sidebars, and social media integration.

Typography is one of the most elegant features of the theme. It is beautiful across different devices and improves reading experience. The homepage has one, two, and three column layouts with multiple color options.

4. Poseidon

Poseidon

Poseidon is a free WordPress magazine theme. It comes with a large full-width slider on top, clean typography, and a spacious white layout.

The theme features a magazine homepage layout with custom widgets designed to work on magazine homepage. It also comes with theme-specific options which can be setup using customizer.

5. NewsAnchor Pro

NewsAnchor Pro

As the name suggests the, NewsAnchor Pro is a WordPress news and magazine theme. It comes with multiple page layouts, including multiple layouts for the homepage.

The theme has three extra widgets for your front page so you can create a complete magazine layout. These widgets are: a posts carousel widget, a featured images widget and a widget that displays four categories.

6. Responz

Responz

Responz is a three column news and magazine theme for WordPress. It features an elegant design with great typography and fully responsive layout.

It comes with multiple layout options like 2 sidebars, 1 sidebar, or full width homepage. You can also choose from the list view or grid view post layouts. It has built-in sliders, custom widgets, and shortcodes.

7. Oblique

Oblique

Oblique is a free magazine WordPress theme with a beautiful masonry layout. It features a beautiful parallax header, unlimited color choices, homepage templates, etc.

8. Magazine PRO

Magazine PRO

Magazine pro is premium WordPress magazine theme by StudioPress. It is built on top of Genesis theme framework, which means it comes with rock solid code.

The theme comes with multiple page templates for homepage, blog, and landing pages. It has three widgetized areas for homepage. It is easy to customize and setup using theme customizer.

9. Candid

Candid

Candid is a beautiful WordPress magazine theme designed to tell rich content stories. The theme focuses on improved readability with beautiful typography that looks great on all devices.

The homepage comes with a masonry layout that can be one, two, or three column layouts. It also supports infinite scroll, which lets your visitors seamlessly load more of your content without leaving the page.

10. Domino Magazine

Domino Magazine

Domino Magazine is a highly customizable WordPress magazine theme. The homepage features multiple widgetized areas and a dynamic page builder. It comes with built-in news ticker, weather widget, and a tabbed widget.

The theme also allows you to easily add custom background, headers, sliders, and your own logo.

11. Hueman

Hueman

Hueman is a popular free WordPress theme beautiful magazine style layout. It comes with multiple page templates giving you the option to choose between two or three column layouts.

It also allows users to toggle sidebars to create more reading space. Hueman has a theme options panel which allows you to fully customize it to match your needs.

12. Author

Author

Author is a premium WordPress theme designed for writers, bloggers, and authors. It features a spacious layout with lots of white space and beautiful typography.

It has a featured post carousel to display your most important content on the top. It allows you to use videos and images as featured images for your articles. It has built-in support for galleries, beautiful image displays, pullquotes, and much more to elegantly enhance reading experience.

13. ColorMag

ColorMag

ColorMag is a beautiful free WordPress magazine theme. It feature 15+ widget ready areas with 6 custom widgets which allow you to setup your site in many different ways. It also has multiple color options and the ability to set a primary color for your theme.

14. Alpha

Alpha

Alpha is powerful WordPress news/magazine style theme. It comes with two skins for magazine or news websites. Each skin will radically change your site’s layout and you can choose the one that meets your needs.

Among other features, it comes with a breaking news ticker and a custom slider. It also comes with a video widget to showcase your video content on the homepage.

We hope this list helped you choose the best WordPress magazine theme for your website. You may also want to see our list of 10 WordPress plugins that will quickly help you get more traffic

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 14 Best WordPress Magazine Themes of 2016 appeared first on WPBeginner.

Adding a Custom Inline Route Constraint in ASP.NET Core 1.0

ASP.NET supports both attribute routing as well as centralized routes. That means that you can decorate your Controller Methods with your routes if you like, or you can map routes all in one place.

Here’s an attribute route as an example:

[Route("home/about")]
public IActionResult About()
{
//..
}

And here’s one that is centralized. This might be in Startup.cs or wherever you collect your routes. Yes, there are better examples, but you get the idea. You can read about the fundamentals of ASP.NET Core Routing in the docs.

routes.MapRoute("about", "home/about",
new { controller = "Home", action = "About" });

A really nice feature of routing in ASP.NET Core is inline route constraints. Useful URLs contain more than just paths, they have identifiers, parameters, etc. As with all user input you want to limit or constrain those inputs. You want to catch any bad input as early on as possible. Ideally the route won’t even “fire” if the URL doesn’t match.

For example, you can create a route like

files/{filename}.{ext?}

This route matches a filename or an optional extension.

Perhaps you want a dateTime in the URL, you can make a route like:

person/{dob:datetime}

Or perhaps a Regular Expression for a Social Security Number like this (although it’s stupid to put a SSN in the URL 😉 ):

user/{ssn:regex(d{3}-d{2}-d{4})}

There is a whole table of constraint names you can use to very easily limit your routes. Constraints are more than just types like dateTime or int, you can also do min(value) or range(min, max).

However, the real power and convenience happens with Custom Inline Route Constraints. You can define your own, name them, and reuse them.

Lets say my application has some custom identifier scheme with IDs like:

/product/abc123

/product/xyz456

Here we see three alphanumerics and three numbers. We could create a route like this using a regular expression, of course, or we could create a new class called CustomIdRouteConstraint that encapsulates this logic. Maybe the logic needs to be more complex than a RegEx. Your class can do whatever it needs to.

Because ASP.NET Core is open source, you can read the code for all the included ASP.NET Core Route Constraints on GitHub. Marius Schultz has a great blog post on inline route constraints as well.

Here’s how you’d make a quick and easy {customid} constraint and register it. I’m doing the easiest thing by deriving from RegexRouteConstraint, but again, I could choose another base class if I wanted, or do the matching manually.

namespace WebApplicationBasic
{
public class CustomIdRouteConstraint : RegexRouteConstraint
{
public CustomIdRouteConstraint() : base(@"([A-Za-z]{3})([0-9]{3})$")
{
}
}
}

In your ConfigureServices in your Startup.cs you just configure the route options and map a string like “customid” with your new type like CustomIdRouteConstraint.

public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.Configure<RouteOptions>(options =>
options.ConstraintMap.Add("customid", typeof(CustomIdRouteConstraint)));
}

Once that’s done, my app knows about “customid” so I can use it in my Controllers in an inline route like this:

[Route("home/about/{id:customid}")]
public IActionResult About(string customid)
{
// ...
return View();
}

If I request /Home/About/abc123 it matches and I get a page. If I tried /Home/About/999asd I would get a 404! This is ideal because it compartmentalizes the validation. The controller doesn’t need to sweat it. If you create an effective route with an effective constraint you can rest assured that the Controller Action method will never get called unless the route matches.

If the route doesn't fire it's a 404

Unit Testing Custom Inline Route Constraints

You can unit test your custom inline route constraints as well. Again, take a look at the source code for how ASP.NET Core tests its own constraints. There is a class called ConstrainsTestHelper that you can borrow/steal.

I make a separate project and setup xUnit and the xUnit runner so I can call “dotnet test.”

Here’s my tests that include all my “Theory” attributes as I test multiple things using xUnit with a single test. Note we’re using Moq to mock the HttpContext.

public class TestProgram
{

[Theory]
[InlineData("abc123", true)]
[InlineData("xyz456", true)]
[InlineData("abcdef", false)]
[InlineData("totallywontwork", false)]
[InlineData("123456", false)]
[InlineData("abc1234", false)]
public void TestMyCustomIDRoute(
string parameterValue,
bool expected)
{
// Arrange
var constraint = new CustomIdRouteConstraint();

// Act
var actual = ConstraintsTestHelper.TestConstraint(constraint, parameterValue);

// Assert
Assert.Equal(expected, actual);
}
}

public class ConstraintsTestHelper
{
public static bool TestConstraint(IRouteConstraint constraint, object value,
Action<IRouter> routeConfig = null)
{
var context = new Mock<HttpContext>();

var route = new RouteCollection();

if (routeConfig != null)
{
routeConfig(route);
}

var parameterName = "fake";
var values = new RouteValueDictionary() { { parameterName, value } };
var routeDirection = RouteDirection.IncomingRequest;
return constraint.Match(context.Object, route, parameterName, values, routeDirection);
}
}

Now note the output as I run “dotnet test”. One test with six results. Now I’m successfully testing my custom inline route constraint, as a unit. in isolation.

xUnit.net .NET CLI test runner (64-bit .NET Core win10-x64)
Discovering: CustomIdRouteConstraint.Test
Discovered: CustomIdRouteConstraint.Test
Starting: CustomIdRouteConstraint.Test
Finished: CustomIdRouteConstraint.Test
=== TEST EXECUTION SUMMARY ===
CustomIdRouteConstraint.Test Total: 6, Errors: 0, Failed: 0, Skipped: 0, Time: 0.328s

Lots of fun!


Sponsor: Working with DOC, XLS, PDF or other business files in your applications? Aspose.Total Product Family contains robust APIs that give you everything you need to create, manipulate and convert business files along with many other formats in your applications. Stop struggling with multiple vendors and get everything you need in one place with Aspose.Total Product Family. Start a free trial today.


© 2016 Scott Hanselman. All rights reserved.
     

ASP.NET supports both attribute routing as well as centralized routes. That means that you can decorate your Controller Methods with your routes if you like, or you can map routes all in one place.

Here's an attribute route as an example:

[Route("home/about")]

public IActionResult About()
{
//..
}

And here's one that is centralized. This might be in Startup.cs or wherever you collect your routes. Yes, there are better examples, but you get the idea. You can read about the fundamentals of ASP.NET Core Routing in the docs.

routes.MapRoute("about", "home/about",

new { controller = "Home", action = "About" });

A really nice feature of routing in ASP.NET Core is inline route constraints. Useful URLs contain more than just paths, they have identifiers, parameters, etc. As with all user input you want to limit or constrain those inputs. You want to catch any bad input as early on as possible. Ideally the route won't even "fire" if the URL doesn't match.

For example, you can create a route like

files/{filename}.{ext?}

This route matches a filename or an optional extension.

Perhaps you want a dateTime in the URL, you can make a route like:

person/{dob:datetime}

Or perhaps a Regular Expression for a Social Security Number like this (although it's stupid to put a SSN in the URL ;) ):

user/{ssn:regex(d{3}-d{2}-d{4})}

There is a whole table of constraint names you can use to very easily limit your routes. Constraints are more than just types like dateTime or int, you can also do min(value) or range(min, max).

However, the real power and convenience happens with Custom Inline Route Constraints. You can define your own, name them, and reuse them.

Lets say my application has some custom identifier scheme with IDs like:

/product/abc123

/product/xyz456

Here we see three alphanumerics and three numbers. We could create a route like this using a regular expression, of course, or we could create a new class called CustomIdRouteConstraint that encapsulates this logic. Maybe the logic needs to be more complex than a RegEx. Your class can do whatever it needs to.

Because ASP.NET Core is open source, you can read the code for all the included ASP.NET Core Route Constraints on GitHub. Marius Schultz has a great blog post on inline route constraints as well.

Here's how you'd make a quick and easy {customid} constraint and register it. I'm doing the easiest thing by deriving from RegexRouteConstraint, but again, I could choose another base class if I wanted, or do the matching manually.

namespace WebApplicationBasic

{
public class CustomIdRouteConstraint : RegexRouteConstraint
{
public CustomIdRouteConstraint() : base(@"([A-Za-z]{3})([0-9]{3})$")
{
}
}
}

In your ConfigureServices in your Startup.cs you just configure the route options and map a string like "customid" with your new type like CustomIdRouteConstraint.

public void ConfigureServices(IServiceCollection services)

{
// Add framework services.
services.AddMvc();
services.Configure<RouteOptions>(options =>
options.ConstraintMap.Add("customid", typeof(CustomIdRouteConstraint)));
}

Once that's done, my app knows about "customid" so I can use it in my Controllers in an inline route like this:

[Route("home/about/{id:customid}")]

public IActionResult About(string customid)
{
// ...
return View();
}

If I request /Home/About/abc123 it matches and I get a page. If I tried /Home/About/999asd I would get a 404! This is ideal because it compartmentalizes the validation. The controller doesn't need to sweat it. If you create an effective route with an effective constraint you can rest assured that the Controller Action method will never get called unless the route matches.

If the route doesn't fire it's a 404

Unit Testing Custom Inline Route Constraints

You can unit test your custom inline route constraints as well. Again, take a look at the source code for how ASP.NET Core tests its own constraints. There is a class called ConstrainsTestHelper that you can borrow/steal.

I make a separate project and setup xUnit and the xUnit runner so I can call "dotnet test."

Here's my tests that include all my "Theory" attributes as I test multiple things using xUnit with a single test. Note we're using Moq to mock the HttpContext.

public class TestProgram

{

[Theory]
[InlineData("abc123", true)]
[InlineData("xyz456", true)]
[InlineData("abcdef", false)]
[InlineData("totallywontwork", false)]
[InlineData("123456", false)]
[InlineData("abc1234", false)]
public void TestMyCustomIDRoute(
string parameterValue,
bool expected)
{
// Arrange
var constraint = new CustomIdRouteConstraint();

// Act
var actual = ConstraintsTestHelper.TestConstraint(constraint, parameterValue);

// Assert
Assert.Equal(expected, actual);
}
}

public class ConstraintsTestHelper
{
public static bool TestConstraint(IRouteConstraint constraint, object value,
Action<IRouter> routeConfig = null)
{
var context = new Mock<HttpContext>();

var route = new RouteCollection();

if (routeConfig != null)
{
routeConfig(route);
}

var parameterName = "fake";
var values = new RouteValueDictionary() { { parameterName, value } };
var routeDirection = RouteDirection.IncomingRequest;
return constraint.Match(context.Object, route, parameterName, values, routeDirection);
}
}

Now note the output as I run "dotnet test". One test with six results. Now I'm successfully testing my custom inline route constraint, as a unit. in isolation.

xUnit.net .NET CLI test runner (64-bit .NET Core win10-x64)

Discovering: CustomIdRouteConstraint.Test
Discovered: CustomIdRouteConstraint.Test
Starting: CustomIdRouteConstraint.Test
Finished: CustomIdRouteConstraint.Test
=== TEST EXECUTION SUMMARY ===
CustomIdRouteConstraint.Test Total: 6, Errors: 0, Failed: 0, Skipped: 0, Time: 0.328s

Lots of fun!


Sponsor: Working with DOC, XLS, PDF or other business files in your applications? Aspose.Total Product Family contains robust APIs that give you everything you need to create, manipulate and convert business files along with many other formats in your applications. Stop struggling with multiple vendors and get everything you need in one place with Aspose.Total Product Family. Start a free trial today.


© 2016 Scott Hanselman. All rights reserved.
     

How to Add WordPress Navigation Menu in Posts / Pages

Do you want to display WordPress navigation menu in your posts or pages? Usually, your WordPress theme handles how and where navigation menus are displayed. In this article, we will show you how to add wordPress navigation menu in posts/pages or anywhere on your WordPress… Read More »

The post How to Add WordPress Navigation Menu in Posts / Pages appeared first on WPBeginner.

Do you want to display WordPress navigation menu in your posts or pages? Usually, your WordPress theme handles how and where navigation menus are displayed. In this article, we will show you how to add wordPress navigation menu in posts/pages or anywhere on your WordPress site.

Adding WordPress navigation menu in posts or pages

Why Add WordPress Navigation Menu in Posts/Pages

Navigation menus in WordPress provide an easy way to add a structured menu to your site.

You can create as many navigation menus as you want in your WordPress admin area, but you can only display them on menu locations available in your WordPress theme.

What if you needed to add a menu in a post or page? In that case, you will have to manually create a list of links which is not as efficient to manage as a WordPress menu.

Having said that, let’s see how you can add navigation menus in WordPress posts or pages.

Adding Navigation Menu in WordPress Posts/Pages

First thing you need to do is install and activate the Shortcode Menu plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Before you can use the plugin, first you will need to create the navigation menu that you want to display. Go to Appearance » Menus to create it. See our beginner’s guide on how to add navigation menu in WordPress for detailed instructions.

Once your menu is ready, you can click on the Shortcode Menu from your WordPress admin bar. This will take you to the plugin’s shortcode generator page.

Shortcode Menu settings page

First you need to select the menu you want to add from the ‘Select Menu’ drop down list. If you need to add an ID or class attribute to your menu, then you can add those.

Next, you need to choose a display style for your menu. By default, your menu will be displayed as a block. You can change that to inline if you want to display the menu in a horizontal line.

Default list type block menu

You can also change menu colors under ‘Design your menu on the fly’ section. The plugin allows you to select background, hover, and anchor colors.

At the bottom of the shortcode generator column, you will find the shortcode with options you chose above. Simply copy the shortcode and paste it in the post, page, or widget where you want to display your menu.

Copy the menu shortcode to use in a post or page in WordPress

The plugin adds some basic style to make your menu presentable. But if you want to customize the appearance of the menu, then you will need to do that with CSS.

In the second column of the plugin’s settings page, you will find a basic CSS snippet. You can use that as an starting point by adding it to your child theme‘s stylesheet or by using Simple Custom CSS plugin.

However, if you are not familiar with CSS, then you can try CSS Hero. It is a powerful plugin that allows you to style anything on your WordPress site using a simple user interface and without writing any code.

We hope this article helped you add navigation menu in your WordPress posts or page. You may also want to see our guide on how to create a table of contents in WordPress post or page.

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 WordPress Navigation Menu in Posts / Pages appeared first on WPBeginner.

9 Best PDF Plugins for WordPress

Do you want to add PDF files to your WordPress site? By default, WordPress cannot generate or embed PDF files in posts or pages. In this article, we have hand-picked some of the best PDF plugins for WordPress. 1. PDF Viewer The PDF Viewer allows… Read More »

The post 9 Best PDF Plugins for WordPress appeared first on WPBeginner.

Do you want to add PDF files to your WordPress site? By default, WordPress cannot generate or embed PDF files in posts or pages. In this article, we have hand-picked some of the best PDF plugins for WordPress.

Best PDF plugins for WordPress

1. PDF Viewer

PDF Viewer

The PDF Viewer allows you to display PDF files inside your WordPress posts and pages. It uses Mozilla’s PDF.js script to render PDF documents beautifully with tools to scroll, search, jump between pages, print, and download PDF files.

For detailed instructions, see our guide on how to add a PDF viewer in WordPress.

2. WP Advanced PDF

WP Advanced PDF

WP Advanced PDF plugin allows your users to download your posts and pages in PDF format. You can enable the PDF download for all users or just for registered users. You can use custom fonts, logo, and even add a watermark to your PDF files.

3. PDF & Print by BestWebSoft

PDF and Print

As the name suggests, this plugin adds a PDF download and print button to your WordPress posts, pages, and custom post types. You can add your website title, featured image, custom styles, and fonts. The plugin can also execute shortcodes when generating PDFs or creating a printer friendly version.

4. PDF Image Generator

PDF Image Generator

PDF Image Generator creates a cover image for PDF Files you add in WordPress posts for download. The plugin can generate this cover image by either using the first page in the PDF or featured image. The download icon will then display the thumbnail image linked to PDF file.

For this plugin to work your WordPress hosting provider should have ImageMagick and GhostScript installed on their server.

5. PDF Thumbnails

PDF Thumbnails

Similar to the previous plugin, PDF thumbnail also generates a thumbnail of the first page of your PDF file during the upload. However, your PDF file and the thumbnail image remain as two separate files. You will need to manually insert the generated thumbnail and then link it to the PDF file.

6. DK PDF

DK PDF

This powerful plugin allows users to download your posts and pages in PDF format by clicking on a button. It comes with an easy interface to setup the placement of the PDF download button and create your own custom header and footer for PDF downloads.

The plugin also comes with shortcodes that allow you to control what content goes inside the PDF. You can also hide the content you don’t want to be included into PDF download.

7. PDF Embedder

PDF Embedder

As the name suggests, PDF Embedder plugin allows you to embed PDF files in WordPress posts and pages. The plugin uses JavaScript to embed files with a fully functional toolbar allowing users to zoom, navigate, and even download the PDF file.

8. WordPress PDF Light Viewer Plugin

PDF Lite Viewer

WordPress PDF Lite Viewer plugin is particularly good at embedding very large PDF files. It uses Turn.js JavaScript library to display PDF files as flipbooks with thumbnail navigation. The PDF viewer comes with zoom, navigation, and fullscreen buttons. It is also fully responsive and can work on different device sizes.

9. BSK PDF Manager

BSK PDF Manager

BSK PDF Manager is a file manager for PDF files on a WordPress site. If you upload PDF files often, then you may want to categorize them, display them as lists, or a single download. This plugin makes it easier to manage PDF files in WordPress.

Bonus Plugins

These plugins do not offer a way generate or embed PDF files. However, if you serve PDF files on your WordPress site, then you may find them helpful.

10. SearchWP

SearchWP

SearchWP is a paid WordPress plugin. It allows you to add a better search experience to your WordPress site. One of the features of this plugin is the ability to search the text inside PDF files. However, it cannot search PDF files that are encrypted, stored outside media library, or have images as text. See our guide on how to improve WordPress search with SearchWP

11. OptinMonster

OptinMonster

OptinMonster is a powerful tool that helps you grow your email list. You can convert abandoning visitors into subscribers by using OptinMonster. You can ask users to signup for your email list in exchange for free download PDF resource.

You can also use it to offer content upgrades. See this list of 30 content upgrade ideas to 10X your subscribers.

We hope this article helped you find the best PDF plugins for WordPress. You may also want to see our list of 24 must have WordPress plugins for business websites.

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 9 Best PDF Plugins for WordPress appeared first on WPBeginner.

How to Create a Multi-Page Form in WordPress

Recently, one of our users asked us how to create a multi-page form in WordPress? Multi part forms allow you to collect more information without scaring the users away. In this article, we will show you how to create a multi-page form in WordPress. Why… Read More »

The post How to Create a Multi-Page Form in WordPress appeared first on WPBeginner.

Recently, one of our users asked us how to create a multi-page form in WordPress? Multi part forms allow you to collect more information without scaring the users away. In this article, we will show you how to create a multi-page form in WordPress.

Creating a multi-page form in WordPress

Why and When You Need Multi-Page Form in WordPress?

Forms are the easiest way to collect data and get in touch with your users. Whether it is a contact form, email capture form, or a simple survey.

However, lengthy forms are daunting for users and increases form abandonment.

To overcome this issue, user experience experts recommend multi-page forms. This way form fields are broken into sections and pages.

A multi-step checkout page example

With a progress bar on top and fewer fields on screen, users feel more at ease filling out the form. It provides a more engaging and interactive experience to your users.

Having said that, let’s see how to easily create a multi-page form in WordPress.

Creating A Multi-Page Form in WordPress with WPForms

We will be using WPForms which is the most beginner friendly contact form plugin for WordPress. You will need at least the Basic license which costs $39.

You can use the WPForms coupon: WPB10 to get 10% discount on your purchase of any WPForms plan.

First thing you need to do is install and activate the WPForms plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you will need to enter your license key. You can get this key by signing into your account on WPForms website.

Copy the license key and then visit WPForms » Settings page on your WordPress site. Paste the license key and then click on the verify key button.

WPForms license key

After verifying your license key, you are now ready to create your first multi-page form in WordPress.

Simply go to WPForms » Add New page, and it will launch the Form Builder.

Adding a new form in WPForms

Provide a title for your form and then select one of the templates shown below. WPForms offers ready-made form to speed up the form creation process.

You can choose the one that closely matches your form requirements or choose a blank form. Clicking on a template will launch the form editor.

Form editor in WPForms

Simply click on the fields from left column to add them into your form. After that click on a field in the form to edit it. You can also drag and drop form fields.

Adding form fields in WPForms

After adding a few form fields, you are ready to add a new page to your form. Click on the Pagebreak field under fancy fields sections from the left column.

Adding pagebreak field

You will notice that WPForms will add a pagebreak marker to the bottom and a first page marker at the top of the page.

It will also push the submit button to the next page, and your first page will now have a ‘Next’ button instead.

Click on the first page marker at the top to edit your multi-page form properties. In the left hand column, you can select a progress bar type. WPForms allows you to use a simple progress bar, circles, connector, or no progress indicator at all.

Edit first page marker to select progress bar type

For this tutorial, we will be using Connectors as progress bar. You can also choose the color of your page indicator. Lastly, you can provide a title for the first page.

Now you need to click on the pagebreak marker to edit its properties. Here you can provide a title for the next page. You can also edit the text to display on the Next button.

Edit page title and next button text

You can continue adding form fields after the pagebreak. If you are using the PRO version of WPForms, then you can also use conditional logic to show and hide form fields based on user responses.

After adding more fields, you can add more pagebreaks if you need.

Once you are done creating your form, click on the save button on the top right corner of the screen.

Congratulations, you have successfully created your first multi-page form.

Adding Your Multi-Page Form into WordPress Posts and Pages

WPForms makes it super easy to add forms into WordPress posts and pages.

Create a new post/page or edit an existing one. On top of the post editor, you will see an ‘Add Form’ button.

Add form button

Clicking on it will bring up an insert form popup.

Select your form from the drop down list and then click Add Form button.

Select and insert your multipage form

You will notice WPForms shortcode added into your post/page. You can now save or publish this post or page.

Visit your website to see your multi-page form in action.

Preview of a paged form in WordPress

We hope this article helped you add a multi-page form in WordPress. You may also want to see our guide on how to add a contact form popup in WordPress.

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 Create a Multi-Page Form in WordPress appeared first on WPBeginner.