Dependency Injection Using MEF

1. Introduction
“Dependency Injection is a design pattern that takes away the responsibility of creating dependencies from a class thus resulting in a loosely coupled system.”

Or

“Dependency Injection means that this is done without the object intervention, usually by a framework component that passes constructor parameters and set properties.”

Read More…

Advertisements

How to Display the Latest Sticky Posts in WordPress

WordPress has this very cool feature called sticky posts. Think of sticky posts as featured posts for your blog. When you mark a post as sticky, it shows up above your new posts, but only if your theme permits it. In this tutorial we will show you how to display the latest sticky posts in WordPress.

First thing you need to do is copy and paste this code snippet in your theme’s functions.php file or in a site-specific plugin.

01 function wpb_latest_sticky() {
02
03 /* Get all sticky posts */
04 $sticky = get_option( ‘sticky_posts’ );
05
06 /* Sort the stickies with the newest ones at the top.
07 * Remove this if you want to display oldest posts first
08 */
09 rsort( $sticky );
10
11 /* Get the 5 newest stickies (change 5 for a different number) */
12 $sticky = array_slice( $sticky, 0, 5 );
13
14 /* Query sticky posts */
15 $the_query = new WP_Query( array( ‘post__in’ => $sticky, ‘caller_get_posts’ => 1 ) );
16
17
18 // The Loop
19 if ( $the_query->have_posts() ) {
20 $return .= ‘<ul>’;
21 while ( $the_query->have_posts() ) {
22 $the_query->the_post();
23 $return .= ‘<li><a href=”‘ .get_permalink($post->ID). ‘” title=”‘ . get_the_title() . ‘”>’ . get_the_title() . ‘</a></li>’;
24
25 }
26 $return .= ‘</ul>’;
27
28 } else {
29 // no posts found
30 }
31
32
33 /* Restore original Post Data */
34 wp_reset_postdata();
35
36 return $return;
37
38 }
39 add_shortcode(‘latest_stickies’, ‘wpb_latest_sticky’);

The code above queries the WordPress database to retrieve the 5 latest sticky posts. It then displays each sticky post’s title with a link in a list format. We have wrapped all that in a function and created a shortcode.

Now to display your latest sticky posts, you can use the shortcode [latest_stickies] in any WordPress post, page, or even a text widget.

If you would like to use shortcodes inside a text widget, then you will need to add this extra line of code in your theme’s functions.php or site-specific plugin.

add_filter('widget_text', 'do_shortcode');

This snippet and function can very well be used in featured slider, or any other advanced feature that you would like to display on your site. This snippet is mostly geared toward a WordPress site that has a custom homepage or a magazine style look.

Source: http://www.wpbeginner.com/wp-tutorials/how-to-display-the-latest-sticky-posts-in-wordpress/

14 Most Common WordPress Errors and How to Fix Them

WordPress is very easy to use but some common WordPress errors can cause panic among beginners. It is very possible that the error you are seeing on your site has been already reported and resolved by someone before you. At WPBeginner, we have covered and showed you how to fix several WordPress errors. In this article, we will take a look at 14 most common WordPress errors along with showing you how to fix all of these common WordPress errors.

Important: Make sure that you have a complete backup of your WordPress site. We strongly recommend using an automated scheduled backup system like BackupBuddy. However, if you can not install plugins at this time, then check out how to manually create WordPress backup manually. In case you are unable to resolve a issue, please contact your WordPress hosting company.

1. How to Fix the Syntax Error in WordPress

This error usually occurs when you are trying to add code snippets into WordPress and have accidentally missed something or the code has incorrect syntax. This will result into a PHP parse error and you will see a notice like:

Parse error - syntax error, unexpected $end in /public_html/site1/wp-content/themes/my-theme/functions.php on line 278

The error message would indicate the unexpected thing found in the code and the location of the script where the error occurred with line number. To fix this issue you will have to correct the syntax. Most of the time it is a missing bracket, or some unexpected character in the code. [Fix this error]

2. How to Fix the Internal Server Error in WordPress

Another common error that WordPress users may come across is “Internal Server Error”, or sometimes “500 Internal Server Error”. This error usually happens when there is something wrong, but the server is unable to idefntify where the problem is. Since the error message does not indicate where you should look for the error, it pretty much up to you to figure this out. We have compiled a list of solutions that you can try and one of them will help you resolve it. [Fix this error]

