WordPress How to get wp-includes path

Hi Guys, First thing first, I am developing my 3rd wordpress plugin and this one is for public consumption. While developing this plugin I have this problem where I wanted to include PHPMailer class from wp-includes folder. But the way I wanted to do was to make it generic so that plugin won't break with directory changes. This is what I can up with. This solution can be improved and other one will exist too but its worth checking this tip So here are my solutions Pre-requisite to the method below is that wp-content and wp-includes are under same parent folder, which I hope is that case for majority of wordpress installs [crayon-62f3e96b5bde5713918039/] So as you see that what I've done is that I used WP_CONTENT_DIR constant available in wordpress code as of version 3.3.2 Another method is Pre-requisite is that immediate parent to wp-includes is wordpress install folder. ABSPATH returns path to wordpress root. [crayon-62f3e96b5bded547285469/] You can also use $_SERVER['DOCUMENT_ROOT'] but I find above method more reliable in all means. You will need to atleast include your wp-config.php file in order to make above work. There is more expensive way too to iterate through the directories to find your file, but I doubt that that's a good Idea. I guess if you are reading this and have something more to add for other visitors please use comments to add your feedback to this topic.   I hope this helps Cheers,         … [Read more...]

WordPress Creating Admin Menu and Sub Menu

Hi Guys, I am working on a wordpress plugin nowadays and would like to share few concepts with you. One of those is to create Admin Menu and Sub Menus. Menus are integral part of any website, let alone wordpress. Ok so lets get started. Now with wordpress good thing is that you can take your plugin to any limit. Wordpress offers such flexibility that I sometime am overwhelmed with just a thought about what can be achieved. So finally I decided to write my first wordpress plugin. This post is not about developing plugin from scratch but is more on topic about how to go about creating Admin Menu and Sub Menu on the main left Navigation. Wordpress version I am using is 3.3.2 There are 3 topics I will cover in this post. Hooks required for creating Admin Menu Admin Sub Menu A basic landing page when you click on a Menu Item. Ok so lets get started. I assume that you already know what hooks and filters are, If not then you are better off reading this article http://codex.wordpress.org/Plugin_API Ok so you read the above article and now ready to groove. I am in fovor of showing with example so its better If I take that opportunity and create a basic wireframe Plugin and I call this Plugin as "jcorgtestplugin". We will however will just be concentrating on Admin Menu and Sub Menus. You can download the source for what I've done later. Ok first create a folder under plugins directory of your Wordpress Install  /path/to/wordpress/root/wp-content/plugins/jcorgtestplugin, below is how it looks on my machine.   Now create a file called jcorgtestplugin.php under the newly created folder and insert the lines below into that file. [crayon-62f3e96b61559666331779/] Advertisement   Now goto Wordpress administration and the Check you Plugins, Your new plugin will show up in the list as shown below Now if you Activate/Deactivate this plugin Nothing happens. Well that's true because we haven't done … [Read more...]

WordPress Reset Admin Password using automated email, phpMyAdmin or SQLYog

Hi Guys, Ok so embarrassingly I forgot my local wordpress install password. There are too many password I guess I have to remember. Best way to reset your password is to get the reset link through an automated email. Follow the points below Go to your WordPress Login page and  Click on "Lost your password?" link This will take you to a new page. Enter your email address on file for that account. You will get an email with your new password. Idea now is to use this password to login and change is to something secure and something that you can remember. I did that. Because its my local development box I reset it to most secure password on planet. :) I won't reveal that its 123. Ok so another method is query based method and below are the steps to reset your password. Either use phpMyAdmin or SQLYog to connect to your database. I hope that you remember your database passwords. If not let me tell you that you can read another post of mine that talks about resetting mySQL root user password. The article is to reset root password. It can be handy to read that anyway http://jaspreetchahal.org/mysql-reset-root-user-password-linux/ Ok so you've logged in now Select your database from left navigation and goto Query/SQL editor You will have to type this query now [geshi lang="mysql" nums="1" target="_self" ] [crayon-62f3e96b62a92026316582/] [crayon-62f3e96b62a98656461909/] Run that query by Clicking Go in phpMyAdmin or in SQLYog hit F9 Your password is now reset. Try to login again with your new password. If everything went right your should be able to login to your wordpress . Advertisement Third method is to use emergency password reset script Here is a link from where you can get that script. Follow the instructions and you should be good to go http://codex.wordpress.org/User:MichaelH/Orphaned_Plugins_needing_Adoption/Emergency I hope this quick tip will help you. Cheers, … [Read more...]

