Change WordPress User Roles in myPHP

Change WordPress User Roles in myPHP

If you are using WordPress, you may want to change user roles in bulk. But why?

This is down to my own personal experience where I had installed bbpress forum software. It was to start looking at providing support in a forum style.

However, I had not set up the user settings correctly and ended up with 1000’s of my visitors being set to bbpress user role of spectator rather than the WordPress user roles of Subscriber.

This then became a particular problem when I decided to remove bbpress, I had orphaned users all over the place. I needed a solution to change the user role of 1000’s of user accounts without having to go through each one manually.

myPHP Admin

This is where myPHP came in. You can use myPHP to amended data in your WordPress database. In this case, changing all users with spectator as their user role to subscriber.

NOTICE – Before you go any further, you are about to change your core WordPress database, so ensure that you have a good backup before going any further. You have been warned!

To carry this out, you need to login to your hosting cPanel and open up the myPHP Admin app:

myPHP Admin in cPanel
myPHP Admin in cPanel

When you click myPHP Admin it will automatically redirect you to the utility. Using the top menu bar, you should click on the SQL button:

myPHP Admin SQL Button
myPHP Admin SQL Button

This will now take you to the area where you can add your script to make the changes required.

myPHP WordPress User Role Change Script

Below is the script that you can use to update your own WordPress database by changing the users table and taking any user with bbp_spectator and changing it to subscriber.

UPDATE wp55_users
INNER JOIN wp55_usermeta
ON wp55_users.ID = wp55_usermeta.user_id
SET wp55_usermeta.meta_value = 'a:1:{s:10:"subscriber";b:1;}'
WHERE
(
(wp55_usermeta.meta_key)='wp55_capabilities'
)
AND
(
(wp55_usermeta.meta_value)="a:1:{s:13:"bbp_spectator";b:1;}"
);

Note that the following will need to be changed to suit your environment:

  • wp55 = this is the WordPress database name
  • SET wp55_usermeta.meta_value = ‘a:1:{s:10:”subscriber“;b:1;}’ = Change the subscriber part to whatever you want the user role to be after the change is made
  • “a:1:{s:13:”bbp_spectator“;b:1;}” = This is the existing user role that you want to change

Once you are happy that everything is correct, you can click the Go button at the bottom right of the SQL page. This will then go off and make the changes you have asked to make.

WordPress Confirmation

Then log in to your WordPress administration portal and check the users, they should now be Subscribers instead of Spectators!

Feedback

If you have any problems with this and you need help, please feel free to leave us a message in the comments section.

If you have found that this has helped you out, then great! Let us know below in the comments!

WordPress – How to Exclude a Category from your Homepage

How to Exclude a Category from your Homepage

Introduction

If you are a WordPress user, you may want to find a way of excluding a certain category from your main homepage. This could be if you post latest news articles but do not want them to clutter up your homepage.

The reason I wanted to exclude a certain category was that I run daily giveaways through a partner site and did not want them on the homepage, as it would just be full of them and none of my other posts!

There are a few methods to carry this out, but I am going to show you how to do this with some simple code. However, if you would rather use a WordPress plugin, then you should check out this part of the article:

Use a WordPress Plugin

WordPress plugins are great and usually very simple to use. However, you have to take into consideration things like:

“Will it slow your website down?”

“Is the plugin secure?”

Will the plugin be compatible with my website?

Will the plugin break my website?

But, let’s be honest, most plugins are perfectly safe so long as they are kept up to date and you should always check out the reviews for them to help you make your decision.

That being said, before I decided to go with the coded method, I did try out these three WordPress plugins and they all did the job perfectly well. However, due to the amount of plugins I use already, I decided that I did not want another one for this process.

Use Code

Some people bulk at the mere thought of adding additional code into the WordPress core files. However, it really is not that complicated to make minor changes to get excellent results.

Category ID

Before you start with any coding, you will first need the category ID of the category you want to exclude from your homepage. This is a unique number allocated to each category within your own WordPress installation.

To get this, go to your WordPress dashboard and go to Posts > Categories:

WordPress Portal Categories Menu
WordPress Portal Categories Menu

You will now see a list of all the categories that you have in your WordPress. Find the category that you want to exclude and then click on the Edit link:

WordPress Edit Category
WordPress Edit Category

This will now take you to the detailed area of the category where you can make a number of changes. However, we are interested in the browser address bar. For this guide I am using Google Chrome, but it should be the same with other browsers like Firefox or Edge.

Looking in the address bar, you will see in the middle of the URL that it has category&tag_ID=530 (530 being my category that I am excluding – yours will be different!):

WordPress Category Tag ID
WordPress Category Tag ID

The number is what you need – this is the ID of the category. In my example above, the category ID that I want to exclude from my homepage is 530.

Backup your WordPress

