Content Management

Professional Practice

Themes

How far have you been?

  • Child theme?
  • Full theme?
  • Theme versionning (main repository)?
  • Theme versionning (as a submodule)?

Advantages/Drawbacks

  • See lecture 02
  • What have you learnt in trying?

Module progress

Currently week 5

End week 13 or 15

Courseworks

  • Demonstration week 13 (8 weeks from now)
    • 50% mark
  • Critical essay week 15 (?) (10 weeks from now)
    • 50% mark

Coursework 1: create a website

  • Build a WordPress website
  • Create custom theme (child or full), logo provided
  • Create custom plugin (with database and form processing)
  • Assessment on speed, overall design, accessibility, security...

Coursework 2: critical essay

  • 2000 words
  • Compare 6 CMSs
    • Security
    • Speed
    • SEO
    • Ease of use
    • Costs (initial and maintenance)
    • ...

Tips

  • Manage your time
    • Other modules courseworks
    • Don't spend to much on building the site
  • Second coursework is academic
    • Keep sentences simple (not to long, split in paragraphs)
    • Structure is as important as content

Questions?

Extending WordPress

Plugins

Definition

From codex.wordpress.org

Plugins are ways to extend and add to the functionality that already exists in WordPress.

The core of WordPress is designed to be lean and lightweight, to maximize flexibility and minimize code bloat. Plugins then offer custom functions and features so that each user can tailor their site to their specific needs.

Use existing plugins

  • Through the administration interface
    • From the repository
    • From an archive (zip or tar)
    • Create / move files for you! (no tracking)
  • In the wp-content/plugins
    • Add files (and version in your repository)
    • Add as git submodules

Plugin content

  • PHP
  • CSS
  • Javascript
  • Images

Naming

You have to choose a unique name for your plugin to avoid problems with other plugins you may need to use.

Use a consistent naming convention for your organisation, with a descriptive part.

Example: napier-newsletter {organisation}-{feature}

Single file plugin

Plugins can be contained in a single file {plugin-name}.php

Do not use extensively as maintenance is almost impossible, prefer creating more files as requirements can change and your code can get more complicated.

Example: Smashing Magazine: how to create a WordPress plugin

Split your plugin

You can create a plugin with multiple files. The directory name and the main plugin file should be called the same for it to work.

Example:

/wp-content/plugins/napier-newsletter/napier-newsletter.php

Plugin infos


<?php
   /*
   Plugin Name: Awesomeness Creator
   Plugin URI: http://my-awesomeness-emporium.com
   Description: a plugin to create awesomeness and spread joy
   Version: 1.2
   Author: Mr. Awesome
   Author URI: http://mrtotallyawesome.com
   License: GPL2
   */
?>
						

Only the name is required. This has to be in the main file.

Hooks

A plugin hook is a function you can use to register a specific function to be executed at a specific time in the dispatch loop.


add_action(
	'hook_name',
	'your_function_name',
	[priority],
	[accepted_args]
);
						
add_action ( 'publish_post', 'email_friends' );

Template tags

A template tag is PHP function used to generate and display information dynamically. This function is defined in the global namespace and can therefore be used in any template file (because of the dispatch loop, plugins are loaded before executing templates).

Example:

function bloginfo('test');

Because the function name is already in use in WordPress, this can be use to override its behaviour.

Best practice

Never use

wp-content/plugins/

use

plugin_dir_path

or

plugins_url

Best practice

Never hardcode the table prefix

wp_

use

$wpdb->prefix

Best practice

Use

wp_enqueue_script()

and

wp_enqueue_style()

to load scripts and css

Questions?

Extending plugins

Shortcode

Definition

A shortcode is a small code surrounded by squared brackets that the end user can use when editing content on WordPress, in order to use advanced features or styles.

Example

https://generatewp.com/shortcodes/?clone=video-embed-shortcode

Questions?

Extending plugins

Widget

Definition

WordPress Widgets add additional content and features to your WordPress site’s sidebars. Examples are the default widgets that come with WordPress — like those for archives, post categories, search bars and custom menus.

From ithemes - using WordPress widgets

Customise an existing widget

WordPress documentation: Create your own widget

Add a widget to your plugin

WP Beginner: How to create a custom WordPress widget

Questions?

Next week

Create a plugin

You need to create a form where visitors can enter their email address.

Once the address has been validated, store it into your database.

If the address does not validate, display the form again with the email provided in the email field and an error message.

Please version or backup your code, we will reuse this example for the security practical.

Bonus

Create an administration interface to display the list of addresses.

Create the form as a shortcode embeddable in any post.

Questions?

Thanks for coming

  • Feedback welcome
  • Questions welcome
  • See you on Tuesday
Fork me on GitHub