3. How to Fix the Error Establishing a Database Connection in WordPress

This error message is clear that your website is unable to connect to the database. However solving this error can be tricky for beginners. Usually this occurs when a user has entered or modified their database credentials (database host, database username, and database password) incorrectly. Sometimes your database server could be unresponsive, or your database may have corrupted. However, most of the time it is usually incorrect database login credentials. Take a look at common solutions for this problem. [Fix this error]

4. How to Fix the WordPress White Screen of Death

This error usually results into a plain white screen with no error message which makes it the most puzzling because you have no clue where to look and what to fix. Most of the time it is caused when a script exhausts PHP memory limit. It can also happen due to a configuration on the server. It is also possible that a user would only see white screen of death on certain sections of their site. [See how to fix this error]

5. How to Fix WordPress Posts Returning 404 Error

The symptoms of this error is that when a user visits a single post on their site they get a 404 page – not found error. The user can browse all other sections of their site including the admin area. The most common cause of this issue is permalink settings in WordPress. To solve this issue a user would need to reconfigure their permalinks settings or manually update their rewrite rules. [Fix this error]

6. How to Fix the Sidebar Below Content Error in WordPress

Another common issue that many WordPress beginners face is sidebar appearing below the content when it is supposed to appear next to the content. Causes of this issue are mostly related to themes. Sometimes when users are adding code snippets to their site, they may accidentally forget to close an html div tag or add an extra closing div which may result into breaking the theme layout. Another common cause is using disproportionate width in CSS or not clearing float properly. [Fix this error]

7. How to Fix White Text and Missing Buttons in WordPress Visual Editor

Sometimes buttons from WordPress visual editor may disappear or start showing blank white spaces instead of buttons. This problem may occur when concatenated JavaScript is not working in user’s admin area, missing or corrupt TinyMCE files, or conflict with some other plugin that modifies or extends the TinyMCE shipped with WordPress. [Fix this error]

8. Fix: WordPress Memory Exhausted Error – Increase PHP Memory

Indications of this error could be a white screen of death, or an error message like this one:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2348617 bytes) in /home/username/public_html/site1/wp-includes/plugin.php on line xxx

This error occurs when a WordPress script or a plugin exhausts the default allocated memory size limit. [Fix this error]

9. What To Do When You Are Locked Out of WordPress Admin (wp-admin)

Sometimes you may find yourself locked out of the WordPress admin area. This could happen if you forgot your password and don’t have to access to password recovery email. This could also happen due to a plugin or code that incorrectly tries to make some changes into admin section. It could also happen if someone has hacked your WordPress site and changed all usernames and passwords. [Fix this issue]

10. How to Fix WordPress Login Page Refreshing and Redirecting Issue

Symptoms of this issue are that when a user attempts to login to the WordPress dashboard, they are redirected by WordPress back to the login page. Most of the time it happens due to incorrect values for site url and home url fields in WordPress options table. [Fix this issue]

11. How to Fix Image Upload Issue in WordPress

Sometimes a user would suddenly notice that all the images from their site are gone and are showing broken image placeholders. When the user tries to upload an image to a post using the media uploader, it results into an error. All these files in the media library will appear as broken. This error occurs due to incorrect file and directory permissions in a WordPress installation. A number of factors may cause this issue. [Fix this issue]

12. How to Fix Common Image Issues in WordPress

Uploading images to a WordPress site can be confusing for someone new to WordPress. A user may be unable to find out how to align images, resize or crop them, or display them in a gallery format. This is not an error or issue in WordPress. You just need to familiarize yourself with how WordPress handles media. [Fix this issue]

13. How to Fix “Are You Sure You Want to Do This” Error in WordPress

Users may come across this error in WordPress admin area. The most common cause of this error is a plugin or theme failing to use Nonce properly. Nonce are special security keys which may be appended to URLs when performing an admin action in WordPress. Sometimes a plugin or theme may use it incorrectly which may result into users seeing this error. [Fix this error]

14. How to Fix Briefly Unavailable for Scheduled Maintenance Error in WordPress