Now before we go any further, any mistakes here could break your website. So ensure that you follow the instructions carefully, but most importantly, backup your site now! Check out the most reliable WordPress backup service for your business to carry out a backup.

At least then, if the worst was to happen, you can revert your site back.

Theme Editor

Now that you have the category ID of the category you want to exclude from your homepage, you will need to add some code to the functions.php file.

To do this, hover over the Appearance link and then click on the Theme Editor link:

WordPress Theme Editor Menu
WordPress Theme Editor Menu

This will take you to the Theme Editor where you can now edit your themes code. The first thing you will need to do is to look towards the top right of the screen and select from the drop down, the theme that you want to edit. When you have selected your theme from the drop down, click on the Select button:

WordPress Select Theme Drop Down
WordPress Select Theme Drop Down

Once you have done that, you will see a list of files underneath this drop down. Find and click on the file named functions.php:

WordPress Theme Functions File
WordPress Theme Functions File

The code

Now to the left of this area, you will see the code that forms the functions.php file. You should now copy and paste the below code into this functions.php file:

function exclude_category_home($query) {
if ($query->is_home ){
$query->set('cat','-530');
}
return $query;
}
add_filter('pre_get_posts','exclude_category_home');

Note the red -530 part of the above code – this means minus category 530. So yes you guessed it, you need to delete the 530 and replace with your categories ID that you retrieved earlier in this guide.

Once you are happy that you have the correct code in place, you should now double and triple check that there are no syntax errors. Sometimes when copying and pasting code, some special characters can become malformed – especially quote marks and dollar signs like are included in this code. The best thing to ensure everything is correct is to manually delete and type in these special characters.

Now you are really happy everything is correct, go ahead and click on the Update File button at the bottom left of the screen.

Refresh your homepage (clear your caches if you have them in place) and you should now see that the category is no long on your homepage!

Feedback

We would love to hear your feedback on this one so please feel free to leave us a message below in our comments section.

Reasons to Choose Gutenberg for WordPress Website Editor

Gutenberg

Here arrives the good news!  With a release of WordPress 5.2, the Gutenberg Editor has also got new updates. The existing  TinyMCE text editor in WordPress has not achieved many changes from along. And, it is now replaced with  Gutenberg Editor. It is named after Johannes Gutenberg. Movable type printing was initially used by him. … Read more

WordPress Plugin – LinkGather

WordPress-Featured-Post

I am delighted to announce the release of our first ever WordPress Plugin – LinkGather. A few weeks ago I needed a full list of all of our posts’ JetPack wp.me shortlinks. Having around 1500 posts published mean’t that it wasn’t an easy task to just copy and paste the links into a text file. … Read more

How to Export WordPress Shortlinks

How-to-Export-WordPress-Shortlinks

Would you like to export all of your published WordPress posts’ wp.me shortlink URLs to a big list quickly and easily? If so, then this post is for you as we show you how, in a few simple steps, you can get all the wp.me links you want.

WordPress Plugin

We have created a WordPress plugin that carries out this task for you, whenever you want! You can go ahead and download it from our site using the button below:

LinkGather WordPress Plugin

You can also install our plugin from the official WordPress Plugin Repository using the button below:

LinkGather WordPress Plugin

Step by Step Guide

The wp.me links are a module of the JetPack plugin installation. I’m sure most of you are familiar with JetPack but if you do not have this module activated, go into your JetPack settings and active it first.

Prerequisites

You will also need to ensure that you either have FTP access or File Manager access to your WordPress installation. This is because we are going to upload a PHP file to the root of your WordPress installation folder. This is the file that we will then run to gather all the wp.me shortlinks and echo them out into a big list within your internet browser.

PHP Code

Once you are happy that you have upload access to the root of your WordPress installation, go ahead and create a simple text file. You can use the built in Windows Notepad, but I’d suggest that you use Notepad++ and it is much better for writing any sort of code. But please, do not try and use Microsoft Word or Google Docs as this will more than like screw up the PHP code formatting.

Once you have your text file, save it to a location of your choice (Desktop is fine) and you can name it anything you like, but for the purposes of this guide, we will use getlinks.php.

Now copy and paste the PHP code below into the text file:

<?php
include "wp-load.php";
$posts = new WP_Query('post_type=any&posts_per_page=-1&post_status=publish');
$posts = $posts->posts;
header('Content-type:text/plain');
foreach($posts as $post) {
switch ($post->post_type) {
default:
$shortlink = wp_get_shortlink($post->ID);
break;
}
echo "\n{$shortlink}";
}
?>

Please be aware of the syntax formatting though, sometimes it can get a bit screwed up copied from a web browser, just check the speech marks and semicolons etc.

Video Demo

See the video below for a quick example of the formatting to look out for and the full process:

Save the text file again so that the file has the PHP in it.

