When you are developing a website with WordPress and support for Unique Page Sidebars WordPress Plugins then you may noticed when add a sidebar all the widget parameters inputs are empty. Something like the below image

default-inputs

Here with this code example you can auto fill the widget parameters.

Step 1: include a javascript for WordPress admin interface.

wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'admin-custom-js', get_template_directory_uri() . '/resources/js/custom-admin.js', array( 'jquery' ), '1.2', true );

Step 2: Write below codes on your custom-admin.js

/*
---------------------------------------------------------------------------------------
Auto fill input values for WordPress Unique Page Sidebars when creating a synamic sidebar with default values
---------------------------------------------------------------------------------------
*/

jQuery(document).ready( function($) {

    //Finding all inputs from unique page sidebars when creating a sidebar
    $("input[id^=ups_sidebars]").each( function( k, v ) {

        //Finding current input fields id
        id = $( this ).attr( 'id' );

        //Check if it has a default value already
        if ( $( this ).val() == '' ) {

            //Matching if it is the before_title field
            before_title = id.match(/\bbefore_title/);
            if ( before_title ) {
            $( this ).val( '<h3 class="widget-title">' );
            }

            //Matching if it is the after_title field
            after_title = id.match(/\bafter_title/);
            if ( after_title ) {
            $( this ).val( '</h3>' );
            }

            //Matching if it is the before_widget field
            before_widget = id.match(/\bbefore_widget/);
            if ( before_widget ) {
            $( this ).val( '<div id="%1$s" class="widget %2$s">' );
            }

            //Matching if it is the after_widget field
            after_widget = id.match(/\bafter_widget/);
            if ( after_widget ) {
            $( this ).val( '</div>' );
            }

        }

    });

});

That’s all if everything goes fine you will see a interface as the below image shown when adding a sidebar.
input-pre-values

Note: Don’t forget to widget parameters as your need on javascript what you are using when registering a sidebar for your theme.

When you are working with WordPress menu then sometimes you may noticed if no menu is defined it is putting a div wrapper just above the url tag. Here is how you can remove that div and keep ul as it as.

wp_nav_menu( 
    array( 
        'theme_location'  => '', //Just keep this as empty
        'container'       => '', //Keep this one also as empty
        'menu_class'      => 'menu',
        'menu_id'         => 'primary-menu',
        'depth' => '2',
    )
);

Checking if a menu published in WordPress

$has_enabled_main_menu = false; 
$menu_location = 'primary'; //Going to check if this menu location (primary) has a menu as defined
$menu_locations = get_nav_menu_locations();
$menu_object = ( isset( $menu_locations[ $menu_location ] ) ? wp_get_nav_menu_object( $menu_locations[ $menu_location ] ) : null );
if( $menu_object ) {
    $has_enabled_main_menu = true;
}

Sometimes we needs to find all parent pages of current page in WordPress. It is useful to create a breadcrumb. Here is a example code snippet to find all parent pages.

<ul class="page-breadcrumbs">
    <li><a href="<?php echo home_url(); ?>"><?php _e( 'Home', 'mondira' ) ?></a></li>
    <?php
    global $post;
    $parent_id = $post->post_parent;
    $breadcrumbs = array();
    while ( $parent_id ) {
        $page = get_page( $parent_id );
        $breadcrumbs[] = '<li><a href="' . get_permalink( $page->ID ) . '">' . get_the_title( $page->ID ) . '</a></li>';
        $parent_id = $page->post_parent;
    }
    $breadcrumbs = array_reverse( $breadcrumbs );
    foreach ( $breadcrumbs as $crumb ) echo $crumb;
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title();?></a></li>
</ul>

Recently I worked on a site which is using wordpress as it’s cms and creloaded as it’s web shop. So the wordpress was top of the shopping cart and then the shopping cart as webshop. So basically I had to develop the site using wordpress and then had to install that creloaded inside woordpress installation.

For main site wordpress has it’s header (with navigation), footer (with navigation and other contents), sidebar with widgets etc. So when I am visiting the web shop with creloaded I was required to show the same layouts and design. For that I had to use wp xmlrpc to fetch those common features into creloaded system.

XML-RPC functionality is turned on by default since WordPress 3.5. So anyone can use it who is using wp 3.5 or greater without activating xml-rpc via wordpress admin!

All of this can be done with below written 3 steps.
1. Writing XML Client Class
2. Using XML Client
3. Defining XML Server methods in wp functions.php

Note: Here all the things are not well documented, Because I am assuming you are enough expert on wp and did some google and finally here to see a code example of wp xml rpc implementations.
Read more »

If you see any control visual looks is not just what it was looking on interface design mode (or windows style looks) like below 2 images

looks of interface design mode

Without Enable Visual Styles or Windows Classic Looks

Then It means you are skipping a method call from System.Windows.Forms Namespaces, that is EnableVisualStyles

To Enables visual styles or operating system like controls color, fonts and other visual elements for your application just use below code before application run on Main method.

Application.EnableVisualStyles();

as below

[STAThread]
static void Main()
{
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new Form1());
}

It is a common features you may need it several times when you are on the way of a professional C# application development.

Suppose you have a Parent form which has a Textbox control and a Button control. Now you want to click on the button Control then it will open a Sub form or a PopUp form. In which there will be another button or any other control for example DatagridView and you want to click on it and it will return a value to it’s Parent form and that value will display on Parent forms TextBox control as text property.

You can do it by below listed steps.

Step 1 (Parent Form Code):
On parent form button control click event you can call your sub form like below code to open it and get it’s returning values from it’s predefined properties and use it for your textBox control as below.

private void button1_Click(object sender, EventArgs e)
        {
            frmSubForm objSForm = new frmSbFOrm();
            if (objSForm.ShowDialog() == DialogResult.OK) 
            {
                this.txtParent.Text = objSForm.StringProperty;
            }
        }

Step 2 (Sub Form Code):
On the sub form which one is opening after the click on button control of Parent form you can write below code for any events to return the value and exit sub form.

private void button1_Click(object sender, EventArgs e)
        {
             this.StringProperty= "Sample String";
             this.DialogResult = DialogResult.OK;
        }