Sometimes due to an unfinished or interrupted WordPress update, you might see Briefly Unavailable for Scheduled Maintenance error in WordPress. What happens there is that WordPress puts your site in maintenance mode during an update. If for some reason the update is interrupted, WordPress does not get the chance to put your site out of the maintenance mode. This error would lock down your entire site and make it unavailable for admins as well as visitors.

Source: http://www.wpbeginner.com/beginners-guide/14-most-common-wordpress-errors-and-how-to-fix-them/

How to Add SSL and HTTPS in WordPress

What is HTTPS and SSL?

WordPress Security

Every day we share our personal information with different websites whether it’s making a purchase or simply logging in.

In order to protect the data transfer, a secure connection needs to be created.

That’s when SSL and HTTPS come in.

HTTPS or Secure HTTP is an encryption method that secures the connection between users’ browser and your server. This makes it harder for hackers to eavesdrop on the connection.

Each site is issued a unique SSL certificate for identification purposes. If a server is pretending to be on HTTPS, and it’s certificate doesn’t match, then most modern browsers will warn the user from connecting to the site.

Google Chrome showing warning about an unsecure connection

Now you are probably wondering, why would you ever need to move from HTTP to HTTPS and install a SSL certificate?

Why do you need HTTPS and SSL?

If you are running an eCommerce website, then you absolutely need a SSL certificate specially if you are collecting payment information.

Most payment providers like Stripe, PayPal Pro, Authorize.net, etc will require you to have a secure connection using SSL.

Recently, Google also announced that they will be using HTTPS and SSL as a ranking signal in their search results. This means that using HTTPS and SSL will help improve your site’s SEO.

We already use SSL for our eCommerce sites like OptinMonster, Soliloquy, and Envira Gallery. We will also switch all content sites to SSL as well. We just added SSL for Syed Balkhi’s blog (our founder).

A site secured by HTTPs and SSL in WordPress

We’re often asked wouldn’t SSL and HTTPS slow down my WordPress website? In reality, the difference in speed is negligible, so you should not worry about that.

Requirements for using HTTPS/SSL on a WordPress Site

The requirements for using SSL in WordPress is not very high. All you need to do is purchase a SSL certificate.

Some WordPress hosting providers offer free SSL with their plans. Siteground, one of our favorite providers, offer a one year free SSL certificate with their “grow big” plan).

If your hosting provider does not offer a free SSL certificate, then you can ask them if they sell third party SSL Certificates. Most hosting providers like Bluehost sell them around $50-$200.

You can also buy SSL from providers like Godaddy.

Once you have purchased a SSL Certificate, you would need to ask your web hosting provider to install it on your server.

This is a fairly straight forward process.

How to Setup WordPress to Use SSL and HTTPS

If you are starting a new site and/or want to use HTTPS everywhere on your site, then you need to update your site URL.

You can do this by going to Settings » General and updating your WordPress and site URL address fields.

updating-urls

Now if you’re adding SSL to your existing site, then you need to setup WordPress SSL redirect from HTTP to HTTPS.

You can do this by adding the following code in your .htaccess file:

1 <IfModule mod_rewrite.c>
2 RewriteEngine On
3 RewriteCond %{SERVER_PORT} 80
4 RewriteRule ^(.*)$ https://www.yoursite.com/$1 [R,L]
5 </IfModule>

Don’t forget to replace yoursite.com with your site URL.

If you are on nginx servers (most users are not), you would add the following to redirect from HTTP to HTTPS:

1 server {
2 listen 80;
3 server_name yoursite.com http://www.yoursite.com;
4 return 301 https://yoursite.com$request_uri;
5 }

By following these steps, you will avoid the WordPress HTTPS not working error because all your site URL and content will be on SSL.

If you want to add SSL and HTTPS on your WordPress multi-site admin area or login pages, then you need to configure SSL in wp-config.php file.

Simply add the following code above the “That’s all, stop editing!” line in your wp-config.php file:

1 define('FORCE_SSL_ADMIN', true);

This wp-config.php SSL trick works for single sites as well as multi-sites.

Setup SSL and WordPress HTTPS on Exclusive Pages

Now if for some reason, you only want to add HTTPS and SSL on specific pages of your site, then you would need the plugin called WordPress HTTPS (SSL).