WordPress Find and Replace content in all blog posts

Hi Guys, I had this dilemma where I have to replace a string a shortcode on every posts that I've written. Well pretty daunting task If I had to go individually to each and every post that I've written. Advertisement   Fortunately for me I know a little bit of SQL :) STOP! STOP! Before you go pass this point Backup you data base. You don't need to backup your file system just the database. Now fire up your SQLYog or phpMyAdmin and select you WP database What I am going to show you is replacing a simple string and replacing a URL with another (really handy if you are moving domains for any number of reasons) Ok so lets replace [myshortcode] to [mynewshortcode]. The table that we are interested in is wp_posts, Please note:  If you are running multiple websites under same database then this table name can have number in it e.g. wp_3_posts etc. make sure that you are running this query on right table. In my example I am running my query on wp_posts [crayon-62f3e96b62d4c082700308/] Now lets repeat the same query for replacing domain name Advertisement [crayon-62f3e96b62d50816762931/] [crayon-62f3e96b62d51513622578/] Now that you know how to do this you can extend the same query to replace anything in your post to a new string. Say if you are using a CDN for your images and your public facing domain has changed, you can change your Images URL in all posts in one hit. Now if you messed it up, I am sure you will not kill me because I told ya to backup your freakin database. So just restore it :) I hope this helps Cheers, … [Read more...]

WordPress Delete post revisions

Hi Guys, I think keeping a saved revision is a good Idea. After all it save you from data loss. But there are sometimes where you do not change your posts too often and want to get rid of auto saves and revisions altogether. This decision is based on space saving or your post database table getting too heavy. This post highlights the way you can turn off auto saving and delete all the previous revisions. I will say Backup your wordpress database now, before you continue reading further. Here is what you can do to backup your database. You can use phpMyAdmin to export your database too. [geshi lang="mysql" nums="1" target="_self" ] [crayon-62f3e96b62f6e260238527/] [crayon-62f3e96b62f73857110174/] Let check how to delete your revisions now Advertisement     Ok so you here we go Fire up your phpMyAdmin as a privileged user. I am using SQLYog to do the same thing. After selecting your database Goto your Query tab and execute this query [crayon-62f3e96b62f74735696776/] [crayon-62f3e96b62f75619654383/] I've just done that and here is the result for what I did. Advertisement   So your revisions are gone now. Now lets see how you can instruct wordpress not to save revision. i.e. disable auto saves. Here is a cheeky solution followed by recommended one Open /path/to/blogroot/wp-admin/post.php file in an editor and on line 164 as of version 3.3.2 you will find this line wp_enqueue_script('autosave'); [crayon-62f3e96b62f76909925425/] Change above line to this // wp_enqueue_script('autosave'); [crayon-62f3e96b62f77806483989/] Now your autosave has been disabled. Recommended: add this line to you wp-config.php file located here /path/to/blogroot/wp-config.php [crayon-62f3e96b62f78063498975/] If you want to limit your auto saves to say a number then open up wp-config.php file again in editor and do this and this line to the file before last require_once … [Read more...]

get_avatar not working

Hi Guys, Quick tip here. Depending on what version of Wordpress you use it become really important that you know what functional API it provides. There have been few changes related to how Wordpress uses Gravatar. get_avatar function is available to be used in themes in general and is available from Wordpress Version 2.5+ Reason why this function won't work You are trying too fast to load your pic from Gravatar. Give it atleast 10 minutes before you can see your picture somewhere.  Get rid of that Browser Cache altogether before trying again.  Make sure that you've assigned you pic to the email address if you are maintaining multiple emails in Gravatar Account. Click on check this gravatar to see if it actually works, as shown below     You will see something like this. If you see something else then your gravatar is not ready yet.   Use function exactly like this when you start   Advertisement   [crayon-62f3e96b631a0036339007/] [crayon-62f3e96b631a3602491950/] Please note that get_the_author_id() is deprecated and you should be using get_the_author_meta('user_email') function instead.  If you are unsure if get_avatar function is present or not then use the code below  [crayon-62f3e96b631a4136462662/] I hope this helps. You will see you gravatar appearing in blogs soon after you sign up. But you can keep above in mind when you are writing your own them or plugin.   Cheers,   … [Read more...]

