url paths in wordpress

Functions are also available to help determine URLs in wordPress.

  1. plugins_url() — Full plugins directory URL (for example, http://example.com/wp-content/plugins)
  2. includes_url() — Full includes directory URL (for example, http://example.com/wp-includes)
  3. content_url() — Full content directory URL (for example, http://example.com/wp-content)
  4. admin_url() — Full admin URL (for example, http://example.com/wp-admin/)
  5. site_url() — Site URL for the current site (for example, http://example.com)
  6. home_url() — Home URL for the current site (for example, http://example.com)

The home_url() function retrieves the value for home in the wp_options table.

The plugins_url() function will be one of your best friends while building plugins in WordPress.

Parameters:
• $path – (string) (optional) :

Path relative to the plugins URL
• $plugin – (string) (optional):

Plugin file that you want to be relative (that is, pass in __FILE__)

advantages of using the plugins_url() function to determine plugin URLs:

Auto detects SSL, so if SSL is enabled in WordPress, the URL returned would contain https.
• Uses the WP_PLUGIN_URL constant, meaning it can detect the location of the plugin even if the user has moved it to a custom location.
• Supports Multisite using the WPMU_PLUGIN_URL constant.

How plugins are registered:
this function is called register_activation_hook().

The function accepts two parameters as shown here:
<?php register_activation_hook( $file, $function ); ?>
Parameters:
• $file – (string) (required) — Path to the primary
plugin file
• $function – (string) (required) — The function to be
executed when the plugin is activated

<?php
register_activation_hook( __FILE__, ‘hello_myplugin_install’ );
function hello_myplugin_install() {
//do cool activation stuff
}
?>
The first parameter you send the function is the path to your file, using the __FILE__ constant. This is a PHP constant that always contains the absolute path to the file it is called from.
The second parameter is the unique function you want to call when your plugin is activated.
Now that you understand how the register_activation_hook() function works, look at a real-world example. Following is an example of how you can easily verify the version of
WordPress is compatible with your plugin.
<?php
register_activation_hook( __FILE__, ‘hello_install’ );
function boj_install() {
If ( version_compare( get_bloginfo( ‘version’ ), ‘3.2’, ‘<‘ ) )
{
deactivate_plugins( basename( __FILE__ ) ); //
Deactivate our plugin

}
}
?>

 

 

<?php
register_activation_hook( __FILE__, ‘hello_install’ );
function hello_install() {
$hello_myplugin_options = array(
‘view’ => ‘flat’,
‘category’ => ‘alumni’,
‘stage’ => ‘final’

);
update_option( ‘hello_myplugin_options’, $hello_myplugin_options );
}
?>
how to deactive wordpress plugin

<?php register_ deactivation_hook( $file, $function ); ?>
Parameters:
• $file – (string) (required) — Path to the primary
plugin file
• $function – (string) (required) — The function to be executed when the plugin is activated

<?php
register_deactivation_hook( __FILE__,
‘boj_myplugin_uninstall’ );
function boj_myplugin_uninstall() {
//do something
}
?>

how to uninstall wordpress plugin

WordPress provides two different methods for uninstalling a plugin: the uninstall.php file and the uninstall hook.
Uninstall.php

This is typically the preferred method because it keeps all your uninstall code in a separate file. To use this method, create an uninstall.php file and place it in the root directory of your plugin. If this file exists WordPress executes its contents when the plugin is deleted from the WordPress Plugins screen page. Now look at an example using the uninstall.php file:

<?php
// If uninstall not called from WordPress exit
if( !defined( ‘WP_UNINSTALL_PLUGIN’ ) )
exit ();

// Delete option from options table
delete_option( ‘boj_myplugin_options’ );
//remove any additional options and custom tables
?>

Uninstall Hook
The second uninstall method available is the uninstall hook. If you delete a plugin in WordPress and uninstall.php does not exist, WordPress executes the uninstall hook (if it exists).
<?php register_uninstall_hook( $file, $function ); ?>
Parameters:
• $file – (string) (required) — Path to the primary
plugin file
• $function – (string) (required) — The function to be
executed when the plugin is uninstalled

<?php
register_activation_hook( __FILE__, ‘hello_myplugin_activate’
);
function boj_myplugin_activate() {
//register the uninstall function
register_uninstall_hook( __FILE__, ‘hello_myplugin_uninstaller’ );

function hello_myplugin_uninstaller() {
}

what is best to use single quote or double quote in wordpress. Both can be used but best single quote
as follow examples show the same result;
<?php
echo ‘<a href=”http://example.com/”>Visit
Example.com</a>’;
?>
how to use double quote method to escape html
<?php
$hello_myplugin = ‘http://example.com/’;
echo “<a href=’$hello_myplugin’>Visit
Example.com</a>”;?>

urls are very important in wordpress plugin development as described above the methodology for how to create urls system in wordpress plugin

wordpress tutorials