First thing you need to do is install and activate the WordPress HTTPS (SSL) plugin.

Please note that this plugin hasn’t been updated for a while, but it works fine and is safe to use. See our guide on installing plugins not tested with your WordPress version for more information.

Upon activation the plugin will add a new menu item labeled HTTPS in your WordPress admin. You can click it to visit the plugin’s settings page.

WordPress HTTPs SSL settings

The first option of the settings page asks you to enter your SSL host. Mostly it is your domain name. However, if you are configuring the site on a subdomain and the SSL certificate you got is for your main domain name, then you will enter the root domain. If your using a shared SSL certificate provided by your web host, then you will need to enter the host information they provided instead of your domain name.

In some cases if you are using a non-traditional SSL host and need to use a different port, then you can add it in the port field.

Force SSL Administration setting forces WordPress to use HTTPs on all admin area pages. You need to check this box to make sure that all traffic to your WordPress admin area is secure.

The next option is to use Force SSL Exclusively. Checking this box will only use SSL on pages where you have checked the Force SSL option. All other traffic will go to the normal HTTP url.

This works if you only want to use SSL on specific pages like shopping cart, checkout, user account pages, etc.

Click on the save changes button to store your plugin settings.

If you want to use HTTPS just for specific pages, then you need to edit those pages and check the Force SSL checkbox.

Forcing HTTPs on specific pages and posts

Once done, visit your page to ensure that you have all green light in Chrome and other browsers.

Chrome WordPress HTTPS error

Source: http://www.wpbeginner.com/wp-tutorials/how-to-add-ssl-and-https-in-wordpress/

7 Best WordPress Backup Plugins Compared (Pros and Cons)

Creating regular WordPress backups is the best thing you can do for your website. Backups give you a peace of mind and can save you in catastrophic situations when your site gets hacked or you accidentally lock yourself out. There are several free and paid backup plugins for WordPress, and most of them are fairly easy to use. In this article, we will show you the 7 best backup plugins for WordPress.

Important: Many WordPress hosting providers offer limited backup services, but please remember that it is your responsibility to backup your website on your own. Do not rely solely on your hosting provider for backups.

If you are not already backing up your site, then you should pick one of these 7 best WordPress bckup plugins and start using it right away.

1. VaultPress

VaultPress

At WPBeginner, we use VaultPress to backup our site. VaultPress was founded by Matt Mullenweg (WordPress co-founder) and his team at Automattic.

It is a subscription based service with different plans and pricing. VaultPress offers automated real-time cloud backup solution starting at $5 / month (which is good for most websites).

Setting up VaultPress and restoring from backups is just a matter of clicks. With some of their packages, they even offer security scans.

The only downside to VaultPress is that it is a recurring expense that can add up if you have multiple WordPress sites.

2. BackupBuddy

BackupBuddy - The most beginner friendly WordPress Backup Plugin

BackupBuddy is the most popular premium backup plugin for WordPress. It allows you to easily schedule daily, weekly, or monthly backups and store them in Dropbox, Amazon S3, Rackspace Cloud, FTP, Stash (their cloud service), and even email it to yourself.

The biggest advantage of using BackupBuddy is that it is not a subscription based service. You are licensed to use the plugin on the number of sites mentioned in your plan. You get access to premium support forums, updates, and 1GB of cloud storage to store your backups.

You can even use BackupBuddy to move WordPress to a new host with no Downtime.

3. BackWPup

BackWPup

BackWPup is a free plugin that allows you to create complete WordPress backup for free and store it on the cloud (Dropbox, Amazon S3, Rackspace, etc), FTP, email, or on your computer.

It is extremely easy to use and allows you to schedule automatic backups according to your site’s update frequency.

Restoring a WordPress site from backup is also very simple. The BackWPup Pro version comes with priority support, ability to store backups on Google Drive, and some other cool features.

4. BackUpWordPress

BackupWordPress

BackupWordPress is a complete WordPress backup plugin with automatic scheduling support. It allows you to create different schedules for your database and files. The only problem is that the free version does not allow you to store your WordPress backups to a cloud storage service.

