Build Your Own Business Website header image

Lesson 8 – Storing, Retrieving and Updating Thesis Options

Difficulty Level -

Filed Under Topics -

Listed Under Lesson Subjects -

Applies to -

Understanding the Problem – Watch the Video

  • Installing the child theme

    • manually enter all options
    • use code to override options
    • use code to set options
  • Uninstalling the child theme/switching themes

    • manually remove child theme options – restore original options
    • use code to reset options to original condition
  • Finding a WordPress event to trigger this

    • automatically update options upon theme activation
    • automatically restore original options upon theme deactivation
    • include a button in the theme that does this
    • create new custom hooks

Create a Custom WordPress Hook – Watch the Video

  • A hook is a place holder

  • A good reference source

  • do_action

    • syntax
    • tag
    • arguments
  • Write a custom hook

  • Attach a function to that hook

Create Theme Activation/Deactivation Hooks – Watch the Video

  • Why do_action won’t work

  • Krishna Kant Sharma’s PHP Library

    • Both functions are called every time the theme is loaded
    • Activate – If the activation option switch exists then nothing happens if it doesn’t then the activation function is fired
    • Deactivate – if the switch theme hook is called then the deactivation function happens and the option switch is deleted
  • Use the Library

    • Create the file
    • Include the file
    • Create an activation function
    • Create a deactivation function
    • Call the activate hook
    • Call the deactivate hook

Create Child Theme Default Options – Watch the Video

  • Thesis Import/Export theme options

    • Export Thesis design options
    • Restore default design options
    • Import Thesis design options
  • Thesis options DAT file

  • Add the DAT file to the child theme

    • Name
    • Location

Set Child Theme Default Options at Theme Activation – Watch the Video

  • WordPress Options API

    • option vs site_option
    • add, delete, get, update
  • Set default options

    • Create a new file
    • global $all_options
    • Check to make sure the file exists – PHP is_file()
    • Get the contents of the file – PHP file_get_contents()
    • PHP unserialize()
    • W3TC cache fix
    • update_option
  • Add the function to the activation hook

    • include the file
    • add the function call to the “hook” function

Play Nice – Restore Original Options at Theme Deactivation – Watch the Video

  • Store the original options at activation

    • get the existing options
    • create a new option
    • add the function to the activation “hook” function
  • Replace the options at deactivation

    • get the original options
    • update the options
    • delete the old options

Question and Answer Session – Watch the Video

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
THIS IS A LIMITED TIME OFFER!
Subscription Options
0 Comments… add one
0 comments… add one

Leave a Comment