<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>W4dev</title>
	<atom:link href="https://w4dev.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://w4dev.com/</link>
	<description>Best WordPress Plugins</description>
	<lastBuildDate>Mon, 16 Feb 2026 05:15:16 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://w4dev.com/wp-content/uploads/2026/02/w4dev-favicon-150x150.png</url>
	<title>W4dev</title>
	<link>https://w4dev.com/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How WordPress Plugin Auto Update Works</title>
		<link>https://w4dev.com/wp/how-wordpress-plugin-auto-update-works/</link>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Tue, 09 Aug 2022 22:12:08 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">https://w4dev.com/?p=8078</guid>

					<description><![CDATA[<p>WordPress upgrades a plugin when an admin click on update-now button or upload a new zip file. Besides that, a WordPress plugin can also be updated automatically if an admin enables auto-update for that plugin. Here&#8217;s how plugin auto update works. WP_Version_Check When we click on Enable auto-updates for a plugin, WordPress store the plugin&#8217;s [&#8230;]</p>
<p>The post <a href="https://w4dev.com/wp/how-wordpress-plugin-auto-update-works/">How WordPress Plugin Auto Update Works</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">WordPress upgrades a plugin when an admin click on update-now button or upload a new zip file. Besides that, a WordPress plugin can also be updated automatically if an admin enables <strong>auto-update</strong> for that plugin. Here&#8217;s how plugin auto update works.</p>



<h2 class="wp-block-heading">WP_Version_Check</h2>



<p class="wp-block-paragraph">When we click on <strong>Enable auto-updates </strong>for a plugin, WordPress store the plugin&#8217;s folder name in <code>auto_update_plugins</code> option. Later, the plugin (along with other auto update enabled plugin) gets updated on a recurring cron event <code>wp_version_check</code>. <code>wp_version_check</code> cron event is triggered in every 12 hour. </p>



<pre class="wp-block-code"><code lang="php" class="language-php">/**
 * @file wp-includes/update.php
 */

function wp_schedule_update_checks() {
	if ( ! wp_next_scheduled( 'wp_version_check' ) &amp;&amp; ! wp_installing() ) {
		wp_schedule_event( time(), 'twicedaily', 'wp_version_check' );
	}
	// ...
}</code></pre>



<p class="wp-block-paragraph">In cases, WordPress also schedule extra event to run this job when WordPress version check request respond with a <code>ttl</code> property.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">/**
 * @file wp-includes/update.php
 */

function wp_version_check( $extra_stats = array(), $force_check = false ) {
	// ...
	$url = 'http://api.wordpress.org/core/version-check/1.7/?' . http_build_query( $query, '', '&amp;' );

	// ...
	$response = wp_remote_post( $url, $options );

	// ...
	$body = trim( wp_remote_retrieve_body( $response ) );
	$body = json_decode( $body, true );

	// ...
	if ( ! empty( $body['ttl'] ) ) {
		$ttl = (int) $body['ttl'];

		if ( $ttl &amp;&amp; ( time() + $ttl &lt; wp_next_scheduled( 'wp_version_check' ) ) ) {
			// Queue an event to re-run the update check in $ttl seconds.
			wp_schedule_single_event( time() + $ttl, 'wp_version_check' );
		}
	}
	// ...
}</code></pre>



<p class="wp-block-paragraph"><code>wp_version_check</code> cron event is handled by a function named <a href="https://developer.wordpress.org/reference/functions/wp_version_check/" target="_blank" rel="noreferrer noopener">wp_version_check</a>. At the end of this function, WordPress triggers an action named <a href="https://developer.wordpress.org/reference/hooks/wp_maybe_auto_update/" target="_blank" rel="noreferrer noopener">wp_maybe_auto_update</a> which performs the auto update. <a href="https://developer.wordpress.org/reference/hooks/wp_maybe_auto_update/" target="_blank" rel="noreferrer noopener">wp_maybe_auto_update</a> action is only triggered when <a href="https://developer.wordpress.org/reference/functions/wp_version_check/" target="_blank" rel="noreferrer noopener"><code>wp_version_check</code> </a>function runs in the cron context. Means, calling <a href="https://developer.wordpress.org/reference/functions/wp_version_check/" target="_blank" rel="noreferrer noopener">wp_version_check</a> in a plugin will not trigger <a href="https://developer.wordpress.org/reference/hooks/wp_maybe_auto_update/" target="_blank" rel="noreferrer noopener">wp_maybe_auto_update</a> action. <a href="https://developer.wordpress.org/reference/hooks/wp_maybe_auto_update/" target="_blank" rel="noreferrer noopener">wp_maybe_auto_update</a> action is responded by a function named <a href="https://developer.wordpress.org/reference/functions/wp_maybe_auto_update/" target="_blank" rel="noreferrer noopener">wp_maybe_auto_update</a>.</p>



<h2 class="wp-block-heading">WP_Maybe_Auto_Update</h2>



<p class="wp-block-paragraph">Here&#8217;s the function definition</p>



<pre class="wp-block-code"><code lang="php" class="language-php">/**
 * @file wp-includes/update.php
 */

function wp_maybe_auto_update() {
	include_once ABSPATH . 'wp-admin/includes/admin.php';
	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';

	$upgrader = new WP_Automatic_Updater;
	$upgrader-&gt;run();
}</code></pre>



<p class="wp-block-paragraph">So the main task is done in <code>WP_Automatic_Updater</code> class. </p>



<p class="wp-block-paragraph">The <code>$upgrader-&gt;run()</code> method first checks whether automatic update is enabled. </p>



<p class="wp-block-paragraph">Automatic update might be disabled in many ways, defining wp-config constant (<code>AUTOMATIC_UPDATER_DISABLED</code>, <code>DISALLOW_FILE_MODS</code>), using hook (<code>automatic_updater_disabled</code>) and if WordPress is installing something (<code>wp_installing</code> function).</p>



<p class="wp-block-paragraph">The next thing it checks whether current site is the main site of a network (for multisite installation). It doesn&#8217;t process auto update on sub-sites.</p>



<p class="wp-block-paragraph">The next thing WordPress do is create a lock so that the updater doesn&#8217;t run recurrently rather only once. And remove few filters.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">/**
 * @class WP_Automatic_Updater
 */

public function run() {
	if ( $this-&gt;is_disabled() ) {
		return;
	}

	if ( ! is_main_network() || ! is_main_site() ) {
		return;
	}

	if ( ! WP_Upgrader::create_lock( 'auto_updater' ) ) {
		return;
	}
	// ...
}</code></pre>



<h2 class="wp-block-heading">Updating Plugin</h2>



<p class="wp-block-paragraph">Next the process fetch plugin update information, and run each plugin update one by one. Plugin only gets updated if an update is available, auto-update is enabled &amp; minimum php version requirements is met. </p>



<pre class="wp-block-code"><code lang="php" class="language-php">/**
 * @class WP_Automatic_Updater
 */

public function run() {
	// ...
	wp_update_plugins(); // Check for plugin updates.
	$plugin_updates = get_site_transient( 'update_plugins' );
	if ( $plugin_updates &amp;&amp; ! empty( $plugin_updates-&gt;response ) ) {
		foreach ( $plugin_updates-&gt;response as $plugin ) {
			$this-&gt;update( 'plugin', $plugin );
		}
		// Force refresh of plugin update information.
		wp_clean_plugins_cache();
	}
	// ...
}</code></pre>



<p class="wp-block-paragraph">The update process uses <code><a href="https://developer.wordpress.org/reference/classes/automatic_upgrader_skin/" target="_blank" rel="noreferrer noopener">Automatic_Upgrader_Skin</a></code> class as skin, and <code><a href="https://developer.wordpress.org/reference/classes/plugin_upgrader/" target="_blank" rel="noreferrer noopener">Plugin_Upgrader</a></code> class as upgrader. Skin is responsible handing the messages shown on interface, and upgrader is responsible for handing the file download, verification, replacement, deletion etc process. The next process is upgrading the plugin. <code>$upgrader_item</code> is the folder name (or single file name) of the plugin.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">/**
 * @class WP_Automatic_Updater
 */

public function update( $type, $item ) {
	$skin = new Automatic_Upgrader_Skin;

	// ...
	$upgrader = new Plugin_Upgrader( $skin );
	$context  = WP_PLUGIN_DIR;

	// ...
	if ( ! $this-&gt;should_update( $type, $item, $context ) ) {
		return false;
	}

	$upgrader_item = $item-&gt;plugin;

	$upgrade_result = $upgrader-&gt;upgrade(
		$upgrader_item,
		array(
			'clear_update_cache'           =&gt; false,
			// Always use partial builds if possible for core updates.
			'pre_check_md5'                =&gt; false,
			// Only available for core updates.
			'attempt_rollback'             =&gt; true,
			// Allow relaxed file ownership in some scenarios.
			'allow_relaxed_file_ownership' =&gt; $allow_relaxed_file_ownership,
		)
	);
}</code></pre>



<p class="wp-block-paragraph">Now we jump to the <code><a href="https://developer.wordpress.org/reference/classes/plugin_upgrader/upgrade/" target="_blank" rel="noreferrer noopener">Plugin_Upgrader::upgrade</a></code> method. This upgrader method performs a check to see if the plugin does have an update. <code>$r</code> is the plugin update response, <code>$r-&gt;package</code> is the direct link to the new version zip file. Then it runs the upgrade. Following is the code</p>



<pre class="wp-block-code"><code lang="php" class="language-php">/**
 * @class Plugin_Upgrader
 */

public function upgrade( $plugin, $args = array() ) {
	// ...
	$current = get_site_transient( 'update_plugins' );

	// ...
	$r = $current-&gt;response[ $plugin ];
	
	// ...
	$this-&gt;run(
		array(
			'package'           =&gt; $r-&gt;package,
			'destination'       =&gt; WP_PLUGIN_DIR,
			'clear_destination' =&gt; true,
			'clear_working'     =&gt; true,
			'hook_extra'        =&gt; array(
				'plugin' =&gt; $plugin,
				'type'   =&gt; 'plugin',
				'action' =&gt; 'update',
			),
		)
	);
	// ...
);</code></pre>



<p class="wp-block-paragraph">This run method is defined in <code>WP_Upgrader</code> class. First it downloads the package, then extract it to <code>wp-content/upgrade</code> folder, then remove  Then check for plugin file.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">/**
 * @class Wp_Upgrader
 */

public function run( $options ) {
	// ...
	$download = $this-&gt;download_package( $options['package'], true, $options['hook_extra'] );

	// ...
	$delete_package = ( $download !== $options['package'] );

	// ...
	$working_dir = $this-&gt;unpack_package( $download, $delete_package );

	// ...
	$result = $this-&gt;install_package(
		array(
			'source'                      =&gt; $working_dir,
			'destination'                 =&gt; $options['destination'],
			'clear_destination'           =&gt; $options['clear_destination'],
			'abort_if_destination_exists' =&gt; $options['abort_if_destination_exists'],
			'clear_working'               =&gt; $options['clear_working'],
			'hook_extra'                  =&gt; $options['hook_extra'],
		)
	);

	// ...
}</code></pre>



<p class="wp-block-paragraph">There&#8217;s a interesting thing in this <code>install_package</code> method. If the new update zip contains a folder in the root and no other files, it extracts the folder content as the plugin folder / files.  Means, you can zip a plugin of <code>something/my-plugin/file.php</code> as and update. </p>



<p class="wp-block-paragraph">That&#8217;s it.</p>
<p>The post <a href="https://w4dev.com/wp/how-wordpress-plugin-auto-update-works/">How WordPress Plugin Auto Update Works</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Extend WooCommerce Registration form fields</title>
		<link>https://w4dev.com/wp/woocommerce-registration-form-fields/</link>
					<comments>https://w4dev.com/wp/woocommerce-registration-form-fields/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Mon, 19 May 2014 23:49:26 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WooCommerce]]></category>
		<category><![CDATA[WordPress Registration]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=1437</guid>

					<description><![CDATA[<p>As like WordPress, WooCommerce Registration form fields are the same &#8211; User email &#38; Password. Additionally, WC sometime just use the Email field only. This article describes how you can add additional registration form fields to the WC&#8217;s registration form. In this post, we will add two more fields there &#8211; First name &#38; Last name, [&#8230;]</p>
<p>The post <a href="https://w4dev.com/wp/woocommerce-registration-form-fields/">Extend WooCommerce Registration form fields</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">As like WordPress, WooCommerce Registration form fields are the same &#8211; User email &amp; Password. Additionally, WC sometime just use the Email field only. This article describes how you can add additional registration form fields to the WC&#8217;s registration form.</p>



<p class="wp-block-paragraph">In this post, we will add two more fields there &#8211; First name &amp; Last name, and will generate username from first name, last name value rather than email prefix (what WC uses at present).</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h4 class="wp-block-heading">Table of Contents</h4>



<ul class="wp-block-list">
<li><a href="#add-extra-registration-fields">Add Extra Registration Fields</a></li>



<li><a href="#validate-additional-fields-input">Validate Additional fields input</a></li>



<li><a href="#saving-field-information">Saving Field Information</a></li>
</ul>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading" id="add-extra-registration-fields">Add Extra Registration Fields</h2>



<p class="wp-block-paragraph">Woocommerce has a callback/hook <code>woocommerce_register_form_start</code> to display custom html before their registration form. We are using the hook <code>woocommerce_register_form_start</code> to display our first &amp; last name field.</p>



<p class="wp-block-paragraph">Below code will add First/Last name fields right at the top of the registration box.</p>



<pre class="wp-block-code"><code lang="php" class="language-php line-numbers">&lt;?php
function w4dev_woocommerce_register_form() {
    $fields = array(
        'first_name' 	=&gt; 'First name',
        'last_name' 	=&gt; 'Last name'
    );
    foreach ( $fields as $k =&gt; $v ) {
        $val = '';
        if ( ! empty( $_POST[$k] ) ) {
            $val = $_POST[$k];
        }
        ?&gt;
        &lt;p class="form-row form-row-wide"&gt;
            &lt;label for="&lt;?php echo $k; ?&gt;"&gt;&lt;?php echo $v; ?&gt; &lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt;
            &lt;input type="text" class="input-text" name="&lt;?php echo $k; ?&gt;" id="&lt;?php echo $k; ?&gt;" value="&lt;?php esc_attr( $val ); ?&gt;" /&gt;
        &lt;/p&gt;
        &lt;?php
    }
}
﻿add_action( 'woocommerce_register_form_start', 'w4dev_woocommerce_register_form' );
?&gt;</code></pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading" id="validate-additional-fields-input">Validate Additional fields input</h2>



<p class="wp-block-paragraph">The next part is to validate the form field values whether someone tries to register. We are making sure all of these fields are required and can not be left empty. Thus, we are generating errors using proper hook <code>woocommerce_process_registration_errors which comes with a argument $validation_error</code>. Argument <code>$validation_error</code> is a WP_Error object. We just need to add error to this object if there&#8217;s any invalid value used on our newly created fields.</p>



<pre class="wp-block-code"><code lang="php" class="language-php line-numbers">&lt;?php
function w4dev_registration_errors( $validation_error, $username, $password, $email ) {
    if ( ! isset( $_POST['first_name'] ) || empty( $_POST['first_name'] ) ) {
        $validation_error-&gt;add('error', 'Please enter your First name');
    } elseif ( ! isset( $_POST['last_name'] ) || empty( $_POST['last_name'] ) ) {
        $validation_error-&gt;add( 'error', __( 'Please enter your Last name' ) );
    }
    return $validation_error;
}
add_filter( 'woocommerce_process_registration_errors', 'w4dev_woocommerce_registration_errors', 10, 4 );
?&gt;</code></pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading" id="saving-field-information">Saving Field Information</h2>



<p class="wp-block-paragraph">Once the fields has been placed on the registration form, and we are properly validating the inputs,<br>the next thing we need is to save those fields information. For that we will be using the following code &#8211;</p>



<pre class="wp-block-code"><code lang="php" class="language-php line-numbers">function w4dev_woocommerce_new_customer_data( $data ) {
    /**
     * generate username from first/last name field input
     * only if username field is inactive
     */
    if ( 'no' !== get_option( 'woocommerce_registration_generate_username' ) || ! empty( $username ) ) {
        $username = sanitize_user( wc_clean( $_POST['first_name'] ) );
        if ( username_exists( $username ) ){
            $username .= sanitize_user( wc_clean( $_POST['last_name'] ) );
        }

        // Ensure username is unique
        $append     = 1;
        $o_username = $username;

        while ( username_exists( $username ) ) {
            $username = $o_username . $append;
            $append ++;
        }
        $data['user_login'] = $username;
    }

    /**
     * wordpress will automatically insert this information's into database, 
     * we just need to include it here
    **/
    $data['first_name'] = wc_clean( $_POST['first_name'] );
    $data['last_name'] = wc_clean( $_POST['last_name'] );

    return $data;
}
add_filter( 'woocommerce_new_customer_data', 'w4dev_woocommerce_new_customer_data' );</code></pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Conclusion</h2>



<p class="wp-block-paragraph">Now put all of the codes together and place it on your themes functions.php file. Either you could place it also on an active plugin.</p>
<p>The post <a href="https://w4dev.com/wp/woocommerce-registration-form-fields/">Extend WooCommerce Registration form fields</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/wp/woocommerce-registration-form-fields/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Categories, Tags, Terms Custom Order</title>
		<link>https://w4dev.com/wp/categories-tags-terms-custom-order/</link>
					<comments>https://w4dev.com/wp/categories-tags-terms-custom-order/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Tue, 18 Feb 2014 23:22:55 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Terms]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=1230</guid>

					<description><![CDATA[<p>WordPress doesn&#8217;t allow to fetching categories or terms order by their id. You have probably seen, while doing a post query ( get_post(), WP_Query() ), if we set post__in argument with an array of post id, the query exactly order the results by given ids order. But, when using get_terms(), if we pass include argument, [&#8230;]</p>
<p>The post <a href="https://w4dev.com/wp/categories-tags-terms-custom-order/">Categories, Tags, Terms Custom Order</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">WordPress doesn&#8217;t allow to fetching <strong>categories or terms order by their id</strong>. You have probably seen, while doing a post query ( <code>get_post()</code>, <code>WP_Query()</code> ), if we set <code>post__in</code> argument with an array of post id, the query exactly order the results by given ids order. But, when using <code>get_terms()</code>, if we pass <code>include</code> argument, the returning result doesn&#8217;t not come at the order term ids was passed. So, i figured a solution digging the core codes on the file <code>wp-includes/taxonomy.php</code>.</p>



<p class="wp-block-paragraph">We can use any of two available hooks, <code>get_terms_orderby</code> or <code>terms_clauses</code>.</p>



<h3 class="wp-block-heading">Terms Order by provided ids using terms_clauses hook</h3>



<pre class="wp-block-code"><code lang="php" class="language-php">function terms_clauses( $clauses, $taxonomies, $args ) {
    if ( ! empty( $args['include'] ) &amp;&amp; ! empty( $args['orderby_include'] ) ) {
        $ids                = implode( ',', array_map( 'absint', $args['include'] ) );
        $clauses['orderby'] = "ORDER BY FIELD( t.term_id, $ids )";
    }
    return $clauses;
}
add_filter( 'terms_clauses', 'w4dev_terms_clauses', 10, 3 );
    </code></pre>



<p class="wp-block-paragraph">Now, the above code just extends the <code>get_terms()</code> functionality to order by passed ids. To use this on your query, you will need to set an additional argument <code>orderby_include =&gt; true</code>. We can not define the default <code>orderby</code> argument as invalid orderby argument will automatically be remove before any useful hook is available.</p>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading">Terms Order by provided ids using get_terms_orderby hook</h3>



<p class="wp-block-paragraph">Processing using this hook is the same as previous. But here i tried to use an fixed condition &#8211; &#8220;If include argument is defined, and orderby is left empty, we will order by include ids automatically&#8221;.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function w4dev_get_terms_orderby( $orderby, $args ) {
    if ( ! empty( $args['include'] ) &amp;&amp; empty( $orderby ) ) {
        $ids = implode(',', array_map('absint', $args['include']) );
        $orderby = "FIELD( t.term_id, $ids )";
    }
    return $orderby;
}
add_filter( 'get_terms_orderby', 'w4dev_get_terms_orderby', 10, 2 );
</code></pre>



<p class="wp-block-paragraph">I haven&#8217;t noticed any difference using any of these two hooks, none with performance or with compatibility.</p>



<h3 class="wp-block-heading">Example Usage</h3>



<pre class="wp-block-code"><code lang="php" class="language-php">$tags = get_terms( 'post_tag', array( 
    'include'         => array( 21, 11, 31 ), 
    'orderby_include' => true, 
    'hide_empty'      => false 
));</code></pre>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://w4dev.com/wp/categories-tags-terms-custom-order/">Categories, Tags, Terms Custom Order</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/wp/categories-tags-terms-custom-order/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Display Twitter Bootstrap Dropdown on hover by CSS or jQuery</title>
		<link>https://w4dev.com/snippets/bootstrap/bootstrap-dropdown-on-hover-by-css-jquery/</link>
					<comments>https://w4dev.com/snippets/bootstrap/bootstrap-dropdown-on-hover-by-css-jquery/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Sat, 01 Feb 2014 04:47:52 +0000</pubDate>
				<category><![CDATA[Bootstrap]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=1164</guid>

					<description><![CDATA[<p>Want to display Twitter Bootstrap Dropdown on hover ? Here's are some solutions. It can be done using CSS, jQuery Code or a jQuery Plugin</p>
<p>The post <a href="https://w4dev.com/snippets/bootstrap/bootstrap-dropdown-on-hover-by-css-jquery/">Display Twitter Bootstrap Dropdown on hover by CSS or jQuery</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Want to display Twitter Bootstrap Dropdown on hover ? Here&#8217;s are some solutions. It can be done using CSS, jQuery Code or a jQuery Plugin.</p>



<h2 class="wp-block-heading">The CSS solution</h2>



<pre class="wp-block-code"><code lang="css" class="language-css">// make the child list dropdown visible
ul.nav li.dropdown:hover > ul.dropdown-menu {
    display: block;    
}</code></pre>



<h3 class="wp-block-heading">To hide the caret icon on version 3.0</h3>



<pre class="wp-block-code"><code lang="css" class="language-css">.navbar ul.dropdown-menu, .navbar li.dropdown b.caret {
    display: none;
}</code></pre>



<h3 class="wp-block-heading">To hide the caret icon on older version</h3>



<pre class="wp-block-code"><code lang="css" class="language-css">a.menu:after, .dropdown-toggle:after {
    content: none;
}</code></pre>



<p class="wp-block-paragraph">There&#8217;s one dependency with CSS is that, the class <code>open</code> are not applied which could break any other styling you have done. But with pure bootstrap 2.3 &#8211; 3.0 version, it works great.</p>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading">The jQuery Solution</h2>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">jQuery('ul.nav li.dropdown').hover(function() {
  jQuery(this).closest('.dropdown-menu').stop(true, true).show();
  jQuery(this).addClass('open');
}, function() {
  jQuery(this).closest('.dropdown-menu').stop(true, true).hide();
  jQuery(this).removeClass('open');
});</code></pre>



<h3 class="wp-block-heading">Allow click on main menu</h3>



<p class="wp-block-paragraph">The Child menu will be visible on hovering the parent, but the parent menu will not be click-able. The simplest solution is to add a class <code>disabled</code> on the parent menu anchor. You can check reference on <a href="http://stackoverflow.com/a/12653488/712612">stackoverflow</a> </p>



<h3 class="wp-block-heading">Bootstrap Dropdown on Hover jQuery Plugin</h3>



<p class="wp-block-paragraph">Moreover, there&#8217;s also a plugin <a href="http://cameronspear.com/blog/bootstrap-dropdown-on-hover-plugin/">Bootstrap: Dropdown on Hover Plugin</a> written by Cameron Spear.</p>



<pre class="wp-block-code"><code lang="markup" class="language-markup">&lt;ul class="nav">
    &lt;li class="dropdown">
        &lt;a class="dropdown-toggle disabled" href="http://google.com">
            Dropdown &lt;b class="caret">&lt;/b>
        &lt;/a>
        &lt;ul class="dropdown-menu">
            &lt;li>&lt;a href="#">Link 1&lt;/a>&lt;/li>
            &lt;li>&lt;a href="#">Link 2&lt;/a>&lt;/li>
        &lt;/ul>
    &lt;/li>
&lt;/ul></code></pre>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://w4dev.com/snippets/bootstrap/bootstrap-dropdown-on-hover-by-css-jquery/">Display Twitter Bootstrap Dropdown on hover by CSS or jQuery</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/snippets/bootstrap/bootstrap-dropdown-on-hover-by-css-jquery/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress Plugin page without showing in admin menu</title>
		<link>https://w4dev.com/wp/plugin-page-without-showing-menu/</link>
					<comments>https://w4dev.com/wp/plugin-page-without-showing-menu/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Fri, 10 Jan 2014 03:51:21 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=986</guid>

					<description><![CDATA[<p>To exclude Your Plugin page link from wp-admin menu, simply register a menu leaving the parent menu slug empty or null. Template and load plugin page hook will be still available</p>
<p>The post <a href="https://w4dev.com/wp/plugin-page-without-showing-menu/">WordPress Plugin page without showing in admin menu</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">To exclude a Plugin Option Page link from WordPress Admin menu, simply register menu leaving the parent menu slug empty or null.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function w4dev_register_admin_page_menu() {
    $mypage = add_submenu_page( 
        '', 
        'My Plugin Page', 
        'My Plugin Page', 
        'manage_options', 
        'MyPlugInPage', 
        'w4dev_admin_page_content'
    );
    add_action('load-'. $mypage, 'w4dev_load_admin_page_menu' );
}
add_action( 'admin_menu', 'w4dev_register_admin_page_menu' );

function w4dev_load_admin_page_menu(){}
function w4dev_admin_page_content(){}</code></pre>



<p class="wp-block-paragraph">This will create your plugin page without showing it on admin menu. Where you can still use <code>w4dev_load_admin_page_menu</code> function to handle request/action and <code>w4dev_admin_page_content</code> to generate the template for you plugin.</p>
<p>The post <a href="https://w4dev.com/wp/plugin-page-without-showing-menu/">WordPress Plugin page without showing in admin menu</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/wp/plugin-page-without-showing-menu/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress Multiple Post Type Loop &#038; Pagination by Shortcode</title>
		<link>https://w4dev.com/wp/wordpress-multiple-post-type-loop-pagination-shortcode/</link>
					<comments>https://w4dev.com/wp/wordpress-multiple-post-type-loop-pagination-shortcode/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Fri, 10 Jan 2014 01:36:56 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Code Snippet]]></category>
		<category><![CDATA[WordPress Pagination]]></category>
		<category><![CDATA[WordPress Shortcode]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=977</guid>

					<description><![CDATA[<p>This article describe how to create multiple post loop with pagination by shortcode. You might have already know how to create post list with shortcode, here i am extending that with multiple occurrence and pagination. Multiple Post Type Loop &#38; Pagination by Shortcode &#8211; Code For pagination, We are using a custom query argument pg [&#8230;]</p>
<p>The post <a href="https://w4dev.com/wp/wordpress-multiple-post-type-loop-pagination-shortcode/">WordPress Multiple Post Type Loop &#038; Pagination by Shortcode</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">This article describe how to create multiple post loop with pagination by shortcode. You might have already know how to create post list with shortcode, here i am extending that with multiple occurrence and pagination.</p>



<h2 class="wp-block-heading">Multiple Post Type Loop &amp; Pagination by Shortcode &#8211; Code</h2>



<pre class="wp-block-code"><code lang="php" class="language-php">function w4dev_custom_loop_shortcode( $attrs ) {
    static $w4dev_custom_loop;
    if ( ! isset ( $w4dev_custom_loop ) ) {
		$w4dev_custom_loop = 1;
	} else {
		$w4dev_custom_loop ++;
	}

    $attrs = shortcode_atts( array(
        'paging'         => 'pg'. $w4dev_custom_loop,
        'post_type'      => 'post',
        'posts_per_page' => '5',
        'post_status'    => 'publish'
    ), $attrs );

    $paging = $attrs['paging'];
    unset( $attrs['paging'] );

    if ( isset( $_GET[ $paging ] ) ) {
        $attrs['paged'] = $_GET[ $paging ];
    } else {
        $attrs['paged'] = 1;
	}

    $html  = '';
    $custom_query = new WP_Query( $attrs );


    $pagination_base = add_query_arg( $paging, '%#%' );

    if ( $custom_query->have_posts() ) :
	    $html .= '&lt;ul>';
	        while( $custom_query->have_posts()) : $custom_query->the_post();
	        $html .= sprintf( 
	            '&lt;li>&lt;a href="%1$s">%2$s&lt;/a>&lt;/li>',
	            get_permalink(),
	            get_the_title()
	        );
	        endwhile;
	    $html .= '&lt;/ul>';
    endif;

    $html .= paginate_links( array(
        'type'    => '',
        'base'    => $pagination_base,
        'format'  => '?'. $paging .'=%#%',
        'current' => max( 1, $custom_query->get('paged') ),
        'total'   => $custom_query->max_num_pages
    ));

    return $html;
}
add_shortcode( 'w4dev_custom_loop', 'w4dev_custom_loop_shortcode' );</code></pre>



<p class="wp-block-paragraph">For pagination, We are using a custom query argument <code>pg</code> rather than the default <code>page</code>, as this wont effect any of the other pagination on the page. The shortcode can be used multiple times and <code>pg</code> will be increasing with a number, ex pg1, pg2 etc. But you can ofcourse define your own variable name ex: paginate_page, paginate_product, paginate_some or anything but not WordPress protected variables.</p>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading">Usage</h3>



<p class="wp-block-paragraph">The shortcode can be used with <code>[w4dev_custom_loop]</code> in your page or post content. Try copying the code into your themes functions.php or plugin file and then using two shortcode <code>[w4dev_custom_loop]</code> and <code>[w4dev_custom_loop post_type="page"]</code>. This will output you a list of posts and a list of pages. You can paginate both of the list without losing other list pagination. That means, if you are on level 3 of post list, and then navigated page list to level 2, both of the list will have their offset correct.</p>
<p>The post <a href="https://w4dev.com/wp/wordpress-multiple-post-type-loop-pagination-shortcode/">WordPress Multiple Post Type Loop &#038; Pagination by Shortcode</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/wp/wordpress-multiple-post-type-loop-pagination-shortcode/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress Page Add Custom Endpoint</title>
		<link>https://w4dev.com/wp/wordpress-page-add-custom-endpoint/</link>
					<comments>https://w4dev.com/wp/wordpress-page-add-custom-endpoint/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Tue, 07 Jan 2014 19:22:04 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Custom Functions]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=957</guid>

					<description><![CDATA[<p>Extend WordPress Page with Custom Query Variable. Set or get parameter variables using set_query_var &#038; get_query_var. Use parse_request to filter values</p>
<p>The post <a href="https://w4dev.com/wp/wordpress-page-add-custom-endpoint/">WordPress Page Add Custom Endpoint</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Scenario is, you have a page <code>http://example.com/popular/</code>, and you want to add custom query variable for the page which can be retrieve using <code>get_query_var()</code> function to modify template or filter query. So a request to <code>http://example.com/popular/music/2014/usa</code> will make new query variables &#8211; (&lt;<code>popular_category = music</code>, <code>popular_year = 2014</code>, <code>popular_location = usa</code>) available for you.</p>



<p class="wp-block-paragraph">A solution can be achieved using <code>add_rewrite_rule()</code> &amp; <code>add_rewrite_tag()</code> function, but there is a more easier way which will only use one function to make the custom query variable available for the specific page, and won&#8217;t effect any other pages or anything.</p>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading">The Code</h2>



<pre class="wp-block-code"><code lang="php" class="language-php">function popular_page_parse_request( $wp ) {
    // custom variables will only be available on popular page.
    $pageslug = 'popular';

    // get the actual request and parse it down
    if ( isset( $wp->request ) &amp;&amp; strpos( $wp->request, '/' ) ) {
        $requests = explode( '/', $wp->request );

        // array_shift takes out the first path what is the page slug/name.
        // and make sure it's the popular page.
        if ( $pageslug == array_shift( $requests ) ) {
            // set pagename to make sure we have found a page with the name.
            $wp->set_query_var( 'pagename', $pageslug );

            // wordpress automatically try to check if it's an attachment when a parameter is present
            // after pageslug, so we set it false as we do the parsing ourselves.
            $wp->set_query_var( 'attachment', false );

            // we understand this is a valid page, and let WordPress understand there's no error.
            $wp->set_query_var( 'error', false );

            $count = count( $requests );

            if ( $count > 0 ) {
                // stop the canonical redirection, if a url request isn't same as get_permalink( ) or
                // the_permalink( ), then wordpress redirects it to the actual page
                // and removes all parameter after slug name.
                remove_action( 'template_redirect', 'redirect_canonical' );

                // the first parameter will definitely be the category.
                $wp->set_query_var( 'popular_category', $requests[0] );

                // for second one, we check if it could be a year, or it could be the country name.
                if ( isset( $requests['1'] ) ) {
                    // pretty basic checks.
                    if ( 4 == strlen( $requests['1'] ) &amp;&amp; is_numeric( $requests['1'] ) ) {
                        $wp->set_query_var( 'popular_year', $requests[1] );
                    } else {
                        $wp->set_query_var( 'popular_location', $requests[1] );
                    }
                }

                // if location wasn't found yet, and we have third parameter variable.
                if ( isset( $requests['2'] ) &amp;&amp; !isset( $wp->query_vars['popular_location'] ) ) {
                    if ( ! is_numeric( $requests['2'] ) ) {
                        $wp->set_query_var( 'popular_location', $requests[2] );
                    }
                }
            }

            // the final step to set some defaults if no value was available.
            if ( ! isset( $wp->query_vars['popular_category'] ) ) {
                $wp->set_query_var( 'popular_category', 'any' );
            }

            if ( !isset( $wp->query_vars['popular_year'] ) ) {
                $wp->set_query_var( 'popular_year', 'any' );
            }

            if ( !isset( $wp->query_vars['popular_location'] ) ) {
                $wp->set_query_var( 'popular_location', 'any' );
            }
        }
    }
}
add_action( 'parse_request', 'popular_page_parse_request' );</code></pre>



<p class="wp-block-paragraph">Above function processes has been commented for better understanding. Now we can use <code>get_query_var( 'popular_category' )</code> or <code>get_query_var( 'popular_year' )</code> or <code>get_query_var( 'popular_location' )</code> to retrieve specific url custom query variable.</p>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading">Example</h2>



<p class="wp-block-paragraph">We will create a list of posts based on our custom query variable. For that, first we will create a shortcode which will generate content using the custom query variable. And then place the shortcode on the Popular page.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function popular_posts_shortcode( $attrs ) {
    $html  = '';
    $query_args = array( 
        'order'          => 'DESC',
        'orderby'        => 'comment_count',
        'post_type'      => 'post',
        'post_status'    => 'publish',
        'posts_per_page' => -1,
        'meta_query'     => array()
    );

    if ( 'any' != get_query_var( 'popular_category' ) ) {
        $query_args['category_name'] = get_query_var( 'popular_category' );
    }

    if ( 'any' != get_query_var( 'popular_year' ) ) {
        $query_args['year'] = get_query_var( 'popular_year' );
    }

    // i use post custom field to add one or multiple location name with post
    // if you don't have any similar thing, don't use it. Otherwise you will always see empty result.
    if ( 'any' != get_query_var( 'popular_location' ) ) {
        $query_args['meta_query'][] = array( 
            'key' => 'location',
            'value' => array( get_query_var( 'popular_location' ) ),
            'compare' => 'IN'
        );
    }

    $query = new WP_Query( $query_args );

    if ( $query->have_posts() ) {
        $html .= '&lt;ul>';
        while( $query->have_posts() ) : $query->the_post();
        $html .= sprintf( 
            '&lt;li>&lt;a href="%1$s">%2$s&lt;/a> - &lt;span title="posted %3$s ago">posted %3$s ago&lt;/span>&lt;/li>',
            get_permalink(),
            get_the_title(),
            human_time_diff( strtotime( get_post()->post_date ), current_time( 'timestamp' ) )
        );
        endwhile;
        $html .= '&lt;/ul>';
    }

    wp_reset_query();

    return $html;
}
add_shortcode( 'popular_posts', 'popular_posts_shortcode' );</code></pre>



<p class="wp-block-paragraph">Ok, now if you use the shortcode <code>[popular_posts]</code> in your Page (Popular), you should see a list. Try manually entering url appending the popular page and check the results. You can also add some links to you nav menu using direct url of a popular page for quick access by you or user.</p>



<p class="wp-block-paragraph">For ordering/sorting posts, we have used comment_count.</p>
<p>The post <a href="https://w4dev.com/wp/wordpress-page-add-custom-endpoint/">WordPress Page Add Custom Endpoint</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/wp/wordpress-page-add-custom-endpoint/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Using Stylesheet, JavaScript Scripts for WordPress Widget</title>
		<link>https://w4dev.com/wp/loading-scripts-for-widget/</link>
					<comments>https://w4dev.com/wp/loading-scripts-for-widget/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Sun, 05 Jan 2014 01:23:41 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Widget]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=914</guid>

					<description><![CDATA[<p>CSS and Javascript Scripts for Widgets can be used based on widget availability. If you have created a custom widget and need to load stylesheet only if it active on front end, you will have to use is_active_widget WordPress function right after parent::__construct method has been called. Now for using Scripts for Widget outside of [&#8230;]</p>
<p>The post <a href="https://w4dev.com/wp/loading-scripts-for-widget/">Using Stylesheet, JavaScript Scripts for WordPress Widget</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">CSS and Javascript Scripts for Widgets can be used based on widget availability. If you have created a custom widget and need to load stylesheet only if it active on front end, you will have to use <a href="http://codex.wordpress.org/Function_Reference/is_active_widget">is_active_widget</a> WordPress function right after <code>parent::__construct</code> method has been called.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">class MY_Custom_Widget extends WP_Widget {

    function __construct() {
        $widget_ops = array(
            'classname' => 'my_custom_widget',
            'description' => __( 'MY Custom Widget' )
        );
        parent::__construct( 
            'my_custom_widget', 
            __( 'My Custom Widget' ), 
            $widget_ops
        );
    }
    // rest of the widget codes
}
</code></pre>



<p class="wp-block-paragraph">Now for using Scripts for Widget outside of the Widget class, ex: loading stylesheet for <code>calendar</code> widget, you just need to figure out the widget unique id.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function w4dev_load_calendar_scripts() {
    if ( is_active_widget( false, false, 'calendar', true ) ) {
        wp_enqueue_script( 'jquery' );
        wp_enqueue_style( 'something', 'stylesheet_url' ); 
    }
}
add_action( 'wp_head', 'w4dev_load_calendar_scripts');</code></pre>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://w4dev.com/wp/loading-scripts-for-widget/">Using Stylesheet, JavaScript Scripts for WordPress Widget</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/wp/loading-scripts-for-widget/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Extending WordPress Registration Fields</title>
		<link>https://w4dev.com/wp/extend-wordpress-registration-fields/</link>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Wed, 01 Jan 2014 18:18:06 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Registration]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=551</guid>

					<description><![CDATA[<p>WordPress has two registration fields for the default form, email and username. If you need more information, you could use plugins ofcourse. But for some simple fields such as a Name or Full name or Age of the registrants, you might not want to use a plugin. Here is how you can do that. Add [&#8230;]</p>
<p>The post <a href="https://w4dev.com/wp/extend-wordpress-registration-fields/">Extending WordPress Registration Fields</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>WordPress has two registration fields for the default form, email and username. If you need more information, you could use plugins ofcourse. But for some simple fields such as a Name or Full name or Age of the registrants, you might not want to use a plugin. Here is how you can do that.</p>
<hr />
<h2>Add Extra Registration Fields</h2>
<p>We will add three new fields, <strong>First name</strong>, <strong>Last Name</strong>, <strong>Preview Name</strong>. However, these fields are already in use within WordPress, but they did not used it on register form.</p>
<pre class="prettyprint">
add_action( 'register_form', 'w4dev_register_form' );
function w4dev_register_form()
{
    $fields = array(
        'display_name' 	=> 'Preview name',
        'first_name' 	=> 'First name',
        'last_name' 	=> 'Last name'
    );
    foreach( $fields as $k => $v
    ){ ?&gt;
        &lt;p&gt;&lt;label&gt;
        &lt;?php _e($v) ?&gt;
        &lt;br /&gt;&lt;input type=&quot;text&quot; name=&quot;&lt;?php echo $k ?&gt;&quot; id=&quot;wpa_&lt;?php echo $k ?&gt;&quot; class=&quot;input&quot; value=&quot;&quot; /&gt;
        &lt;/label&gt;&lt;/p&gt;
    &lt;?php } ?
    &gt;&lt;input type=&quot;hidden&quot; name=&quot;w4dev_register_fields&quot; value=&quot;1&quot; /&gt;&lt;?php
}
</pre>
<hr />
<h2>Validate Additional fields input</h2>
<p>We are making sure all of these fields are required and can not be left empty. Thus, we are generating errors using proper hook <code>registration_errors</code>.</p>
<pre class="prettyprint">
add_filter( 'registration_errors', 'w4dev_registration_errors', 1, 3 );
function w4dev_registration_errors( $errors, $user_login, $user_email )
{
    $fields = array(
        'display_name' 	=> 'Preview name',
        'first_name' 	=> 'First name',
        'last_name' 	=> 'Last name'
    );

    if( isset($_POST['w4dev_register_fields']) )
        foreach( $fields as $k => $v )
        {
            if( ! isset($_POST[$k]) || '' == $_POST[$k] )
            {
                $errors->add( 'empty_'. $k, __( '<strong>ERROR</strong>: Please enter your '. $v ) );
            }
        }
    }
    return $errors;
}

</pre>
<hr />
<h2>Saving Field Informations</h2>
<p>As said earlier, these are some field that WordPress already use for a user. And we can just pass the value to wp_update_user function to update it. But, if you are using any other custom field name, you will need to use <code>update_user_meta</code> function.</p>
<p><code>user_register</code> hook becomes available just after a new user record has been created, thus a <code>$user_id</code> variable is passed to the hooked function.</p>
<pre class="prettyprint">
add_action( 'user_register', 'w4dev_user_register' );
function w4dev_registration_errors( $user_id )
{
    $user_data = array();
    if( isset($_POST['w4dev_register_fields']) )
    {
        foreach( array( 'display_name', 'first_name', 'last_name') as $k )
        {
            $user_data[$k] = wp_unslash($_POST[$k]);
        }
    }

    if( !empty($user_data) )
    {
        $user_data['ID'] = $user_id;
        wp_update_user( $user_data );
    }
}
</pre>
<p>All of the code above can go on your themes functions.php file or within your plugin.</p>
<p>The post <a href="https://w4dev.com/wp/extend-wordpress-registration-fields/">Extending WordPress Registration Fields</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Facebook Page Like Count WordPress Shortcode</title>
		<link>https://w4dev.com/wp/facebook-page-like-count-wordpress-shortcode/</link>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Wed, 01 Jan 2014 17:04:58 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=552</guid>

					<description><![CDATA[<p>The easiest way to show your facebook page like count is to use the facebook like button. As it comes with a limited module and not show only the number count rather than adding a like or recommend text, somewhere it becomes useless. However they have API to server you the count in number, if [&#8230;]</p>
<p>The post <a href="https://w4dev.com/wp/facebook-page-like-count-wordpress-shortcode/">Facebook Page Like Count WordPress Shortcode</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The easiest way to show your facebook page like count is to use the facebook like button. As it comes with a limited module and not show only the number count rather than adding a like or recommend text, somewhere it becomes useless. However they have API to server you the count in number, if you have proper code.</p>
<pre class="prettyprint">
add_shortcode('fb_likes', 'w4dev_fb_like_count_shortcode' );
function w4dev_fb_like_count_shortcode( $atts )
{
	extract( shortcode_atts( array(
		'page' => 'w4dev'
	), $atts ));
	$count = facebook_like_count( $page );
	return $count;
}
function w4dev_fb_like_count( $page = 'w4dev' ){
	$url = 'http://graph.facebook.com/'. urlencode( $page );
	$content = wp_remote_retrieve_body( wp_remote_request( $url));
	if( is_wp_error( $content))
		return 0;

	$content = json_decode( $content);
	$value = intval( $content-&gt;likes);

	return $value;
}
</pre>
<p>You can use shortcode <code>[fb_likes page="mypage"]</code>, or can use function <code>w4dev_fb_like_count("mypage")</code> to get your Facebook page likes. <code>mypage</code> could be either you facebook page name or page id.</p>
<p>The post <a href="https://w4dev.com/wp/facebook-page-like-count-wordpress-shortcode/">Facebook Page Like Count WordPress Shortcode</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Displaying WordPress Future Posts</title>
		<link>https://w4dev.com/wp/wordpress-future-posts/</link>
					<comments>https://w4dev.com/wp/wordpress-future-posts/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Fri, 27 Dec 2013 10:54:57 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Post]]></category>
		<category><![CDATA[WordPress Shortcode]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=822</guid>

					<description><![CDATA[<p>WordPress doesn&#8217;t include future posts on Blog, Archive, Widget or Single post pages. However that is logical. But yet if someone need to display future posts lists &#38; also display future post on single post page, here is a solution. Shortcode to display the list of future posts function future_postlist_shortcode($atts) { extract( shortcode_atts( array( 'post_type' [&#8230;]</p>
<p>The post <a href="https://w4dev.com/wp/wordpress-future-posts/">Displaying WordPress Future Posts</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>WordPress doesn&#8217;t include future posts on Blog, Archive, Widget or Single post pages. However that is logical. But yet if someone need to display future posts lists &amp; also display future post on single post page, here is a solution.</p>
<h2>Shortcode to display the list of future posts</h2>
<pre class="prettyprint">
function future_postlist_shortcode($atts)
{
    extract( shortcode_atts( array(
        'post_type' => 'post',
        'total'     => '-1',
        'order'     => 'DESC',
        'orderby'     => 'date',
    ), $atts ));


    $html  = '';
    $query = new WP_Query( array( 
        'order'         => $order,
        'orderby'         => $orderby,
        'post_type'         => $post_type,
        'post_status'         => 'future',
        'posts_per_page'    => $total
    ));

    if( $query->have_posts() ):
    $html .= '&lt;ul&gt;';
        while( $query->have_posts()) : $query->the_post();
        $html .= sprintf( 
            '&lt;li&gt;&lt;a href=&quot;%1$s&quot;&gt;%2$s&lt;/a&gt; - 
            &lt;span title=&quot;will be available within %3$s&quot;&gt;in %3$s&lt;/span&gt;&lt;/li&gt;',
            get_permalink(),
            get_the_title(),
            human_time_diff( strtotime(get_post()->post_date), current_time('timestamp') )
        );
        endwhile;
    $html .= '&lt;/ul&gt;';
    endif;

    return $html;
}
add_shortcode( 'future_postlist', 'future_postlist_shortcode' );
</pre>
<p>The shortcode supports few argument. Number of posts to show, Order &amp; Orderby. You can use it like &#8211;</p>
<pre class="prettyprint">[future_postlist total='10' orderby='date' order='ASC']</pre>
<p>Now, this should display list of future posts, with a human readable publishing time, <strong>ex: in 9 hours</strong>, and post title linked to post page. But the problem is, non loggedin user can not see future posts, and for that we will need some more code to add.</p>
<h2>Display future posts for not loggedin user</h2>
<p>On Single post page, non loggedin user do not see future posts. Here we will filter the condition and allow non loggedin user to see future post on Single post page.</p>
<pre class="prettyprint">add_filter( 'the_posts', 'myplugin_the_future_posts', 10, 2 );
function myplugin_the_future_posts( $posts, $query )
{
    global $wpdb;

    // We will skip if -
    // - there's already found posts 
    // - or it isn't a single post page
    // - or User is loggedin
    if( !empty($posts) || ! $query-&gt;is_singular() || is_user_logged_in() )
        return $posts;

    if( $post_name = $query-&gt;get('name') ){
        $post_type = $query-&gt;get('post_type') ? $query-&gt;get('post_type') : 'post';
        $post_status = 'future';
        $post_ID = $wpdb-&gt;get_var( $wpdb-&gt;prepare( "SELECT ID FROM $wpdb-&gt;posts WHERE post_name = %s AND post_type= %s AND post_status= %s", $post_name, $post_type, $post_status ) );
        if( $post_ID ){
            $posts = array( get_post($post_ID) );
        }
    }

    return $posts;
}</pre>
<p>All of the above codes used here, you will need to add that on your plugin or within themes <code>functions.php</code> file.</p>
<p>The post <a href="https://w4dev.com/wp/wordpress-future-posts/">Displaying WordPress Future Posts</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/wp/wordpress-future-posts/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>add_action &#8211; WordPress function to hook on events</title>
		<link>https://w4dev.com/wp/add_action/</link>
					<comments>https://w4dev.com/wp/add_action/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Mon, 23 Dec 2013 05:20:44 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=796</guid>

					<description><![CDATA[<p>add_action is an extremely used WordPress function, constructed using of PHP’s native function call_user_func_array, widely used in WP core, plugin &#038; theme. In other sense, add_action is similar method to JavaScript’s on event binding mechanism – on(‘event’)</p>
<p>The post <a href="https://w4dev.com/wp/add_action/">add_action &#8211; WordPress function to hook on events</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><strong>add_action</strong> is an extremely used WordPress function, constructed using of PHP&#8217;s native function <code>call_user_func_array</code>, widely used in WP core, plugin &#038; theme. In other sense, add_action is similar method to JavaScript&#8217;s <code>on</code> event binding mechanism &#8211; <code>on('event')</code>.</p>
<p>If you dig WordPress Core files and see <code>do_action('somethis')</code>, then the &#8216;something&#8217; is an Action Hook that you can use to do your custom processing using <a href="http://codex.wordpress.org/Function_Reference/add_action"><code>add_action()</code></a> function. A list of WordPress hooks <em>(Action hooks)</em> reference can be found at <a href="http://codex.wordpress.org/Plugin_API/Action_Reference">Action Reference</a>.</p>
<hr />
<h3>Understanding <code>add_action</code>:</h3>
<p>WordPress uses an event binding method, events such as <code>save_post</code>, <code>post_updated</code>, <code>insert_user</code> &#038; lots more. These are called <strong>hook</strong> or <strong>callback</strong>. Each of these hook has it&#8217;s own definition (you can will find that on WordPress Codex pages). These hooks supply one or multiple variables (values), Like, <code>save_post</code> supply <strong>post_id</strong> that is being saved right now, <code>delete_post</code> supply <strong>post_id</strong> what will be deleted right now. These Hooks are used by creating a function and using add_action function with the hook name. Using these hook, you can do your own processing. Ex: you might need to send and email to the site administrator after a post has been saved, or might want to recalculate the social sharing count after post has been updated, and a much more deeper things. I will try to describe a Practical Example.</p>
<hr />
<h3>An Example of <code>add_action</code>:</h3>
<p><strong>Goal</strong>: Send an email to an user email address upon deleting their account.<br />
<strong>Brief</strong>: There are two hook WordPress provide us to use upon user account deletion. <code>delete_user</code> &#8211; that is fired before deleting everything about an user from database, and <code>deleted_user</code> &#8211; that fires after all data regarding that user has been deleted from database. Now, To send the email, we will need to use the first hook &#8216;delete_user&#8217;, because on the second hook <code>deleted_user</code>, user data wont be available on the database. But we will need user email address &#038; that we can get using <code>deleted_user</code> hook.</p>
<p><strong>Code example</strong>:</p>
<pre class="prettyprint">
add_action('delete_user', 'myplugin_send_email_before_delete_user');

// this is a custom function that is hooked,
// the $user_id variable on out function will be passed by the delete_user hook.
function myplugin_send_email_before_delete_user($user_id)
{
    // we are querying the user email from database
    $email = get_user_option('user_email', $user_id);

    // ofcourse you can retrieve more user information and add into email
    wp_mail($email, 'You account has been deleted', 'The mail content.');
}
</pre>
<p>So if you put this code on your plugin or on your active themes functions.php file, an email will be sent to the user, whom account has been just deleted. You can test this by creating an account with your email address and deleting that from the WP Admin -> Users page. You will need to login with an administrator account ofcourse.</p>
<p>If you had a question in mind that how do i know that user_id will be supplied to our function (myplugin_send_email_before_delete_user), the answer is, i read that on the WP Codex page, You can read that also &#8211; <a href="http://codex.wordpress.org/Plugin_API/Action_Reference/delete_user">delete_user</a>.</p>
<hr />
<h3>Custom Hook</h3>
<p>Rather than the hook&#8217;s WP made available on their framework, we can create additional hook for our own purpose. That is done using <code>do_action(')</code> function. Example: We can add a hook to our function we have created <code>myplugin_send_email_before_delete_user</code> which will allow us or others to add an action on it.</p>
<pre class="prettyprint">
// this is a custom function that is hooked,
// the $user_id variable on out function will be passed by the delete_user hook.
function myplugin_send_email_before_delete_user($user_id)
{
    // we are querying the user email from database
    $email = get_user_option('user_email', $user_id);

    // ofcourse you can retrieve more user information and add into email
    wp_mail($email, 'You account has been deleted', 'The mail content.');

    // the new line we just added
    do_action('myplugin_user_deletion_notified', $user_id);
}
</pre>
<p>On the code, the last line means we are allowing others to use our custom hook to do something. As like we have used <code>save_post</code> hook, we can now also use the &#8216;myplugin_user_deletion_notified&#8217; to do some more thing, ex: notify admin about this deletion, check the next example.</p>
<hr />
<h3>Notify Admin Regarding User Account Deletion</h3>
<pre class="prettyprint">
add_action('myplugin_user_deletion_notified', 'myplugin_notify_admin_about_deletion');

// the $user_id variable will be passed by the myplugin_user_deletion_notified hook.
function myplugin_notify_admin_about_deletion($user_id)
{
    // we are querying the user name from database
    $user_name = get_user_option('display_name', $user_id);

    // we are querying the admin email from database
    $admin_email = get_option('admin_email');

    // send mail
    wp_mail( 
        $admin_email, 
        'User Account Deleted', // subject
        'Hi Admin, An account has been deleted from the site. User name was - '. $user_name // content
    );
}
</pre>
<p>I hope you understand the concept of hooks and using <code>add_action()</code>.</p>
<p>The post <a href="https://w4dev.com/wp/add_action/">add_action &#8211; WordPress function to hook on events</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/wp/add_action/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Create WordPress Plugin</title>
		<link>https://w4dev.com/wp/create-wordpress-plugin/</link>
					<comments>https://w4dev.com/wp/create-wordpress-plugin/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Sun, 22 Dec 2013 06:57:32 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Developing WordPress Plugin]]></category>
		<category><![CDATA[WordPress Customization]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=784</guid>

					<description><![CDATA[<p>Creating a WordPress Plugin is very simple if you have a basic PHP knowledge. A single PHP file can be used as a WordPress Plugin having some structured information. Lets try creating your first WordPress Plugin.</p>
<p>The post <a href="https://w4dev.com/wp/create-wordpress-plugin/">Create WordPress Plugin</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Developing or writing a WordPress Plugin is very simple if you have a basic PHP knowledge. A single PHP file can be used as a WordPress Plugin having some structured information.</p>
<p>To create a PHP file, you can use notepad, or if you already have any advanced editor, that&#8217;s fine also.</p>
<h2>Step 1: Creating plugin file:</h2>
<p>Plugin file is just a simple PHP file. But containing some structured data at the top of the file, commented information in general. Plugin file name can be anything, but majority of the cases, it is a sanitized name of the plugin. Ex: if you are creating a plugin named &#8220;James Analytics&#8221;, the suitable name for the file would be &#8220;james-analytics.php&#8221;. But it&#8217;s not a required thing. The plugin data should be only on the plugin file, not all of the file that are used by the plugin.</p>
<hr />
<h2>Step 2: Adding plugin information to the file:</h2>
<p>For each and every WordPress Plugin, the minimum information needed to be provided within plugin file is <strong>Plugin Name</strong>.</p>
<pre class="prettyprint">&lt;?php
/**
 * Plugin Name: MyPlugin
 */
?&gt;</pre>
<p>Some more information can be added here such as plugin version, author name, but those are all optional information&#8217;s and can be left empty.</p>
<p>Now the basic structure is set, and it can be used as a Plugin.</p>
<p>The plugin doesn&#8217;t have any feature yet. So lets add something that will do act like a plugin and do something.</p>
<hr />
<p>Let&#8217;s create an Email feature for your plugin, to send a notification email to the site administrator email address when you plugin is activated.</p>
<h3>Send Email on WordPress Plugin Activation</h3>
<p><script src="https://gist.github.com/shazzad/888b66a09cb71b04daa88d9fbcd688a4.js"></script></p>
<p>On the above code, three native WordPress function has been used. You can learn about their usage from WordPress Codex Page, <a href="http://codex.wordpress.org/Function_Reference/register_activation_hook">register_activation_hook</a>, <a href="http://codex.wordpress.org/Function_Reference/get_option">get_option</a> &amp; <a href="http://codex.wordpress.org/Function_Reference/wp_mail">wp_mail</a> .</p>
<p>We will add another method that will also send an email but only on deactivation.</p>
<h3>Send Email on WordPress Plugin Deactivation</h3>
<p><script src="https://gist.github.com/shazzad/59a7bb090d1db79c098c1a1cd475c511.js"></script></p>
<h3>Now put everything together. It should look like this &#8211; </h3>
<p><script src="https://gist.github.com/shazzad/7557609e7577f25075833bf2ec507339.js"></script></p>
<p>Next thing is to save the file and put it on plugins directory. By default, WP Plugins directory/folder is relative to your WordPress Setup. So if WordPress is setup is at <code>public_html/</code>, plugins directory will be at <code>public_html/wp-content/plugins/</code> . Just upload or drop your file in that folder (no need to create a new folder for it).</p>
<p>Now, You should see your plugin listed besides other plugins of your site. Activating the plugin will send an email to the site administrator&#8217;s email and upon deactivation another email. Note: If you are testing this on localhost such as WAMP/XAMP etc, you wont actually get any email, as localserver doesn&#8217;t come with an email server by default.</p>
<p>So that&#8217;s a small, simple Plugin you have created. Next u might want to add more things to you plugin.</p>
<hr />
<h3>What&#8217;s should do Next ?</h3>
<p>You could check another post that describe how you can capture user&#8217;s login time and save it for future reference &#8211; <a href="https://w4dev.com/wp/add-last-login-time-in-admin-users-column/">User&#8217;s Last login time</a>. Additionally, you could also check the usage of <a href="https://w4dev.com/wp/add_action/">add_action</a> function in your plugin or theme.</p>
<p>The post <a href="https://w4dev.com/wp/create-wordpress-plugin/">Create WordPress Plugin</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/wp/create-wordpress-plugin/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Win Freelancer.com Bid and Get Awarded</title>
		<link>https://w4dev.com/freelance/win-freelancer-com-bid/</link>
					<comments>https://w4dev.com/freelance/win-freelancer-com-bid/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Mon, 25 Nov 2013 03:39:16 +0000</pubDate>
				<category><![CDATA[Freelance]]></category>
		<category><![CDATA[Freelancer]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=751</guid>

					<description><![CDATA[<p>Following some simple steps, you can increase your chance to win freelancer.com bid. Avoid bidding on all project, read requirement carefully, bid within your expertise</p>
<p>The post <a href="https://w4dev.com/freelance/win-freelancer-com-bid/">Win Freelancer.com Bid and Get Awarded</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><strong>Winning freelancer.com bid</strong> is not tough nor so easy. It does not depends on luck, but does on your presentation &amp; reputation. In my opinion, reputation are not the key factor always. Key factor is presentation. Things you should need to keep in mind for your presentation are &#8211; <strong>Clients requirement</strong>, <strong>Clients Geo location</strong>, <strong>Your Experience &amp; working Knowledge</strong>. For bid pricing, just think how much money you would spend to get the same thing done.</p>
<p>If you have an account at freelancer.com and you have no or few reputation / reviews and you have planned to bid on a project, then i have few recommendations for you that might help you to get the project creators attention and get rewarded.</p>
<hr />
<h3>Always go for Projects which match your experience</h3>
<p>No matter if you are a PHP developer or Python, don&#8217;t try to bid on projects from <a href="http://www.freelancer.com/jobs/">Latest Projects</a> page. Try going thought <a href="http://www.freelancer.com/job/">Project Categories</a>, ex: for PHP related jobs &#8211; <a href="http://www.freelancer.com/jobs/PHP/">http://www.freelancer.com/jobs/PHP/</a>, for Magento related job &#8211; <a href="http://www.freelancer.com/jobs/Magento/">http://www.freelancer.com/jobs/Magento/</a>. You can see all available category to work at &#8211; <a href="http://www.freelancer.com/job/">http://www.freelancer.com/job/</a>. Go through it, find a better matched category for you, the go for projects of it.</p>
<hr />
<h3>Read Project description twice</h3>
<p>Read the Project description carefully, Note: Bidding first doesn&#8217;t mean you have a better chance to win. So read the description to understand what the client actually wants.</p>
<hr />
<h3>Look for &#8211; <em>&#8220;Include the word in your bid so that i understand you have read this&#8221;</em></h3>
<p>Experienced &amp; Senior Clients (who already posted couple of projects before) put a note like this <em>Include &#8212;&#8211; In your bid so that i understand you have read this</em>. It&#8217;s very very important that you read that and include the word in your bid description to let them know that you have actually read the project.</p>
<hr />
<h3>Do not waste your bid if the project doesn&#8217;t suit you</h3>
<p>After reading through the project description, if you think you can do 90% of the work, and rest 10% is out of your knowledge, just put 2/3 minute maximum to find a solution by searching for it on Google or Yahoo search engine. If didn&#8217;t find anything helpful, just skip the project and go forward. Remember, if you take a project where you have no solution for few requirements of the project, it will really make you suffer later and at the end, this suffering will effect on your other work and waste a lot of valuable time of yours.</p>
<hr />
<h3>Always ask Questions and Show your Expertise on bid description</h3>
<p>OK, that&#8217;s the most common &amp; hard part to get Clients attention. Showing you Expertise means, tell them something related to the current project requirement, how you will achieve this, what are the alternative, what could be good, what would not be good etc. But <strong>Don&#8217;t bother posting multiple website links that you have done earlier</strong>. After letting them know your expertise, ask them something that you haven&#8217;t understand or need further clarification. This will provoke them to send you some replies, and that&#8217;s where you will get a chance to start a conversation and increase your change to win.</p>
<hr />
<h3>Go for a Price that you think would be best for you to do the work</h3>
<p>Do not consider what price other have bid for, bidding minimum amount could help you a bit to win, but it&#8217;s not correct 80% times. So go for a price which you think would be good for you. Because, usually you wont have a chance to increase the price after getting selected for the project. So select the best suitable price for you, as if you are happy with the price, you would also be happy to provide a high quality service.</p>
<hr />
<h3>Do no accept before milestone is created</h3>
<p>While you bid, you do post a milestone amount. Milestone amount means, how much money the client will reserve to freelancer.com for paying you. Client must create the amount before you accept and start working on the project. So don&#8217;t accept if client already haven&#8217;t created the milestone amount after awarding you the project. Why not ? Well, asap you accept the project, freelancer will deduct the project fees from your account based on your membership level, and in-case the project creator wish to cancel the project you will be the only victim of it, as project fees aren&#8217;t reversible.</p>
<hr />
<h3>Schedule next conversation / meeting</h3>
<p>You must ask to schedule what is the next time client will be available to communicate. Show interest in communication and try to be online on time. Lack of communication increase high chance of dispute. And yet, if you haven&#8217;t done something on time or as promised, share it with client, but do not ignore their message.</p>
<hr />
<h2>Conclusion</h2>
<p>I am a freelancer too and all i have written here are from my own experience. I hope it could help you. If you do have some tips and want to share, you can post comments and i will include that also. Thank you for reading.</p>
<p>The post <a href="https://w4dev.com/freelance/win-freelancer-com-bid/">Win Freelancer.com Bid and Get Awarded</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/freelance/win-freelancer-com-bid/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WooCommerce Custom Pricing Method for Products</title>
		<link>https://w4dev.com/wp/woocommerce-custom-pricing/</link>
					<comments>https://w4dev.com/wp/woocommerce-custom-pricing/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Sun, 24 Nov 2013 06:55:53 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WooCommerce]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=742</guid>

					<description><![CDATA[<p>WooCommerce have two pricing method for Products &#8211; Regular and Sale price. These methods are used regardless of registered users or visitors. Now, what if you wanna add pricing for some specific user role ? there is plugin for that ofcourse. But how can you make it without using any plugin ? Well, we have [&#8230;]</p>
<p>The post <a href="https://w4dev.com/wp/woocommerce-custom-pricing/">WooCommerce Custom Pricing Method for Products</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"><a href="http://www.woothemes.com/woocommerce" target="_blank" rel="noreferrer noopener">WooCommerce</a> have two pricing method for Products &#8211; <code>Regular</code> and <code>Sale</code> price. These methods are used regardless of registered users or visitors. Now, what if you wanna add pricing for some specific user role ? there is plugin for that ofcourse. But how can you make it without using any plugin ? Well, we have a solution for that, and this article describe that.</p>



<p class="wp-block-paragraph">Adding some PHP codes, we can add an extra pricing method, lets call it <strong>Wholesale Price</strong>. And then set this price for a specific user role. In this article we are calling the new pricing as &#8211; <strong>Wholesale Pricing</strong> &amp; <strong>Editor</strong> is the specific user role to whom the price will be applicable for.</p>



<hr class="wp-block-separator"/>



<h4 class="wp-block-heading" id="1-woocommerce-custom-pricing---table-of-content">Table of Contents</h4>



<ul class="wp-block-list"><li><a href="#3-determine-if-current-user-can-avail-the-wholesale-pricing">Determine if current user can avail the Wholesale Pricing</a></li><li><a href="#4-get-the-wholesale-pricing-value-for-a-product">Get the Wholesale Pricing value for a Product</a></li><li><a href="#5-wholesale-pricing-for-simple-product">Add Wholesale price for Simple product</a></li><li><a href="#9-wholesale-pricing-for-variable-product">Add Wholesale price for Variable product</a></li></ul>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading" id="3-determine-if-current-user-can-avail-the-wholesale-pricing">Determine if current user can avail the Wholesale Pricing</h3>



<pre class="wp-block-code"><code lang="php" class="language-php">// this checks if the current user is capable to have the wholesale pricing
function w4dev_wholesale_applicable() {
    return (bool) ( current_user_can('editor') &amp;&amp; ( !is_admin() || is_ajax() ) );
}</code></pre>



<h3 class="wp-block-heading" id="4-get-the-wholesale-pricing-value-for-a-product">Get the Wholesale Pricing value for a Product</h3>



<pre class="wp-block-code"><code lang="php" class="language-php">// this get the wholesale price when available for both Simple &amp; Variable product type
function w4dev_get_wholesale_price( $product ) {
    if ( 
        $product->is_type( array('simple', 'variable') ) 
        &amp;&amp; get_post_meta( $product->id, '_wholesale_price', true ) > 0 
    ) {
        return get_post_meta( $product->id, '_wholesale_price', true );
    } elseif ( 
        $product->is_type('variation') 
        &amp;&amp; get_post_meta( $product->variation_id, '_wholesale_price', true ) > 0 
    ) {
        return get_post_meta( $product->variation_id, '_wholesale_price', true );
    }
    return 0;
}
﻿</code></pre>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading" id="5-wholesale-pricing-for-simple-product">Wholesale Pricing for Simple Product</h2>



<h3 class="wp-block-heading" id="6-step-one---adding-the-input-field">Step One &#8211; Adding the input field</h3>



<p class="wp-block-paragraph">First, we need to add Wholesale Pricing input to the product editing page. Here&#8217;s the code &#8211;</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function w4dev_woocommerce_product_options_pricing() {
    woocommerce_wp_text_input( array( 
        'id' => '_wholesale_price',
        'class' => 'wc_input_wholesale_price short',
        'label' => __( 'Wholesale Price', 'woocommerce' ) . ' ('.get_woocommerce_currency_symbol().')',
        'type' => 'text'
    ));
}
﻿add_action( 'woocommerce_product_options_pricing', 'w4dev_woocommerce_product_options_pricing' );
</code></pre>



<p class="wp-block-paragraph">After you have added this in your themes functions.php or plugin file, you would see a new input appears under the sale price input (note: Simple Product only).</p>



<div class="wp-block-image"><figure class="aligncenter size-full"><img fetchpriority="high" decoding="async" width="851" height="307" src="https://w4dev.com/wp-content/files/2013/11/woocommerce-wholesale-price-simple-product.png" alt="" class="wp-image-1240" srcset="https://w4dev.com/wp-content/uploads/2013/11/woocommerce-wholesale-price-simple-product.png 851w, https://w4dev.com/wp-content/uploads/2013/11/woocommerce-wholesale-price-simple-product-600x216.png 600w, https://w4dev.com/wp-content/uploads/2013/11/woocommerce-wholesale-price-simple-product-200x72.png 200w" sizes="(max-width: 851px) 100vw, 851px" /></figure></div>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading" id="7-step-two---saving-the-price">Step Two &#8211; Saving the price</h3>



<p class="wp-block-paragraph">Next we need to save the wholesale price value.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">add_action( 'woocommerce_process_product_meta_simple', 'w4dev_woocommerce_process_product_meta_simple', 10, 1 );
function w4dev_woocommerce_process_product_meta_simple( $product_id ) {
    if( isset($_POST['_wholesale_price']) &amp;&amp; $_POST['_wholesale_price'] > 0 )
        update_post_meta( $product_id, '_wholesale_price', $_POST['_wholesale_price'] );
}</code></pre>



<p class="wp-block-paragraph">This code will save the entered value for wholesale price with the product with a custom meta &#8216;_wholesale_price&#8217;.</p>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading" id="8-step-three---frontend-pricing-filter">Step Three &#8211; Frontend pricing filter</h3>



<p class="wp-block-paragraph">Now, to Assign the wholesale price for &#8216;Editor&#8217; we will need to hook into woocommerce_get_price filter.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">add_filter( 'woocommerce_get_price', 'w4dev_woocommerce_get_price', 10, 2);
function w4dev_woocommerce_get_price( $price, $product ) {
    if ( w4dev_wholesale_applicable() &amp;&amp; w4dev_get_wholesale_price($product) > 0 ) {
        $price = w4dev_get_wholesale_price($product);
    }
    return $price;
}</code></pre>



<p class="wp-block-paragraph">All done, Now you can check how it is working by login with any Editor&#8217;s credentials and you should see the product is valued with the wholesale price rather than the sale/regular price. However, all other user/customer should get the sale price as usual.</p>



<p class="wp-block-paragraph">After you have added this in your themes functions.php or plugin file, you would see a new input appears under the sale price input (note: Simple Product only).</p>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading" id="9-wholesale-pricing-for-variable-product">Wholesale Pricing for Variable Product</h2>



<p class="wp-block-paragraph">The above described method is only for Simple Product. The same feature can be added for Variable Product also, read further below.</p>



<h3 class="wp-block-heading" id="10-step-one---adding-the-input-field">Step One &#8211; Adding the input field</h3>



<pre class="wp-block-code"><code lang="php" class="language-php">add_action( 'woocommerce_product_after_variable_attributes', 'w4dev_woocommerce_product_after_variable_attributes', 10, 3 );
function w4dev_woocommerce_product_after_variable_attributes( $loop, $variation_data, $variation ){ ?>
    &lt;tr class="wholesale_price_row">
        &lt;td>
            &lt;div>
                &lt;label>&lt;?php _e( 'Wholesale Price:', 'woocommerce' ); ?>&lt;/label>
                    &lt;input type="text" size="5" name="variable_wholesale_price[&lt;?php echo $loop; ?>]" value="&lt;?php if ( isset( $variation_data['_wholesale_price'][0] ) ) echo esc_attr( $variation_data['_wholesale_price'][0] ); ?>" step="1" min="0" />
            &lt;/div>
        &lt;/td>
    &lt;/tr>&lt;?php
}</code></pre>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" width="851" height="596" src="https://w4dev.com/wp-content/files/2013/11/woocommerce-wholesale-price-variable-product.png" alt="woocommerce-wholesale-price-variable-product" class="wp-image-1239" srcset="https://w4dev.com/wp-content/uploads/2013/11/woocommerce-wholesale-price-variable-product.png 851w, https://w4dev.com/wp-content/uploads/2013/11/woocommerce-wholesale-price-variable-product-600x420.png 600w, https://w4dev.com/wp-content/uploads/2013/11/woocommerce-wholesale-price-variable-product-571x400.png 571w, https://w4dev.com/wp-content/uploads/2013/11/woocommerce-wholesale-price-variable-product-200x140.png 200w" sizes="(max-width: 851px) 100vw, 851px" /></figure></div>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading" id="11-step-two---saving-the-price">Step Two &#8211; Saving the price</h3>



<pre class="wp-block-code"><code lang="php" class="language-php">add_action( 'woocommerce_save_product_variation', 'w4dev_woocommerce_save_product_variation', 10, 2 );
function w4dev_woocommerce_save_product_variation($variation_id, $i)
{
    if( isset($_POST['variable_wholesale_price'][$i]) )
        update_post_meta( $variation_id, '_wholesale_price', $_POST['variable_wholesale_price'][$i]);
}</code></pre>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading" id="12-step-three---frontend-pricing-filter">Step Three &#8211; Frontend pricing filter</h3>



<p class="wp-block-paragraph">The first function <code>w4dev_woocommerce_get_price()</code> and the filter <code>woocommerce_get_price</code> is the same as we have used for the simple product. So, if you add this pricing method for both product type, just ignore the next function and hook.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">if ( ! function_exists( 'w4dev_woocommerce_get_price' ) ) {
    function w4dev_woocommerce_get_price( $price, $product ) {
        if( w4dev_wholesale_applicable() &amp;&amp; w4dev_get_wholesale_price($product) > 0 )
            $price = w4dev_get_wholesale_price($product);
        return $price;
    }
}
add_filter( 'woocommerce_get_price', 'w4dev_woocommerce_get_price', 10, 2);

function w4dev_woocommerce_variation_prices_html( $price, $product ) {
    if ( isset( $product->product_custom_fields['_wholesale_price'][0] ) ) {
        $wholesale_price = $product->product_custom_fields['_wholesale_price'][0];
    } else {
        $wholesale_price = '';
    }

    if ( w4dev_wholesale_applicable() &amp;&amp; $wholesale_price > 0 ) {
        return woocommerce_price( $wholesale_price );
    }

    return $price;
}
add_filter( 'woocommerce_variation_price_html', 'w4dev_woocommerce_variation_prices_html', 10, 2);
add_filter( 'woocommerce_variation_sale_price_html', 'w4dev_woocommerce_variation_prices_html', 10, 2);</code></pre>



<p class="wp-block-paragraph">Thanks.</p>
<p>The post <a href="https://w4dev.com/wp/woocommerce-custom-pricing/">WooCommerce Custom Pricing Method for Products</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/wp/woocommerce-custom-pricing/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WP Admin custom post list page blank</title>
		<link>https://w4dev.com/wp/wp-admin-custom-post-list-page-blank/</link>
					<comments>https://w4dev.com/wp/wp-admin-custom-post-list-page-blank/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Mon, 09 Sep 2013 00:59:46 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=688</guid>

					<description><![CDATA[<p>When i was working with wp e-commerce plugin, i saw product list page is blank. After taking a deeper look i found, WordPress Post List Table Classs loads all the posts at once while post type is hierarchical and there has been no orderby argument. You can check the reference on wp-admin/includes/post.php file on function [&#8230;]</p>
<p>The post <a href="https://w4dev.com/wp/wp-admin-custom-post-list-page-blank/">WP Admin custom post list page blank</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When i was working with wp e-commerce plugin, i saw product list page is blank. After taking a deeper look i found, WordPress Post List Table Classs loads all the posts at once while post type is hierarchical and there has been no orderby argument. You can check the reference on wp-admin/includes/post.php file on function wp_edit_posts_query. So, if the memory is low and the post amount is to much high, the page will be blank.</p>
<p>To get rid of this, you can place the code on any active plugin or in your themes function.php file.</p>
<pre class="prettyprint">add_action( 'load-edit.php', 'fix_hierarchical_post_list' );
function fix_hierarchical_post_list(){
	if( isset($_REQUEST['post_type']) && !isset($_REQUEST['orderby']) ){
		$post_type = $_REQUEST['post_type'];
		if( isset($GLOBALS['wp_post_types'][$post_type]) ){
			$GLOBALS['wp_post_types'][$post_type]->hierarchical = false;
		}
	}
}
</pre>
<p>So here, we are only declaring the current post type to non hierarchical on its list page only.</p>
<p>Hope that helps.</p>
<p>The post <a href="https://w4dev.com/wp/wp-admin-custom-post-list-page-blank/">WP Admin custom post list page blank</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/wp/wp-admin-custom-post-list-page-blank/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Improving Freelancer.com Profile</title>
		<link>https://w4dev.com/freelance/improve-freelancer-profile/</link>
					<comments>https://w4dev.com/freelance/improve-freelancer-profile/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Mon, 30 Apr 2012 04:33:28 +0000</pubDate>
				<category><![CDATA[Freelance]]></category>
		<category><![CDATA[Freelancer]]></category>
		<category><![CDATA[Outsourcing]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=633</guid>

					<description><![CDATA[<p>If you have an account on Freelancer.com, and you are still doing freelancing, then you should try Improving Freelancer.com Profile to get more attention from Clients and get awarded for bid. Except bidding on posted projects, you could also be hired by the hire me widget on your profile page. So all you have to [&#8230;]</p>
<p>The post <a href="https://w4dev.com/freelance/improve-freelancer-profile/">Improving Freelancer.com Profile</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">If you have an account on <a href="http://freelancer.com">Freelancer.com</a>, and you are still doing freelancing, then you should try Improving Freelancer.com Profile to get more attention from Clients and get awarded for bid.</p>



<p class="wp-block-paragraph">Except bidding on posted projects, you could also be hired by the hire me widget on your profile page. So all you have to do is make your profile page as much as complete and make it to look better.</p>



<div class="wp-block-image"><figure class="aligncenter size-full"><img decoding="async" width="953" height="258" src="https://w4dev.com/wp-content/files/2012/04/freelancer-profile-tabs.png" alt="freelancer-profile-tabs" class="wp-image-1302" srcset="https://w4dev.com/wp-content/uploads/2012/04/freelancer-profile-tabs.png 953w, https://w4dev.com/wp-content/uploads/2012/04/freelancer-profile-tabs-600x162.png 600w, https://w4dev.com/wp-content/uploads/2012/04/freelancer-profile-tabs-200x54.png 200w" sizes="(max-width: 953px) 100vw, 953px" /></figure></div>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading" id="1-1-add-profile-picture">1. Add Profile Picture:</h2>



<p class="wp-block-paragraph">For Profile Picture you can use your own or team photo or your company logo. Employers recognize a face much quicker than they do an username or logo. To update your profile photo, visit your <a href="https://www.freelancer.com/users/changeuserinfo.php" target="_blank" rel="noreferrer noopener">freelancer.com account details</a> page. Image size would be 278 px square.</p>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading" id="2-2-add-display-name-subheading-and-summary">2. Add display name, Subheading and Summary:</h2>



<p class="wp-block-paragraph">Give employers a quick introduction about who you are and what services you can offer them. Ensure that your profile is free of spelling mistakes and grammatical errors.</p>



<p class="wp-block-paragraph">For <strong>Display Name</strong>, you might prefer to use your full name or your company name rather than the username you selected when you signed up.</p>



<p class="wp-block-paragraph">Make <strong>use of the subheading</strong> to provide your company slogan or to highlight your top skill that you can offer the employers. Do not use your real name there, as that won&#8217;t put any impact over your profile. Some Example of a better subheading could be &#8211; &#8220;Android Guru&#8221; or &#8220;WordPress Plugin Developer&#8221; or &#8220;SEO Expert&#8221; etc</p>



<p class="wp-block-paragraph">Your summary can be used to tell about yourself, talk about your work history, summarize key points, describe your work ethics and highlight your top skills to ensure employers understand why you’re the right Freelancer for their job. Adding your availability daily hours, week work days &amp; language preference at the bottom would be great.</p>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading" id="3-3-set-an-hourly-rate-that-you-are-willing-to-work-for">3. Set an hourly rate that you are willing to work for:</h2>



<p class="wp-block-paragraph">You can edit your hourly rate underneath the Hire Me button on your profile page. This is optional, but it&#8217;s highly recommend that you fill that. Don&#8217;t set it too high so that anyone don&#8217;t think to reach you, also don&#8217;t let it lowest as this might question your capabilities.</p>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading" id="4-4-use-portfolio-to-showcase-your-best-work">4. Use Portfolio to Showcase Your Best work:</h2>



<div class="wp-block-image"><figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="600" height="548" src="https://w4dev.com/wp-content/files/2013/06/freelancer-portfolio.jpg" alt="freelancer portfolio" class="wp-image-636" srcset="https://w4dev.com/wp-content/uploads/2013/06/freelancer-portfolio.jpg 600w, https://w4dev.com/wp-content/uploads/2013/06/freelancer-portfolio-437x400.jpg 437w, https://w4dev.com/wp-content/uploads/2013/06/freelancer-portfolio-200x182.jpg 200w" sizes="auto, (max-width: 600px) 100vw, 600px" /></figure></div>



<p class="wp-block-paragraph">On your portfolio section, you can upload almost anything including images, text, audio and video. If there is a piece of work that you’re particularly proud of, you can choose to display this as a Featured item. While freelancer.com will not restrict your account if you don’t have a portfolio, they highly recommend you have one. However, in that section freelance designer&#8217;s always get some advantage. As programmer or coded doesn&#8217;t really have visual elements to showcase. In that case, add a brief note about the work and try a relative image from external source.</p>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading" id="5-5-complete-your-resume">5. Complete your Resume</h2>



<p class="wp-block-paragraph">Show Employers examples of your work, highlight all your achievements locally or globally, and display your level of Education. Resumes should tell an employer a great deal about yourself, where you are, where you have been and where you are headed. Convince the employer why you’re the perfect fit for them to hire you.</p>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading" id="6-6-take-exam">6. Take Exam</h2>



<div class="wp-block-image"><figure class="alignright size-full"><a href="http://www.freelancer.com/exam/exams/index.php"><img loading="lazy" decoding="async" width="282" height="383" src="https://w4dev.com/wp-content/files/2012/04/man_award.jpg" alt="" class="wp-image-974" srcset="https://w4dev.com/wp-content/uploads/2012/04/man_award.jpg 282w, https://w4dev.com/wp-content/uploads/2012/04/man_award-200x271.jpg 200w" sizes="auto, (max-width: 282px) 100vw, 282px" /></a></figure></div>



<p class="wp-block-paragraph">Freelancer have a range of technical exams which allow you to certify your skills to potential employers. On passing each exam, a special badge will be added to your profile. This will highlight your abilities and will be displayed next to your bids, to help you stand out from others.</p>



<p class="wp-block-paragraph">Except 3/4 exams, all other exam will charge $5. But good thing is you can use reward point to take an exam. Reward point are automatically achieved when &#8211; you bid on a project, client award you a project, client create a milestone, you complete a project, client leave a review for your completed project and few other events. So, you don&#8217;t have to worry about the reward point, they will come automatically.</p>



<hr class="wp-block-separator"/>



<p class="wp-block-paragraph">Your Profile completion information will be visible on your profile page. Try to complete the profile 100% to take the best advantage on the marketplace.</p>



<div class="wp-block-image"><figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="931" height="111" src="https://w4dev.com/wp-content/files/2012/04/freelancer-complete-profile.png" alt="" class="wp-image-1303" srcset="https://w4dev.com/wp-content/uploads/2012/04/freelancer-complete-profile.png 931w, https://w4dev.com/wp-content/uploads/2012/04/freelancer-complete-profile-600x71.png 600w, https://w4dev.com/wp-content/uploads/2012/04/freelancer-complete-profile-200x23.png 200w" sizes="auto, (max-width: 931px) 100vw, 931px" /></figure></div>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading" id="7-get-inspiration-and-see-examples-of-some-great-user-profiles">Get Inspiration and See Examples of some great user profiles</h2>



<ul class="wp-block-list"><li><a href="https://www.freelancer.com/users/2649161.html">Jericho Domingo</a> – <em>Best Overall Profile</em></li><li><a href="https://www.freelancer.com/users/872249.html">OVX Solutions</a> – <em>Best Developer Profile</em></li><li><a href="https://www.freelancer.com/users/2118054.html">Clifton Johnston</a> – <em>Best Web Designer Profile</em></li><li><a href="https://www.freelancer.com/users/2549044.html">Sevenbros</a> – <em>Best Designer Profile</em></li><li><a href="https://www.freelancer.com/users/2630086.html">The Word Chef</a> – <em>Best Writer Profile</em></li><li><a href="https://www.freelancer.com/users/2180672.html">Sergey Bolshedvorsky</a> – <em>Best Mobile Developer Profile</em></li><li><a href="https://www.freelancer.com/users/2164801.html">Armon Gatus</a> – <em>Best Marketing Profile</em></li></ul>
<p>The post <a href="https://w4dev.com/freelance/improve-freelancer-profile/">Improving Freelancer.com Profile</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/freelance/improve-freelancer-profile/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Integrate Registration with Facebook Account on WordPress Site</title>
		<link>https://w4dev.com/wp/registration-with-facebook-account-on-wordpress-site/</link>
					<comments>https://w4dev.com/wp/registration-with-facebook-account-on-wordpress-site/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Mon, 20 Feb 2012 02:56:59 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Facebook]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=622</guid>

					<description><![CDATA[<p>If you want to build Registration with Facebook Account without using any plugin, this article will help you to do so. All of the codes can be placed on your themes functions.php file, or any file included through that file, or within an active plugin. Step 1: Register Facebook Application Register a facebook application and [&#8230;]</p>
<p>The post <a href="https://w4dev.com/wp/registration-with-facebook-account-on-wordpress-site/">Integrate Registration with Facebook Account on WordPress Site</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">If you want to build <strong>Registration with Facebook Account</strong> without using any plugin, this article will help you to do so. All of the codes can be placed on your themes <code>functions.php</code> file, or any file included through that file, or within an active plugin.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Step 1: Register Facebook Application</h2>



<p class="wp-block-paragraph">Register a facebook application and grab the application id. If you are not sure how to do this, Google <strong>how to register a facebook application</strong> and then visit Facebook application page to register your application.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Step 2: Load Facebook JavaScript SDK</h2>



<p class="wp-block-paragraph">Next, initialize Facebook JavaScript on your WP Site header area. Add the following code. Replace APP_ID with your Facebook application ID/API key.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function FbC_head() {
    if ( is_user_logged_in() ) {
        return;
    }
    ?>
    &lt;script type="text/javascript">
    window.fbAsyncInit = function(){
        FB.init({appId:'APP_ID', status:true, cookie:true, xfbml:true, oauth:true});
    };
    &lt;/script>

    &lt;div id="fb-root">&lt;/div>

    &lt;script type="text/javascript">
    (function() {
    var e = document.createElement('script');
    e.type = 'text/javascript';
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
    }());
    &lt;/script>
    &lt;?php
}
add_action( 'wp_head', 'FbC_head' );
</code></pre>



<p class="wp-block-paragraph">This will be place on head, if the user is not logged in.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Step 3: Insert the button</h2>



<p class="wp-block-paragraph">At this point, insert a button or anchor link to your site and give it a unique CSS id. You can insert it on a widget, or within a page or post content or within your theme template file.</p>



<pre class="wp-block-code"><code lang="markup" class="language-markup">&lt;button id="FbConnect">Connect with facebook&lt;/button>
Or
&lt;a id="FbConnect" href="#">Connect with facebook&lt;/a></code></pre>



<p class="wp-block-paragraph">You can stylize the button as you want with CSS to give it a Facebook button look.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Step 4: Loading jQuery</h2>



<p class="wp-block-paragraph">jQuery library is required to be loaded on the page. It can be safely loaded with the following code &#8211;</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function FbC_enqueue_scripts(){
    wp_enqueue_script( 'jquery' );
}
add_action( 'wp_enqueue_scripts', 'FbC_enqueue_scripts' );</code></pre>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Step 5: Setting up a click event handler for the button</h2>



<p class="wp-block-paragraph">After clicking on the button a popup will appear and Facebook will ask the user to authorize your application (if it hasn’t been yet). If the user cancel the authorization, the poup will close and nothing will happen. But, if he Authorize the application, then we will grab his/her information using Facebook Graph API. Next, we will check if the user already register earlier with the Facebook account, if a match found, we will log him in, else we will create a new account and make the user loging to the site.</p>



<p class="wp-block-paragraph">This code will try to connect the user with your Facebook application, grab a token, and send it to our validator using Ajax.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function FbC_footer() {
	if ( is_user_logged_in() ) :
		// hiding the button for loggedin user using jQuery.
		echo "&lt;script type='text/javascript'>jQuery('#FbConnect').hide(); &lt;/script>";
		return;
	endif;
	?>
	&lt;script type="text/javascript">
	jQuery(document).ready(function(){
		jQuery('#FbConnect').click(FbConnect);
	});

	function FbConnect(){
		FB.login(function(response){
			if ( response.status === 'connected' ){
				jQuery.post( '&lt;?php admin_url('admin-ajax.php'); ?>', {"action": "FbConnect", "FbToken": response.authResponse.accessToken}, function(r){
					if ( ! r.success ){
						alert( r.data.error );
					} else {
						window.location.reload();
					}
				});
			}
			else{
				alert('You are not connected');
			}
		},
		{scope: 'email'});
	}
	&lt;/script>
	&lt;?php
}
add_action( 'wp_footer', 'FbC_footer' );</code></pre>



<h2 class="wp-block-heading">Step 5: Adding the Ajax request handler</h2>



<p class="wp-block-paragraph">The following code should go inside the functions.php file.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function FbConnect_ajax() {
	// check if the token has passed
	if ( empty( $_REQUEST['FbToken'] ) ) {
		wp_send_json_error( array( 'error' => 'Authentication required.' ));
	}

	$FbToken = $_REQUEST['FbToken'];
	$url = "https://graph.facebook.com/me?fields=id,email,username,verified,name&amp;access_token=$FbToken";

	// get the userdata using the token
	$body = wp_remote_retrieve_body( wp_remote_request( $url, array( 'timeout' => '30', 'sslverify' => false ) ) );
	if ( is_wp_error($body) || empty( $body )) {
		wp_send_json_error( array( 'error' => 'Unable to retrieve data.' ));
	}

	$FB_userdata = json_decode( $body );
	if ( is_object( $FB_userdata )) {
		$FB_userdata = get_object_vars( $FB_userdata );
	}

	$FB_userid = (int) $FB_userdata['id'];
	if ( ! $FB_userid ){
		wp_send_json_error( array( 'error' => 'Please Re-connect your facebook account.' ));
	}

	global $wpdb;
	$user_ID = $wpdb->get_var( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '_fbid' AND meta_value = '$FB_userid'" );

	if ( ! $user_ID ) {
		$user_email = $FB_userdata['email'];
		$user_ID = $wpdb->get_var( "SELECT ID FROM $wpdb->users WHERE user_email = '$user_email'" );

		if( ! $user_ID ) {
			// if registration is disabled from General Settings page, not necessary to register a new account
			if ( ! get_option( 'users_can_register' )) {
				wp_send_json_error( array( 'error' => 'Registration is not open at this time. Please come back later..' ));
			}

			extract( $FB_userdata );

			$display_name = $name;
			$user_login = $username;

			// checks if the facebook account is verified
			if ( empty( $verified ) || !$verified ) {
				wp_send_json_error( array( 'error' => 'Your facebook account is un-verified. You have to verify your facebook account before proceed..' ));
			}

			$user_email = $email;
			if ( empty( $user_email )){
				wp_send_json_error( array( 'error' => 'Please re-connect your facebook account. [EMAIL NOT FOUND]' ));
			}

			if ( empty( $display_name )) {
				wp_send_json_error( array( 'error' => 'We didn\'t find your name from facebook. Please complete your facebook account before proceeding..' ));
			}

			// if username empty, try to create from name
			if ( empty( $user_login )) {
				$user_login = sanitize_title_with_dashes( sanitize_user( $display_name, true ));
			}

			$user_login_check = $wpdb->get_var( "SELECT user_login FROM $wpdb->users WHERE user_login = '$user_login' LIMIT 1" );

			// find an available username
			if ( $user_login_check ) {
				$suffix = 2;
				do {
					$alt_user_login = $user_login . "-$suffix";
					$user_login_check = $wpdb->get_var( "SELECT user_login FROM $wpdb->users WHERE user_login = '$alt_user_login' LIMIT 1" );
					$suffix++;
				} while ( $user_login_check );
					$user_login = $alt_user_login;
				}

				$user_login = esc_sql( $user_login );
				$user_pass = wp_generate_password( 12, false );

				$userdata = compact( 'user_login', 'user_email', 'user_pass', 'display_name' );

				$user_ID = wp_insert_user( $userdata );
				if ( is_wp_error( $user_ID )) {
					wp_send_json_error( array( 'error' => 'Unable to register, please try again.' ));
				}

				update_user_meta( $user_ID, '_fbid', (int) $id );
			} else {
				update_user_meta( $user_ID, '_fbid', (int) $FB_userdata['id'] );
			}
		}

		$userdata = new WP_User( $user_ID );
		if ( ! $userdata ) {
			wp_send_json_error( array( 'error' => 'Something went wrong, your account not found. Please try again or contact support' ));
		}
	}

	$userdata = $userdata->data;

	// Let Other hook to the login user information. If they restrict a user for some reason, we will also do that.
	$userdata = apply_filters( 'wp_authenticate_user', $userdata );
	if ( is_wp_error( $userdata )) {
		wp_send_json_error( array( 'error' => $userdata->get_error_message() ) );
	}

	wp_set_auth_cookie( $user_ID, false, false );
	do_action( 'wp_login', $userdata->user_login, $userdata );

	wp_send_json_success( array( 'loggedin' => true ) );
}

add_action( 'wp_ajax_nopriv_FbConnect', 'FbConnect_ajax' );</code></pre>



<p class="wp-block-paragraph">With the wp_ajax_FbConnect’ function, we are checking &#8211;</p>



<ul class="wp-block-list"><li>&#8211; Firstly, we validate the user token and try to fetch his facebook data that we need to create an account.</li><li>&#8211; Secondly, do we already have current facebook user id on our WordPress user meta table, if we found one, we will set login cookie for that user.</li><li>&#8211; Thirdly, do we already have a WP user register with the current facebook users primary email, if we found one, we will set login cookie for that user.</li><li>If these last two method fails, we will mark the current user as an unregistered user and will register him.</li></ul>



<p class="wp-block-paragraph">Any errors will be displayed using JavaScript alert function.</p>



<p class="wp-block-paragraph">If you have placed everything properly, now you have a working Registration with Facebook Account Script for your site.</p>
<p>The post <a href="https://w4dev.com/wp/registration-with-facebook-account-on-wordpress-site/">Integrate Registration with Facebook Account on WordPress Site</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/wp/registration-with-facebook-account-on-wordpress-site/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>JavaScript debugging function similar to PHP var_dump / print_r</title>
		<link>https://w4dev.com/snippets/js/javascript-debugging-function-similar-php-var_dump-print_r/</link>
					<comments>https://w4dev.com/snippets/js/javascript-debugging-function-similar-php-var_dump-print_r/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Mon, 21 Nov 2011 04:31:45 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=635</guid>

					<description><![CDATA[<p>Debug JavaScript array or object as like PHP’s print_r or var_dump function. create your own javascript debugging function</p>
<p>The post <a href="https://w4dev.com/snippets/js/javascript-debugging-function-similar-php-var_dump-print_r/">JavaScript debugging function similar to PHP var_dump / print_r</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">There is no javascript debugging function as like PHP&#8217;s <code>print_r</code> / <code>var_dump</code> function. Here&#8217;s one i have found.</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">/**
* Function : var_dump()
* Arguments: The data - array,hash( associative array),object
* The level - OPTIONAL
* Returns  : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
* Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
*/
function var_dump( arr, level ) {
    var dumped_text = "";
    if ( ! level ) level = 0;

    var level_padding = "";
    for ( var j=0; j&lt;level+1; j++ ) {
        level_padding += "    ";
    }

    if ( typeof(arr) == 'object' ) {
        for ( var item in arr ) {
            var value = arr[item];

            if ( typeof(value) == 'object' ) {
                dumped_text += level_padding+"'"+item+"'=> array(n";
                dumped_text += var_dump( value, level+1 );
                dumped_text += "n" + level_padding + ")n";
            } else {
                dumped_text += level_padding+"'"+item+"'=>""+value+""n";
            }
        }
    } else {
        dumped_text = "===>" + arr + "&lt;===(" + typeof( arr ) + ")";
    }

    return dumped_text;
}

function test_var_dump( arr ) {
    document.getElementById('print_r').innerHTML = '&lt;pre>' + var_dump(arr) + '&lt;/pre>';
}</code></pre>



<p class="wp-block-paragraph">The html <code>div element</code> having id print_r should be placed where you want to see the results. And the JS codes should be placed anywhere between this div and closing body tag but not before this division.</p>



<p class="wp-block-paragraph">Now you can test array value with the <code>test_var_dump</code> function. Example:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">/* Create some array element to test. */

var array_sub1 = new Array( "Hello World", 'Php test', 100, '200' );
var array_sub2 = new Array( "Facebook", 'Google' );
var array_sub3 = {
    'array_sub1': array_sub1,
    'array_sub2' : array_sub2
};
var array_parent = {
    'array_sub1': array_sub1,
    'array_sub2' : array_sub2,
    'array_sub3' : array_sub3
};

/* Test the function */
test_var_dump( array_parent );</code></pre>
<p>The post <a href="https://w4dev.com/snippets/js/javascript-debugging-function-similar-php-var_dump-print_r/">JavaScript debugging function similar to PHP var_dump / print_r</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/snippets/js/javascript-debugging-function-similar-php-var_dump-print_r/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Wp Ajax – WordPress Hook to Handle Ajax Request</title>
		<link>https://w4dev.com/wp/wp_ajax/</link>
					<comments>https://w4dev.com/wp/wp_ajax/#respond</comments>
		
		<dc:creator><![CDATA[Shazzad Hossain Khan]]></dc:creator>
		<pubDate>Wed, 05 Oct 2011 02:45:16 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Functions]]></category>
		<guid isPermaLink="false">http://w4dev.com/?p=615</guid>

					<description><![CDATA[<p>Basic usage of wp_ajax and wp_ajax_nopriv on your WordPress. Add ajaxurl variable on any of your front pages.</p>
<p>The post <a href="https://w4dev.com/wp/wp_ajax/">Wp Ajax – WordPress Hook to Handle Ajax Request</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"><strong>wp_ajax</strong> is not a hook or callback, rather it is just a prefix of hooks or callbacks. Those callbacks&nbsp; are usually available while making ajax call. When a browser or web-client request with an <code>action</code> query parameter to <strong>http://example.com/wp-admin/admin-ajax.php</strong> file, a hook becomes available to use. Which use <code>wp_ajax_</code> as prefix.</p>



<h3 class="wp-block-heading">Brief</h3>



<p class="wp-block-paragraph">A request to <strong>wp-admin/admin-ajax.php?action=contact-us</strong> will make <code>wp_ajax_contact-us</code> action hook available. Here you can see the Action is fired by appending <code>wp_ajax_</code> to the requested <code>action</code> query parameter value <strong>contact-us</strong>. Programmatically, it is <code>'wp_ajax_' . $_REQUEST['action']</code>. Attaching a function with this hook, responses are sent to browser or to the ajax call.</p>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading">Table of content</h3>



<ol class="wp-block-list"><li><a href="#using_wp_ajax_hook">How to use action hook generated by an ajax request</a></li><li><a href="#why_request_admin_ajax_php">Why request to wp-admin/admin-ajax.php file</a></li><li><a href="#wp_ajax_nopriv">What is wp_ajax_nopriv</a></li><li><a href="#wp_ajax_handle_all_request">How to use the hook for both Logged &amp; Not Logged in members</a></li><li><a href="#ajaxurl">What is WordPress ajaxurl</a></li><li><a href="#ajaxurl_front">Adding ajaxurl to Front pages</a></li><li><a href="#example">Example &#8211; Using Ajax in WordPress</a></li></ol>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading" id="using_wp_ajax_hook">How to use the ajax request generated action hook ?</h3>



<p class="wp-block-paragraph">Any request to admin-ajax.php file bring a hook name, and that hook is used to send some response. A function or class method is required to handle the response though. And response handler is attached using <code>add_action()</code> function.<br><strong>Example:</strong> &#8211; <code>add_action( 'wp_ajax_contact-us', 'contact_us_requested_by_ajax' );</code>.<br><strong>Explanation</strong>: Here <code>contact_us_requested_by_ajax</code> is a function you use to do some processing and/or sending some output for the request. You can replace the function name from <code>contact_us_requested_by_ajax</code> to something else ofcourse.</p>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading">Why do i or WP send request to <code>wp-admin/admin-ajax.php</code> file ?</h3>



<p class="wp-block-paragraph">Because, <strong>wp-admin/admin-ajax.php</strong> file was built to handle ajax requests, we can call it as ajax request resolver. This file handles initial processing and enable a chatchable hook after loading all of WordPress core files, active plugin files and themes functions.php file (this makes WP functions available for you to use within the hook). So, all you have to do is to use the hook in your themes functions.php file or inside a plugin file and won&#8217;t have to worry about WordPress file/library inclusion.</p>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading">What is <code>wp_ajax_nopriv</code> ?</h3>



<p class="wp-block-paragraph"><code>wp_ajax_</code> prefix isn&#8217;t used to create the hook name if user is not logged in, therefore <code>wp_ajax_nopriv_</code> is used. <code>wp_ajax_nopriv_</code> does the same thing as <code>wp_ajax_</code> prefix does, <strong>unless it only fires when user is not logged in</strong>. So for not logged-in user the hook name is &#8211; <code>'wp_ajax_nopriv_' . $_REQUEST['action']</code>, and for logged-in user it is <code>'wp_ajax_' . $_REQUEST['action']</code>.</p>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading">How to use the hook for both logged-in/not-logged-in User/visitor ?</h3>



<p class="wp-block-paragraph">Simple. use both <code>wp_ajax_</code> and <code>wp_ajax_nopriv_</code> prefixed hook with your function. Example &#8211;</p>



<pre class="wp-block-code"><code lang="php" class="language-php">add_action( 'wp_ajax_contact-us', 'contact_us_requested' );
add_action( 'wp_ajax_nopriv_contact-us', 'contact_us_requested' );</code></pre>



<p class="wp-block-paragraph">Note: Not both of the hook will be fired at once for a single request, as WordPress itself do user/non-user validation and triggers the appropriate hook. So your function will be called only once not twice. — for further assistance, you could explore <code>admin-ajax.php</code> file inside <code>wp-admin</code> directory for reference.</p>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading">What is WordPress <code>ajaxurl</code></h3>



<p class="wp-block-paragraph"><strong>ajaxurl</strong> is a common JavaScript variable which holds the ajax request handler file uri. In WordPress it is the url of <code>yoursite.com/wp-admin/admin-ajax.php</code> file. WordPress automatically include this variable on every page on <strong>WP Admin</strong> pages, but not on the front pages (post/page/category/author/search/tag etc). Developer define this JS variable or create a different variable, but purpose is the same &#8211; assigning ajax request handler url on a JS variable. Example: Contact Form 7 add their own variable name as <code>wpcf_ajax_url</code>.</p>



<hr class="wp-block-separator"/>



<h3 class="wp-block-heading">How to add <code>ajaxurl</code> variable name to WordPress site Front pages ?</h3>



<p class="wp-block-paragraph">If you are enqueuing any javaScript at front, this variable can be added using <code>wp_localize_script</code> function.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function w4dev_enqueue_scripts() {
    wp_register_script( 'myjs', 'https://example.com/script.js' );

    wp_localize_script( 
        'myjs', 
        'myjs', 
        array( 
            'ajaxurl' => admin_url( 'admin-ajax.php' ) 
        )
    );

    wp_enqueue_script( 'myjs' );
}
add_action( 'wp_enqueue_scripts', 'w4dev_enqueue_scripts' );</code></pre>



<p class="wp-block-paragraph">However, if you are not loading any js file, this can also be added by using the below codes on your theme/plugin file. In this code, custom function <code>w4dev_ajaxurl_cdata_to_front</code> hook&#8217;s to <code>wp_head</code> and print js which defines the ajaxurl for global use.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function w4dev_ajaxurl_cdata_to_front(){ 
    ?>
    &lt;script type="text/javascript"> //&lt;![CDATA[
        ajaxurl = '&lt;?php echo admin_url( 'admin-ajax.php'); ?>';
    //]]&gt; &lt;/script>
    &lt;?php 
}
add_action( 'wp_head', 'w4dev_ajaxurl_cdata_to_front', 1 );</code></pre>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading">Simplest Example &#8211; Using Ajax in WordPress</h2>



<p class="wp-block-paragraph"><strong>Goal</strong>: Display Site Description upon clicking on an Anchor.<br><strong>Brief</strong>: First, we will add a link with a unique HTML/CSS id attribute ( within content are ex: sidebar, content, footer etc or hardcode in theme template files ) and use jQuery onclick function to send a request to ajaxurl and display the return value using Javascript alert.</p>



<p class="wp-block-paragraph">Anchor to be placed:</p>



<pre class="wp-block-code"><code lang="markup" class="language-markup">&lt;a id="view_site_description" href="javascript:void(0);">View Our Site Description&lt;/a></code></pre>



<p class="wp-block-paragraph">Next, Adding the JavaScript codes using wp_footer hook.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function add_js_to_wp_footer(){ ?>
    &lt;script type="text/javascript">
    jQuery('#view_site_description').click(function(){
        jQuery.ajax({
            type: 'POST',
            url: ajaxurl,
            data: {"action": "view_site_description"},
            success: function(data){alert(data);}
        });
        return false;
    });
    &lt;/script>
&lt;?php }
add_action( 'wp_footer', 'add_js_to_wp_footer' );</code></pre>



<p class="wp-block-paragraph">Add this to your themes functions.php or a plugin file</p>



<p class="wp-block-paragraph"><strong>Explanation</strong>: In the above code, we have used jQuery OnClick event. Whenever, an element having id <code>view_site_description</code> is clicked, jQuery will Send a HTTP POST request to the ajaxurl ( <code>wp-admin/admin-ajax.php</code> file ) with a query string <code>action=view_site_description</code>. and the return value will be shown as an JavaScript alert.</p>



<p class="wp-block-paragraph">You read earlier that, a request to <strong>wp-admin/admin-ajax.php</strong> file creates a WP Action hook, and using the hook we can produce anything we want. A request to the <code>admin-ajax.php</code> file will make available <code>wp_ajax_view_site_description</code> or <code>wp_ajax_nopriv_view_site_description</code> hook if action parameter value is set to <code>view_site_description</code></p>



<p class="wp-block-paragraph">Next create a function to process the request and display site description.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function view_site_description(){
    echo get_bloginfo( 'description', 'display' );
    exit;
}
add_action( 'wp_ajax_view_site_description', 'view_site_description' );
add_action( 'wp_ajax_nopriv_view_site_description', 'view_site_description' );</code></pre>



<p class="wp-block-paragraph">Add this to your themes functions.php or a plugin file.</p>



<p class="wp-block-paragraph">Now if everything is OK and well placed, clicking on the link will alert you with your site description. Put the last three block of code on your theme, and try it yourself.</p>



<p class="wp-block-paragraph"><strong>Notice:</strong> If your theme does not loads jQuery, then you will need to add few line of code to load jQuery. Below code will load jQuery, you can paste this code on your theme&#8217;s functions.php file.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">function w4dev_enqueue_jquery(){
    wp_enqueue_script( 'jquery' );
}
add_action( 'wp_enqueue_scripts', 'w4dev_enqueue_jquery');</code></pre>



<p class="wp-block-paragraph">That&#8217;s it, hope this writing helped you to understand Using Ajax in your WordPress site &amp; wp_ajax.</p>



<hr class="wp-block-separator"/>



<h4 class="wp-block-heading">Related Reference</h4>



<ul class="wp-block-list"><li><a href="http://codex.wordpress.org/AJAX_in_Plugins">AJAX in Plugins</a></li><li><a href="http://wp.smashingmagazine.com/2011/10/18/how-to-use-ajax-in-wordpress/">How to use Ajax</a></li></ul>
<p>The post <a href="https://w4dev.com/wp/wp_ajax/">Wp Ajax – WordPress Hook to Handle Ajax Request</a> appeared first on <a href="https://w4dev.com">W4dev</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://w4dev.com/wp/wp_ajax/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