If you want to store your backups on Dropbox, Google Drive, FTP, etc, then you will need to purchase a premium extension for it. The extensions are available for each service, and you can buy the one you need or the whole bundle.

5. UpdraftPlus

UpdraftPlus Settings

UpdraftPlus is another WordPress backup plugin. It allows you to create complete backup of your WordPress site and store it on the cloud or download to your computer. The plugin allows you to create scheduled backups and store them to your chosen location. There is a premium version of the plugin with additional features and addons.

The only downside of Updraftplus is that despite having great features, it has a cluttered user interface. This makes it difficult for beginners to locate the options they need. Despite the clutter, it still has a very good rating in the WordPress plugins directory.

6. Duplicator

Duplicator - Backup and Migration Plugin for WordPress

As the name suggests, Duplicator is a popular WordPress plugin used to migrate WordPress sites. However it is also has backup features.

It does not allow you to create automated scheduled backups which makes it less than ideal for a regularly maintained site to use as its primary backup solution.

7. WP-DB-Backup

WP-DB-Backup

With more than 2 Million downloads, WP-DB-Backup is one of the most popular WordPress backup plugins. The only problem is that it only backups your WordPress database.

This means that you will have to backup your media files manually. If you do not update a site too often or do not upload images, then you can use WP-DB-Backup as your primary WordPress backup plugin.

WP-DB-Backup makes it really simple to create database backups, schedule automated backups, and restore your database. It is also a very useful tool for users who do not have access to phpMyAdmin to backup WordPress database manually.

Source: http://www.wpbeginner.com/plugins

Top 10 Most Important Things To Do After Installing WordPress

What do you do after installing WordPress? This is a common question asked by beginners. In this article, we will show you the top 10 most important things you must do after installing WordPress.

1. Change The Title, Tagline, Time zone, and Favicon

The first three steps can be combined into one because you can quickly make those changes in the same area of your WordPress Admin Dashboard.

Changing title and tagline of your WordPress site

To change these, go to your Settings in your dashboard and choose General. Change both your site title and tagline to something that relates to your site.

Changing timezone in WordPress

Now scroll down the page to update your timezone. This functionality is important to show the most accurate date on your site, and it also helps with scheduling posts.

Towards the middle of the page you’re on (in General Settings), you’ll find the option to set your zone. You can choose a city that is in the same time zone as you live in or set by UTC. To find the right UTC setting, you can search a site like this one here to make sure you select the right time zone.

Don’t forget to save your changes.

The final part of item 1 is updating the favicon. This is the little icon that appears in the browser tab next to your site title which is important for your site’s identity. Often people don’t change this which ends up showing either the default WordPress icon or their hosting provider’s icon such as Bluehost, etc.

The easiest way to add a favicon to your site is by following our guide on How to Add a Favicon in WordPress.

2. Change Your Permalink Structure

Unfortunately, the default permalink structure — the URL structure that tacked on the end of your site name — of WordPress is not very Google friendly. As that is the case, you should be sure to alter this to something else.

Changing permalinks in WordPress

Go back to Settings and then select Permalink from the menu. There you will find a few different choices for setting a new structure. The best ones to use are either the Day and Name or Post Name options.

Select the one you prefer and then save your changes.

3. Configure the Reading Settings

While in the Settings area of your dashboard, you should also configure the Reading settings. Here you can set what your front page display will be.

Reading settings

This part is great if you want to have a custom homepage to display your services and have a separate page to display all your blog posts.

Navigate over to the Reading option in the menu and decide if you want your front page to show your latest posts or if you want to use a static page. Make your choice and then save your changes. You can always change this one later, so don’t feel too pressured.

As a quick note, you can also make some of the above-stated changes using the Customize option in the front-end of your site if you are logged in. However, following this flow of things simply speeds up the process a little.

4. Delete Unused Themes

Most WordPress users will install and test a few themes before deciding on one that’s a keeper. Instead of leaving those unused themes installed, be sure to delete them. Themes even ones that go unused, will need updates.

Leaving them there can create the unnecessary chore of updating them. And not updating them can create a hazard to your sites safety as it can give hackers a way in.

Thankfully, deleting unused themes is a snap. Simply find the menu item named Appearance, and then go to themes. To delete a given theme, you need to hover over it and select Theme Details. After that, a window will open and the option to delete the theme will be available there.

