Category Archives: Hooks

– Welcome –

Welcome to WordPress-Saratoga

  • Attendance: / Sign-in Sheet / password
  • Survey 1: Macintosh, Windows, Linux?
  • Survey 2: Freelance, Startup Team Member, Corporate Employee?
  • Survey 3: Beginner, Intermediate, Advanced User?
  • Fundamentals
    • Blogging
      • Write & post, categorize & tag; fresh content, from time to time.
      • Content consists of text, photos, and/or audio/visual media.
      • Accept comments from visitors.
    • WordPress.com
      • Free Hosted Service, Themes, and Widgets (limited)
      • Optimized Resource Utilization, Load Balancing
      • Automatic Version Updating
    • WordPress.org
      • Host a CMS* website on server of own choosing.
      • Unlimited Customization, Access to Code
      • Maintenance is your own Responsibility!
  • This Month’s Question?
  • Introduce Yourself
    • Name, Title, and Background
    • Tell us about your experience with WordPress so far.
    • Where do you plan to go with WordPress?
  • Next Month’s Topic?
  • Other Meetup Groups 

 <- Twitter Site

* Content Management System (CMS) is a computer program that allows publishing, editing and modifying content on a website as well as maintenance from a central interface. Such systems provide procedures to manage workflow in a collaborative environment.


Coding Format – Banner Ratlif Style – The closing control is indented as the last item in the list, and thus properly loses salience. This makes visual scanning easier since the headers of any block are the only thing exdented at that level so that the closing control of the prior block does not interfere with the visual flow of the next block header.


 

01) Hello Dolly

Plugins can modify the behavior and/or appearance of a website by connecting to “hooks”.

At various times while running, WordPress checks to see whether any plugins have registered functions to run at that time. Then these functions are called.

For instance, if your Plugin needs to add information to the text title, it can register a special function which is called when the the_title filter is called.

Another example is the action hook wp_footer which is checked just before the end of the generated page. Code can be inserted at that place.


Hello Dolly is an example of a plugin adding actions at two different hooks, admin_head and admin_notices.

shortened version of the Hello Dolly plugin, in two different color formatsThe above shows different color formats from two text editors: WP (since v4.9) & BBEdit.

php tag: gray/teal
comment: gold/gray
php: purple/blue
declared function: royalblue/black
called function: black/black
variable: cadetblue/black
string: red/pink

zapmap.com/virgin/wp-admin/plugin-editor.php

07) Hooks

At various times while running, WordPress checks to see if any plugins have functions that are registered to run at that time. If so, those functions are executed.


Plugins register their functions to execute at various times using “filter” and “action” hooks.

Action functions return nothing but true, while Filter functions are expected to return something.


 

Use these commands in your plugin:

 add_action( $hook, $myFunction );
 add_filter( $hook, $myFunction );

Look for these commands in the source code of the templates to see where the hooks are executed:

 do_action( "$hook" )
 apply_filters( "$hook", "what_to_filter" )

Look into the wordpress/wp-admin/admin-footer.php template to find the admin_footer_text filter hook. It looks like this:


And, look into the wordpress/wp-admin/admin-header.php template to find the admin_notices action hook.

The conditionals in the code above show that not all admin pages use the same template.


wordpress.org/plugins/search/simply+show+hooks

Glossary

archive page – a list of posts based on a category, taxonomy, post type.

category – to access a limited set of posts.

class – 1) identifies the style to use in the HTML markup.
class – 2) the uninstantiated object in object oriented progamming (OOPS).

directory – what you see as a folder in your GUI, can be referred to as a “directory” in your command-line interface.

footer – bottom of the web page.

GUI – Graphical User Interface, pronounced goo•ey.

head – the HTML tag inside a web page holding data not displayed.

header – the top part of a web page.

hook – a place in core code made accessible to themes & plugins.

id – an identifier in CSS like class, but unique within the web page.

index – 1) points to an element of an array.
index – 2) the first HTML (or PHP) file sought within a directory.

mapping – using a domain you own to access your wp.com blog.

masking – an extreme form of mapping.

menu – list of links to pages or a category of posts.

navigation – menus to other places in a web site.

page – a “post” of the post type page.

permalink – a custom url structure, the permanent link to individual posts.

plugin – a file added to a theme usually to provide widget(s).

post – 1) a single item of “content” stored in the wp_posts database table, which is one of the five types: post, page, attachment, revision, nav_menu_item.
post – 2) a “post” of the post type post.

sanitize – author name, category, and postname get sanitized in permalinks by having spaces replaced with hyphens.

selector –  – in CSS, the rule set with declaration blocks (property name & value) pointing to the HTML element to style.

sidebar – navagation links, to the right or left.

slug – a user-friendly short text used in a permalink.

style – in CSS, a rule consisting of selectors, and declaration blocks.

tag – 1) an element of the HTML markup language.
tag – 2) used like a category (but without hierarchy) to provide more detail to a post.
$tag – 3) the hook parameter in an action function.
tag, template – 4) PHP function that instructs WordPress to “do” or “get” something. Conditional tags are used in template files to change the content displayed on a particular page depending on what conditions that page matches.

template – a PHP file controlling the structure of part of the web page.

theme – a collection of templates creating the look & feel (design) of the website.

UTC – Coordinated Universal Time is a “time standard” and not a time zone like Greenwich Mean Time (GMT) but, in practice, share the same current time.

widget – provided by a plugin to give extra function & structure.

 

frank_ernest