Friday, August 29, 2014

My First WordPress Plugin - Tutorial Part 1

WordPress Plugin is a set of one or more function that is particularly focused on performing certain task either adding a specific set of features or services to the WordPress weblog. It includes at least a PHP file and other files like css and javascript.

Step 1: Requirements

·         Familiar with basic functionality of WordPress and PHP programming
·         Installed WordPress with administrative privilege

Step 2: Folder Creation

The plugins for the WordPress are kept under the same location at wp_content/plugins. Create a folder with a unique name, the name of the folder should not coincide with other plugin name, as wp_content/plugins/your_plugin_folder_name . This folder is supposed to contain all the required files.

Step 3: File Creation

           Create a normal PHP file as index.php . The file contains the two sections:

3.1.       Plugin Detail

           The descriptions are provided as comment which contains the plugin’s name, description, version and author but there is no limitation to it. You can also add its URI, author URI and license.

The above information is used to display in the plugin section. 

3.2.       Plugin function

           This section is especially focused on the task as the plugin intend to perform. It contains atleast a function and may contain javascript and css files as per the complexity. As for example: a simple filter is shown below to add “Hello World. This is Semicolon Dev” at the end of the content of the pages.

Here, we have used the filter properties of WordPress with the function add_filter(); the filter takes two argument “the_content” which obtains the content of the post and next argument: a function name “helloworld”. This function adds “Hello World. This is Semicolon Dev” to the end of every post.



Thursday, August 21, 2014

Android R.Java file disappeared, not generated or other common issues

What is R file?

It is an auto-generated file by aapt (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory. If you create any component in the activity_main.xml file, id for the corresponding component is automatically created in this file. This id can be used in the activity source file to perform any action on the component.
Note: If you delete R.jar file, android creates it automatically.

How file will be created ?

In file, each resource category will be created as one class. In each resource class all respective elements will be created as static members, means constants. So, we should not change these values. All these are final members also, so we must access them with their class names, like R.drawable.ic_launcher, R.layout.main, etc. See below codes to know how classes will be created for each resource category.

public final class R {  

    public static final class drawable {  
        public static final int ic_launcher=0x7f020000;  
    public static final class id {  
        public static final int menu_settings=0x7f070000;  
    public static final class layout {  
        public static final int activity_main=0x7f030000;  
    public static final class menu {  
        public static final int activity_main=0x7f060000;  
    public static final class string {  
        public static final int app_name=0x7f040000;  
        public static final int hello_world=0x7f040001;  
        public static final int menu_settings=0x7f040002;  

How many classes existed with name R in an android application ?

There are 2 classes available in each android application with name R.
1. First class is part of android core system or android SDK, which can be accessed as android.R .We can see this class in R.class file which is available in android.jar file, which is automatically included in our project by ADT plugin.
2. Second class is part of our application, which can be accessed as yourpackagename.R (yourpackagename is like com.example.semicolonmagazine). If there is support library attached in our project then , we can see two file (one is support library and another is our project which is available in directory gen. This file is visible, only after successful build of your project.

Fig 1                                                                       Fig 2

Problems related to  R file?
·         Errors in res folder (e.g String.xml, menu.xml, other xml files within res folder)
·         May be problem in build target
·         problem in android sdk

Solution For R file not generating?

·         Fix all errors in your XML files
·         Run Project -> Clean (This will delete and regenerate R and BuildConfig)
·         Make sure Project -> Build Automatically is ticked. If not, build it manually via
Menu -> Project -> Build  Project .
·         Wait a few seconds for the errors to disappear.
·         If it doesn't work, delete everything inside the /gen/ folder
·         If it still doesn't work, try right-clicking your project -> Android Tools -> Fix Project Properties.
·         If again doesn’t work, Right-click your project > properties > Android. Look at the Project Build Target and Library sections on the right side of the page. -Your Build Target should match the target in your AndroidManifest.xml. So if it's set to target 17 in AndroidManifest, make sure that the -Target Name is Android 4.2.

·         If it still doesn't work , Make sure all the "import android.R" was removed - Clean again (if this doesn't fix it, restart eclipse and try again)

Hey Google, Android on Eclipse needs more love ! Please fix these minor issues.


© 2013 Echo "Semicolon Developers"; Kathmandu. All rights resevered @ Semicolon Developers Network Pvt. Ltd.. Designed by Templateism

Back To Top