5. Install a Cache Plugin

Why a cache plugin? Because it can help speed up your site. Caching helps take the load off your server and make your site faster. This is great for SEO as well as prevents your site from crashing during heavy load times.

Below are a couple of cache plugins that you can use in your WordPress site:

W3 Total Cache

W3 Total Cache – This plugin can likely lay claim to being the most powerful cache plugin available for WordPress users. It has a ton of options for boosting your site and is a popular plugin of choice for CDN integration. The plugin really does pack a punch and can easily mess things up if you’re not sure how to configure it properly. If you’ve never used the plugin before, it may be better to start small before using this one. However, if you’d like to be brave and use this plugin, be sure to check out our step-by-step guide for setting it up:

WP Super Cache – This one is a bit easier to start using, and yes, it’s still a great cache plugin. Simply install it and turn on caching, and you’re one step closer to a faster site. There are other options that come with the plugin, just be sure you know what you’re selecting before you hit save. Want some help with this plugin? Check out our guide below:

6. Improving WordPress Security

When it comes to your website, it is probably best to be of the philosophy that it’s better to be safe than sorry.

First security step that you can take is installing a backup plugin (we will come to that later). After that you need to protect your WordPress admin area.

WPBeginner uses Sucuri for security purposes. If you’d like to know why we chose this one over others, then be sure to give this post a read:

7. Install an Anti-Spam Plugin

No one likes spam.

Spammy comments are a huge headache for many WordPress site owners. Not only are they irritating, they’re also bad for SEO. To help alleviate the problems that come from this issue, you should install an anti-spam plugin on your site. Here are a few top choices:

Akismet

Akismet – This plugin by Automattic is a premium anti-spam plugin that does wonders for keeping that icky spam stuff out. If you decide to use Jetpack in your site, then you can use that account to activate Akismet for your site. If not, you’’ll need to follow the prompts for fully activating the plugin after install. The free version is limited but can be upgraded it you pay.

Anti Spam Bee

Antispam Bee – This is another great free plugin that helps to block out those pesky spammers. Even though the Akismet plugin does a better job, this one is a great option too.

Either way, be sure you use one.

8. Install A SEO WordPress Plugin

SEO is an important part of any website. To ensure that your blog posts are getting maximum results, you need to optimize them using an SEO plugin. Though these types of plugins don’t automatically boost SEO, they do help you make the most of your blog posts.

WordPres SEO plugin

A top choice for many is the WordPress SEO Plugin by Yoast. It’s easy to use and can even generate an XML sitemap at the click of the mouse. Want to know how to really boost the power of the plugin? Here’s our tutorial:

9. Optimize For Social Media Sharing via Sharing Plugins

Social Media

First off, is this really important? Yes, absolutely! You shouldn’t wait for your site to get traffic before optimizing your site for social shares. The best and easiest way to optimize your site for social shares is to use a Social Sharing Plugin.

There are hundreds of these to choose from, and some of them shouldn’t be used as they tend to slow down site speed. However, there are others that get the job done without bogging you down.

Here is a great article that narrows down the choice a bit:

10. Start Scheduling Regular Backups

Now that you’ve spent all that time setting up and customizing your WordPress site, you wouldn’t want to lose any of this right? Well, in that case, you should create regular backups.

Source: http://www.wpbeginner.com/beginners-guide

How to add Multiple Google Maps on one page?

Here is how you can generate multiple maps on the same page using Google Map API V3.

Multiple-Google-Map-by-Vivacity-InfoTech

Multiple-Google-Map

HTML


<div id="map_canvas" style="width:700px; height:500px; margin-left:80px;" ></div>
<div id="map_canvas2" style="width:700px; height:500px; margin-left:80px;" ></div>

JavaScript

<script type="text/javascript"> 
 var map,map2;

  function initialize(condition) {
  // create the map

var myOptions = {
    zoom: 14,
    center: new google.maps.LatLng(0.0, 0.0),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
    map = new google.maps.Map(document.getElementById("map_canvas"),
                                myOptions);

    map2 = new google.maps.Map(document.getElementById("map_canvas2"),
                                   myOptions);  
}



</script>

 Download Sample File