diff --git a/README.md b/README.md
index 5142195..e821d6f 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,9 @@
# printable-gallery
WordPress plugin that creates a table of images where users can select individual images to be printed.
+## v0.3
+Implemented some rudimentary object oriented design.
+
## v0.2
Setting things up for object oriented conversion.
+
diff --git a/includes/class-pg-functions.php b/includes/class-pg-functions.php
deleted file mode 100644
index e69de29..0000000
diff --git a/includes/class-pg-settings.php b/includes/class-pg-settings.php
deleted file mode 100644
index e69de29..0000000
diff --git a/includes/class-pg-table.php b/includes/class-pg-table.php
new file mode 100644
index 0000000..7c361a1
--- /dev/null
+++ b/includes/class-pg-table.php
@@ -0,0 +1,94 @@
+get_row( "SELECT * FROM wp_posts WHERE post_title = '" . $title_str . "'", 'ARRAY_A');
+ }
+
+ /**
+ * Generates a table according to user specs and inserts it into a new post.
+ *
+ * @since 0.1
+ * @return void
+ */
+ static function pg_generateTable( ) {
+ if(PG_TABLE::pg_exist_post_by_title('Table Page' ) == NULL ){
+ //Creating the $post array
+ $post = array(
+ 'post_title' => 'Table Page',
+ 'post_content'=> "
+ " .
+ PG_TABLE::pg_table_body()
+ . "
+
"
+ ); wp_insert_post( $post );
+ }
+ }
+
+ /**
+ * Generates the body of the table.
+ *
+ * @since 0.1
+ * @param TODO Set default values for no option recall
+ * @return string $tableBody the body of the table
+ */
+ static function pg_table_body() {
+ if(get_option('pg_rows_number') == NULL){
+ $rows= 4;
+ }
+ else {
+ $rows= get_option('pg_rows_number');
+ }
+
+ for( $i = 0; $i < $rows; $i++ ){
+ $tableRows[$i]= "" .
+ PG_TABLE::pg_table_data()
+ . "
";
+ }
+ $tableBody = implode( $tableRows );
+ return $tableBody;
+ }
+
+ /**
+ * Generates the columns of the table and insets their data.
+ *
+ * @since 0.1
+ * @param TODO Set default values for no option recall
+ * @return string $data the data of each cell
+ */
+ static function pg_table_data(){
+ if(get_option('pg_columns_number') == NULL){
+ $columns = 4;
+ }
+ else {
+ $columns = get_option('pg_columns_number');
+ }
+
+ for( $i = 0; $i < $columns; $i++ ){
+ $tableColumns[$i]= "
+ Picture will go here
+ | ";
+ }
+ $data = implode( $tableColumns );
+ return $data;
+ }
+
+}
diff --git a/includes/settings.php b/includes/settings.php
new file mode 100644
index 0000000..649fbea
--- /dev/null
+++ b/includes/settings.php
@@ -0,0 +1,101 @@
+Set up your Printable Gallery';
+}
+
+/**
+ * Generates the rows field
+ *
+ * If there is no option value, the it displays "4" as the default value
+ *
+ * @since 0.1
+ */
+function pg_settings_rows_num_callback(){
+ if(get_option('pg_rows_number') == NULL){
+ echo '';
+ }
+ else {
+ echo '';
+ }
+}
+
+/**
+ * Generates the columns field
+ *
+ * If there is no option value, the it displays "4" as the default value
+ *
+ * @since 0.1
+ */
+function pg_settings_columns_num_callback(){
+ if(get_option('pg_columns_number') == NULL){
+ echo '';
+ }
+ else {
+ echo '';
+ }
+}
+
+/**
+ * Generates the gallery name field
+ *
+ * If there is no option value, the it displays "Gallery Name" as the default value
+ *
+ * @since 0.1
+ */
+function pg_settings_gallery_name_callback(){
+ if(get_option('pg_gallery_name') == NULL){
+ echo '';
+ }
+ else {
+ echo '';
+ }
+}
diff --git a/printable-gallery.php b/printable-gallery.php
index 42b47cb..cea6557 100644
--- a/printable-gallery.php
+++ b/printable-gallery.php
@@ -3,185 +3,68 @@
Plugin Name: Printable Gallery
Plugin URI: TODO
Description: Generates a table of images where users can select individual images to be printed .
-Version: 0.2
+Version: 0.3
Author: Shane W. Coll
Author URI: http://shanecoll.com
-*/
+ */
//TODO IMPLEMENT OBJECT ORIENTATION
-/**
- * Generates a table according to user specs and inserts it into a new post.
- *
- * @since 0.1
- * @return void
- */
-function pg_generateTable( ) {
- if(pg_exist_post_by_title('Table Page' ) == NULL ){
- //Creating the $post array
- $post = array(
- 'post_title' => 'Table Page',
- 'post_content'=> "
- " .
- pg_table_body()
- . "
-
"
- ); wp_insert_post( $post );
- }
-}
-/**
- * Check whether or not the table page already exists.
- *
- * If the table page does not exist, it creates a new one.
- *
- * @since 0.1
- * @param string $title_str the title of the page being checked
- * @return void
- */
-function pg_exist_post_by_title( $title_str ) {
- global $wpdb;
- return $wpdb->get_row( "SELECT * FROM wp_posts WHERE post_title = '" . $title_str . "'", 'ARRAY_A');
-}
+//Exit if accessed directly
+if ( !defined( 'ABSPATH' ) ) exit;
-/**
- * Generates the body of the table.
- *
- * @since 0.1
- * @param TODO Set default values for no option recall
- * @return string $tableBody the body of the table
- */
-function pg_table_body() {
- if(get_option('pg_rows_number') == NULL){
- $rows= 4;
- }
- else {
- $rows= get_option('pg_rows_number');
- }
+if( ! class_exists( 'Printable_Gallery' ) ) :
- for( $i = 0; $i < $rows; $i++ ){
- $tableRows[$i]= "" .
- pg_table_data()
- . "
";
- }
- $tableBody = implode( $tableRows );
- return $tableBody;
-}
+ require_once "includes/class-pg-table.php";
+require_once "includes/settings.php";
/**
- * Generates the columns of the table and insets their data.
+ * Main Printable_Gallery Class
*
- * @since 0.1
- * @param TODO Set default values for no option recall
- * @return string $data the data of each cell
+ * @since 0.2
*/
-function pg_table_data(){
- if(get_option('pg_columns_number') == NULL){
- $columns = 4;
+
+class Printable_Gallery {
+
+ private static $instance;
+
+ static function instance() {
+ if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Printable_Gallery ) ) {
+
+ self::$instance = new Printable_Gallery;
+
+ add_action('admin_init', 'pg_settings_api');
+
+ self::$instance->table = new PG_TABLE();
+ }
+ return self::$instance;
}
- else {
- $columns = get_option('pg_columns_number');
+
+ private function setup_constants() {
+ //Plugin folder path
+ if ( ! defined( 'PG_PLUGIN_DIR' ) ) {
+ define( 'PG_PLUGIN_DIR', plugin_dir_path(__FILE__ ) );
+ }
+
+
+
}
- for( $i = 0; $i < $columns; $i++ ){
- $tableColumns[$i]= "
- Picture will go here
- | ";
- }
- $data = implode( $tableColumns );
- return $data;
-}
+ private function includes() {
-/**
- * Generates the settings page and handles user input.
- *
- * @since 0.1
- */
-function pg_settings_api() {
-
-add_settings_section('pg_settings_section',
- 'Printable Gallery Settings',
- 'pg_settings_section_callback_function',
- 'media');
-
-add_settings_field('pg_gallery_name',
- 'Gallery Name:',
- 'pg_settings_gallery_name_callback',
- 'media',
- 'pg_settings_section');
-
-add_settings_field('pg_rows_number',
- 'Rows of images:',
- 'pg_settings_rows_num_callback',
- 'media',
- 'pg_settings_section');
-
-add_settings_field('pg_columns_number',
- 'Columns of images:',
- 'pg_settings_columns_num_callback',
- 'media',
- 'pg_settings_section');
-
-register_setting('media', 'pg_columns_number');
-register_setting('media', 'pg_gallery_name');
-register_setting('media', 'pg_rows_number');
-pg_generateTable();
-}
+ require_once PG_PLUGIN_DIR . "includes/class-pg-table.php";
-add_action('admin_init', 'pg_settings_api');
+ require_once PG_PLUGIN_DIR . "includes/settings.php";
-/**
- * Prints message in the Gallery settings section
- *
- * @since 0.1
- */
-function pg_settings_section_callback_function(){
- echo 'Set up your Printable Gallery
';
-}
-/**
- * Generates the rows field
- *
- * If there is no option value, the it displays "4" as the default value
- *
- * @since 0.1
- */
-function pg_settings_rows_num_callback(){
- if(get_option('pg_rows_number') == NULL){
- echo '';
- }
- else {
- echo '';
- }
-}
-/**
- * Generates the columns field
- *
- * If there is no option value, the it displays "4" as the default value
- *
- * @since 0.1
- */
-function pg_settings_columns_num_callback(){
- if(get_option('pg_columns_number') == NULL){
- echo '';
}
- else {
- echo '';
- }
}
-/**
- * Generates the gallery name field
- *
- * If there is no option value, the it displays "Gallery Name" as the default value
- *
- * @since 0.1
- */
-function pg_settings_gallery_name_callback(){
- if(get_option('pg_gallery_name') == NULL){
- echo '';
- }
- else {
- echo '';
- }
+endif;
+
+function PG() {
+ Printable_Gallery::instance();
}
+
+PG();