Commits

ncrocfer committed 6050857

Retrieve active template from wp_options

Comments (0)

Files changed (9)

includes/bp-portfolio-ajax.php

  * Intercepts the ajax request and returns projects
  */
 function bp_portfolio_ajax_index_pagination() {    
-    bp_core_load_template( apply_filters( 'portfolio_directory_template', 'default/projects-loop' ) );
+    bp_core_load_template( apply_filters( 'portfolio_directory_template', BP_PORTFOLIO_TEMPLATE . '/projects-loop' ) );
 }
 add_action( 'wp_ajax_projects_filter', 'bp_portfolio_ajax_index_pagination' );
 

includes/bp-portfolio-cssjs.php

 	global $bp;
 
 	if ( ($bp->current_component == $bp->portfolio->slug) OR ($bp->current_component == $bp->activity->slug) ) {
-            wp_register_style( 'bp-portfolio-css', BP_PORTFOLIO_PLUGIN_URL . '/templates/default/css/general.css' );
+            wp_register_style( 'bp-portfolio-css', BP_PORTFOLIO_PLUGIN_URL . '/templates/' . BP_PORTFOLIO_TEMPLATE . '/css/general.css' );
             wp_enqueue_style( 'bp-portfolio-css' );
         }
 }

includes/bp-portfolio-functions.php

             if($attachment != 0)
                 $thumbnail = apply_filters( 'bp_portfolio_get_item_thumbnail', $attachment[0]);
             else
-                $thumbnail = apply_filters( 'bp_portfolio_get_item_thumbnail', BP_PORTFOLIO_PLUGIN_URL . '/templates/default/img/default.png');
+                $thumbnail = apply_filters( 'bp_portfolio_get_item_thumbnail', BP_PORTFOLIO_PLUGIN_URL . '/templates/' . BP_PORTFOLIO_TEMPLATE . '/img/default.png');
             
             
             /* Now record the new activity item */

includes/bp-portfolio-install.php

 <?php
 
 /**
- * Install the necessary tables
+ * Setup the default options in the wp_options table
  */
-function bp_portfolio_install_tables() {
-    global $wpdb;
-
-    $items_table_name = $wpdb->prefix . BP_PORTFOLIO_ITEMS_TABLE;
-
-    $sql = "CREATE TABLE IF NOT EXISTS $items_table_name (
-                id MEDIUMINT( 9 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
-                author_id MEDIUMINT( 9 ) NOT NULL,
-                title TEXT NOT NULL ,
-                description TEXT NOT NULL ,
-                url VARCHAR( 255 ) NOT NULL ,
-                created_at DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
-                updated_at DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
-                tags TEXT NOT NULL
-            );";
-
-    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
-    dbDelta($sql);
-
-    add_option("bp_portfolio_db_version", BP_PORTFOLIO_DB_VERSION);
+function bp_portfolio_default_options() {
+    
+    
+    // The default max size for the description of a project
+    add_option('bp_portfolio_desc_max_size', '720');
+    
+    // The default template
+    add_option('bp_portfolio_template', 'default');
+    
 }
 
 ?>

includes/bp-portfolio-loader.php

             define('BP_PORTFOLIO_SLUG', $this->id);
         
         if(!defined('BP_PORTFOLIO_DESC_MAX_SIZE'))
-            define('BP_PORTFOLIO_DESC_MAX_SIZE', 720);
+            define('BP_PORTFOLIO_DESC_MAX_SIZE', get_option('bp_portfolio_desc_max_size'));
+        
+        if(!defined('BP_PORTFOLIO_TEMPLATE'))
+            define('BP_PORTFOLIO_TEMPLATE', get_option('bp_portfolio_template'));
+        
         
         $global_tables = array(
             'table_items_name' => $bp->table_prefix . BP_PORTFOLIO_ITEMS_TABLE

includes/bp-portfolio-screens.php

 
 		do_action( 'bp_portfolio_directory_setup' );
 
-		bp_core_load_template( apply_filters( 'portfolio_directory_template', 'default/index' ) );
+		bp_core_load_template( apply_filters( 'portfolio_directory_template', BP_PORTFOLIO_TEMPLATE . '/index' ) );
 	}
 }
 add_action( 'bp_screens', 'bp_portfolio_directory_setup' );
 	do_action( 'bp_portfolio_personal_screen' );
 
 	// Displaying Content
