- Log in to the administration page of your WordPress installation.
- Click on Plugins in the left-hand navigation menu.
- Check whether the Chapter 2 - Private Item Text plugin is currently active and deactivate it if it is.
- Copy the entire contents of the ch2-private-item-text directory and rename the copy ch2-oo-private-item-text.
- Navigate to the newly renamed folder and rename the main PHP code file ch2-oo-private-item-text.php.
- Open the newly renamed plugin file in a code editor.
- Update the plugin header to change the name of the plugin to Chapter 2 - Object-Oriented - Private Item Text.
- Right after the plugin header, add the following text to declare a new class for our plugin and specify a constructor method for this class:
class CH2_OO_Private_Item_Text {
function __construct() {
}
}
$my_ch2_oo_private_item_text = new CH2_OO_Private_Item_Text();
- Move the calls to the add_shortcode and add_action functions to be placed inside of the class constructor.
- Modify the second argument of the add_shortcode and add_action functions as follows:
add_shortcode( 'private', array( $this,
'ch2pit_private_shortcode' ) );
add_action( 'wp_enqueue_scripts', array( $this,
'ch2pit_queue_stylesheet' ) );
- Move the complete ch2pit_private_shortcode and ch2pit_queue_stylesheet functions inside of the class body (after the constructor method and before the class closing bracket).
- Save and close the modified file.
- Log in to the administration page of your development WordPress installation.
- Click on Plugins in the left-hand navigation menu.
- Activate the new plugin.
- Visit your site to see that the private item content functionality is still in place and works as it did before.