pluging dev
TRANSCRIPT
-
8/11/2019 Pluging Dev
1/7
Pluging Dev
Plugin activation/deactivation
register_activation_hook( __FILE__,
'function_to_execute_after_registration' );
function_to_execute_after_registration(){
}
Called when a plugin is going to be registered or activated
Register_deactivation_hook(__FILE__, function_to_execute)
Local Paths
To determine the local server path to your plugin, youll use the
plugin_dir_path() function. This function extracts the physical
location relative to the plugins directory from its file name.
plugins_url( 'images/icon.png', __FILE__ )
Usefull Urls
WordPress also features various functions to determine URLs in
WordPress. The following is a list of the functions available:
admin_url()Admin URL (http://example.com/wp-admin/)
site_url()Site URL for the current site (http://example.com)
home_url()Home URL for the current site (http://example.com)
includes_url()Includes directory URL (http://example.com/wp-
includes/)
-
8/11/2019 Pluging Dev
2/7
content_url()Content directory URL (http://example.com/wp-
content/)
wp_upload_dir()Returns an array with location information on the
configured uploads Directory
Hook
A hook is simply a PHP function call with various parameters that can
be sent. Following is an
example showing a properly formatted Action hook call:
The add_filter() function is used to execute a Filter action. You are
using the fi lter called the_content, which is the filter for your
post content. This tells WordPress that every time the content is
displayed, it needs to pass through your custom function called
prowp_function().
The add_filter() function can accept four parameters:
1. filter_action (string): The fi lter to use
2. custom_filter_function (string): The custom function to pass the fi
lter through
3. priority (integer): The priority in which this fi lter should run.
When multiple callback
functions are attached to the same hook, the priority parameter
determines the execution
order
4. accepted args (integer): The number of arguments the function
accepts
-
8/11/2019 Pluging Dev
3/7
Popular Filter Hooks
More than 1,500 different hooks are available in WordPress, which is a
bit overwhelming at fi rst.
Fortunately, a handful of them are used much more often than the rest.
This section explores some
of the more commonly used hooks in WordPress.
Some of the more common Filter hooks are:
the_contentApplied to the content of the post or page before
displaying
-
8/11/2019 Pluging Dev
4/7
the_content_rssApplied to the content of the post or page for RSS
inclusion
the_titleApplied to the post or page title before displaying
comment_textApplied to the comment text before displaying
wp_titleApplied to the page before displaying
the_permalinkApplied to the permalink URL
-
8/11/2019 Pluging Dev
5/7
The default_contentFilter hook is useful for setting the default
content when creating a new post
or page. This is helpful if you have a set format for all of your
posts as it can save you valuable
writing time:
Filter hooks are exceptionally powerful for inserting your own
processing into a variety of points in
the Loop processing of each post. Realizing the full power of the
WordPress plugin system means
also using action hooks to fi re your own code in response to eventswithin the WordPress core.
Popular Action Hooks
Some of the more common Action hooks are:
publish_postTriggered when a new post is published.
create_categoryTriggered when a new category is created.
switch_themeTriggered when you switch themes.
admin_headTriggered in the section of the admin dashboard.
wp_headTriggered in the section of your theme.
-
8/11/2019 Pluging Dev
6/7
wp_footerTriggered in the footer section of your theme usually
directly before the tag.
initTriggered after WordPress has finished loading, but before
any headers are sent.
Good place to intercept $_GET and $_POST HTML requests.
admin_init: Same as init but only runs on admin dashboard pages.
user_register: Triggered when a new user is created.
comment_post: Triggered when a new comment is created.
a {
font-size: 14px; color: #000000; text-decoration: none;
}
a:hover { font-size: 14px; color: #FF0000; text-decoration:
underline;}
The wp_footer hook is also a very commonly used Action hook. Using
this hook you can insert any custom code in the footer of the
-
8/11/2019 Pluging Dev
7/7
WordPress theme. This is a great method for adding analytic tracking
code to your website:
var gaJsHost = (("https:" == document.location.protocol) ?
"https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost +
'google-analytics.com/ga.js'
type='text/javascript'%3E%3C/script%3E"));
var pageTracker = _gat._getTracker("UA-XXXXXX-XX");
pageTracker._trackPageview();