You should now ensure that the file extension is php and not txt which can be a common mistake to make.

Upload to Your WordPress Installation Root

Connect to your WordPress installation root and upload the getlinks.php file.

Do not put it in a subfolder or it will not work.

You are now ready to get all of your published posts wp.me shortlinks. Just go to your blog URL and then add the getlinks.php file to the end of your URL. So for my blog here, you would use:

https://blog.techygeekshome.info/getlinks.php

This should then go off and gather all the shortlinks – this could be a few seconds or maybe longer depending on the size of your site. My blog here has over 1000 posts and it takes 2-3 seconds to complete.

Your web browser should then show you a big list of all your wp.me links:

wp.me shortlinks output

Removing the Blank Lines

You may notice some gaps in the list, this is expected but you can copy and paste this list into something like Microsoft Excel and then just use the Remove Duplicates option under the Data ribbon:

Microsoft Excel Remove Duplicates

You will then get a pop up telling you how many lines it has removed and how many unique values remain:

Removed Duplicates

You will then have a big list of all your wp.me shortlinks!

Feedback

If you have any problems with any steps of this guide, please feel free to leave us a message below in the comments section and we will try to get back to you as soon as we can.

AMP Reports created with Google Analytics

Google-Analytics-Logo

Are you using AMP but now you want to create AMP reports in Google Analytics? Then this guide is for you!

Accelerated Mobile Pages (AMP) seems to be all the rage at the moment. This is because with the advancement of technology with smart phones and tablets, more people are using the internet on smaller screens than ever and this trend is only going to keep going that way.

So when you browse to a website that is using AMP, you will get a sort of stripped back version, a lite version, something quick and simple to load up on a mobile device.

On our blog, we have actually just started using AMP. We had been testing it for a few months and it has been tricky in getting it right for the look of our site and also for the internal linking. Sometimes the AMP would show up for the landing page, but then clicking on an internal link took the visitor to the desktop version. So if you are going to use AMP, make sure you test everything, including links to ensure that you get it right. We do believe that we now have everything correct and should you be viewing our site on a mobile AMP version, we would love to hear your feedback by leaving us a message in the comments section.

You should also ensure that you have AMP reports available to you from whatever analytics system you are using to keep track of AMP visitors and how they are using your site.

As we were testing our AMP pages, we noticed that there are not many AMP reports available for Google Analytics, which is what we use for our site traffic analysis. This lead us to create our own custom AMP reports for all AMP traffic. We will go through the steps to create this report for your own sites.

Prerequisites

For this to work, you need to ensure that you have setup your site for AMP Google Analytics tracking first. There is a guide on how to do this from Google here. Without this, your AMP reports will just be blank.

AMP Reports in Google Analytics Guide

So, first things first. Login to your Google Analytics portal and head to the Administration page.

Creating the Content Grouping

We are going to use Google Analytics Content Grouping to distinguish visitor hits between AMP and non-AMP.

To do this, we need to create the two content groups, so from within the Administration page, on the right side of the three panels, click on Content Grouping:

AMP Reports Content Grouping

In this section, click on the New Content Grouping button:

New Content Grouping

We then need to build the criteria for our AMP traffic.

So, give the group a name, we will use AMP Content Grouping. Then under Group Using Rule Definitions, give the definition a name, we will use AMP Traffic and then define the rule as Page > Contains > /amp/ – this is assuming your AMP traffic is using /amp/ as its page redirection. If you are using something different, make sure you enter it correctly here.

AMP Reports Content Grouping AMP Traffic

We then need to create our definition for non-AMP traffic. So click on Create a new rule set:

Google Analytics Create a new rule set

Then give the definition a name – we are going to use non-AMP traffic. then we need to set the rule as the opposite as our AMP Traffic rule. So, Page > does not contain > /amp/

Google Analytics content grouping does not contain amp

Then click on the Done button. You should now have two rile definitions, one for non-AMP Traffic and one for AMP Traffic:

Google Analytics content grouping Group Definitions

You can then go ahead and click on the Save button.

Viewing the Reports

Come out of the Administration part of your Google Analytics and then click on the Behavior menu option then click on Site Content and then All Pages:

Google Analytics Behaviour Menu

You will now see the Content Grouping option on the report:

Content Grouping on report

Go ahead and click the none dropdown and select the AMP Content Grouping you have just created:

Google Analytics Content Grouping Dropdown

You should now see the report with the two definitions shown, one for non-AMP traffic and one for AMP traffic. At this point, we would love to show you a screen shot, but we cant – because we do not use AMP so we do not have any AMP traffic! But trust us, if you are using AMP traffic, you will now see the two sets of data.

You can then just use it as it is or start to costomise the report further to suit your requirements.

Feedback

We would love to hear your feedback on this article so come and join us on Facebook or Twitter and let us know what you think!