No Follow vs Do Follow Links

Hi Guys, I am using WordPress and in WordPress all external bound links are by default "No Follow" mainly in the comments section. No Follow means that if Google or any other search engine comes to crawl your site then it should crawl your site only rather than follow the outgoing link. In other words we are telling Search Engines that Please do not follow the links. Why do you need No Follow? As far as my understanding goes it lowers your our website Authority. In other words we are telling Search Engine that if you are hungry then please go next door as I don't have enough food for you. Another know fact is that having No Follow does not really hurt as much but it bring less interest from user to post comments etc. on you site. Mainly No follow is for bots only.   Now the big question: how to make a link No Follow and Do Follow? Ok so lets see You normal link look like this Visit for latest Coupons and Discount vouchers [crayon-62f3e96b63381820615465/] By default it is Do Follow link To tell the search engine bots or so called spiders to NOT crawl a link or in other word NOT to follow a link, you need to add the following attribute to the HTML hyperlink code above: [crayon-62f3e96b63384895204111/] A link example will be Visit for hugely discounted Sports Memorabilias [crayon-62f3e96b63385561741470/] The above link will not be followed by search engines any more     Now I am not into business of link building because I only find some time to write my articles and I work full time too so no time to go search Blog to put my junk up there :) But a Tip from me: When you are trying to host a link on another site, watch out if they use No Follow with their external link. From my understanding if its No Follow then weight of that link is relatively reduced but its just a link and humans will click it if they like it. This post is really useful to … [Read more...]

WooCommerce Increase or Limit number of products shown in Shop

Hi Guys, I keep on sharing some products that I write for my projects and put them for sale in my shop http://jaspreetchahal.org/shop Now most of them are FREE if you search my Blog to download except databases. Now I installed WooCommerce as my e-commerce plugin and I am extremely happy with it. There is one limitation for the basic user such as myself. This is how do I limit number of products displayed in my Shop. By default it will show what ever your "Blog pages show at most" is set to under Settings > Reading   Below is the screen shot showing this   Now this is Ok but what If I want my shop be separated to the above settings. This is what you do, Goto Appearance > Editor and Click on function.php from right hand side Scroll till end and add this line [crayon-62f3e96b63fab433611289/] [crayon-62f3e96b63fb1758482007/] In the above line of code you can replace 15 with whatever value you want.   I hope this helps   Cheers,     … [Read more...]

WordPress How to increase max file size upload limit

Hi Guys, Just a quick tip guys Sometimes you want to upload a file that is larger than your current upload limit how then you can change that limit Well first of all this is not a wordpress problem that is something to do with your settings that you have set in your php.ini file. Two of the important settings are called upload_max_filesize post_max_size Other values that you may consider reviewing are You might want review those ini entries: (If changing above setting does not help then increase these values and try again) session.gc_maxlifetime max_input_time max_execution_time Now if you have access to your php.ini file then search for these properties. In my case I wanted to increase my limit from 8MB to 15MB so this is what I did   ; Maximum allowed size for uploaded files. upload_max_filesize = 15M [crayon-62f3e96b64200575396181/]   This helped me resolve my problem. Hope this will help you too.   If you are on shared hosting make sure you can override these settings in .htaccess files. In .htaccess override these settings: php_value upload_max_filesize    15M php_value post_max_size          15M php_value session.gc_maxlifetime 36000 php_value max_input_time         36000 php_value max_execution_time     36000   Consider reading this article if you want to enable .htaccess if it is not enabled http://www.php.net/manual/en/configuration.changes.php Please share if you got any questions   Cheers. … [Read more...]

wordpress process shortcode in text widget

Hi Guys, I was not aware that when you use ShortCodes in wordpress Text widget it will not process correctly. So I explored many pages before I found the solution. This is a quick Tip on how to fix this situation Ok so Goto Appearance > Editor  Now from the right hand side select your theme function file, generally named functions.php Make sure that button "Update File" at the bottom of the editor. If it doesn't then you don't have write permission on that file so change your file permission to allow you to edit this file from wordpress admin console. ok so once you open this file paste this line of code at the end of the file [crayon-62f3e96b643b1462535504/] [crayon-62f3e96b643b4465711309/]   Save you file by clicking Update File button. Refresh you page and you will see that your shortcode is now processing correctly. If it still does not show then make sure that your ShortCode format is correct.   I hope this helps Cheers,   … [Read more...]