-	bp_core_load_template( apply_filters( 'bp_portfolio_template_screen_one', 'default/personal' ) );
+	bp_core_load_template( apply_filters( 'bp_portfolio_template_screen_one', BP_PORTFOLIO_TEMPLATE . '/personal' ) );
 }
 
 
         // Check the nonce
         if(!wp_verify_nonce($_POST['_wpnonce'], 'project_form_nonce')) {
             bp_core_add_message( __( 'There was an error recording the project, please try again', 'bp-portfolio' ), 'error' );
-            bp_core_load_template( apply_filters( 'bp_portfolio_template_screen_add', 'default/personal' ) );
+            bp_core_load_template( apply_filters( 'bp_portfolio_template_screen_add', BP_PORTFOLIO_TEMPLATE . '/personal' ) );
         }
         
         if(empty($_POST['title-input']) OR empty($_POST['url-input']) OR empty($_POST['description'])) {
     do_action( 'bp_portfolio_add_screen' );
 
     // Displaying Content
-    bp_core_load_template( apply_filters( 'bp_portfolio_template_screen_one', 'default/add' ) );
+    bp_core_load_template( apply_filters( 'bp_portfolio_template_screen_one', BP_PORTFOLIO_TEMPLATE . '/add' ) );
 
 }
 
             $project->get(array('id' => $project_id));
             if($project->query->post->post_author != bp_loggedin_user_id()) {
                 bp_core_add_message( __( 'There was an error recording the project, please try again', 'bp-portfolio' ), 'error' );
-                bp_core_load_template( apply_filters( 'bp_portfolio_template_screen_add', 'default/personal' ) );
+                bp_core_load_template( apply_filters( 'bp_portfolio_template_screen_add', BP_PORTFOLIO_TEMPLATE . '/personal' ) );
             }
             
             // Check the nonce
             if(!wp_verify_nonce($_POST['_wpnonce'], 'project_form_nonce')) {
                 bp_core_add_message( __( 'There was an error recording the project, please try again', 'bp-portfolio' ), 'error' );
-                bp_core_load_template( apply_filters( 'bp_portfolio_template_screen_add', 'default/personal' ) );
+                bp_core_load_template( apply_filters( 'bp_portfolio_template_screen_add', BP_PORTFOLIO_TEMPLATE . '/personal' ) );
             }
             
             if(empty($_POST['title-input']) OR empty($_POST['url-input']) OR empty($_POST['description'])) {
                 $project->get(array('id' => $project_id));
                 
                 if($project->query->post->post_author == bp_loggedin_user_id()) {
-                    bp_core_load_template( apply_filters( 'bp_portfolio_template_screen_one', 'default/add' ) );
+                    bp_core_load_template( apply_filters( 'bp_portfolio_template_screen_one', BP_PORTFOLIO_TEMPLATE . '/add' ) );
                 }
                     
             }

includes/bp-portfolio-template.php

             if($thumbnail != 0)
                 return apply_filters( 'bp_portfolio_get_item_thumbnail', $thumbnail[0]);
             else
-                return apply_filters( 'bp_portfolio_get_item_thumbnail', BP_PORTFOLIO_PLUGIN_URL . '/templates/default/img/default.png');
+                return apply_filters( 'bp_portfolio_get_item_thumbnail', BP_PORTFOLIO_PLUGIN_URL . '/templates/' . BP_PORTFOLIO_TEMPLATE . '/img/default.png');
         }
 
 
 define( 'BP_PORTFOLIO_VERSION',             '1.0' );
 define( 'BP_PORTFOLIO_PLUGIN_DIR',          dirname( __FILE__ ) );
 define( 'BP_PORTFOLIO_PLUGIN_URL',          plugins_url() . '/bp-portfolio');
-define( 'BP_PORTFOLIO_DB_VERSION',          '1' );
-define( 'BP_PORTFOLIO_ITEMS_TABLE',         'bp_portfolio_items' );
 
 
 /* Only load the portfolio component if BuddyPress is loaded and initialized. */
 /* Install the tables on activation */
 function bp_portfolio_activate() {
     require( dirname( __FILE__ ) . '/includes/bp-portfolio-install.php' );
-    //bp_portfolio_install_tables();
+    bp_portfolio_default_options();
 }
 register_activation_hook( __FILE__, 'bp_portfolio_activate' );
 

templates/default/index.php

                     
                     <div id="projects-dir-list" class="projects dir-list">
 
-                        <?php load_sub_template( array( 'default/projects-loop.php' ) ); ?>
+                        <?php load_sub_template( array( BP_PORTFOLIO_TEMPLATE . '/projects-loop.php' ) ); ?>
                         
                     </div>