Theater for WordPress Code Reference
  • Package
  • Class

Packages

  • Theater
    • Abstracts
    • Events

Classes

  • Theater
  • Theater_Event
  • Theater_Event_Date
  • Theater_Event_Date_Link
  • Theater_Event_Date_List
  • Theater_Event_Field
  • Theater_Event_List
  • Theater_Item
  • Theater_List

Functions

  • Theater
  1 <?php
  2 /*
  3     Plugin Name: Theater
  4     Plugin URI: https://wp.theater
  5     Description: Turn your Wordpress website into a theater website.
  6     Author: Jeroen Schmit
  7     Version: 0.16
  8     Author URI: http://slimndap.com/
  9     Text Domain: theatre
 10     Domain Path: /lang
 11 
 12     This program is free software; you can redistribute it and/or modify
 13     it under the terms of the GNU General Public License as published by
 14     the Free Software Foundation; either version 2 of the License, or
 15     (at your option) any later version.
 16 
 17     This program is distributed in the hope that it will be useful,
 18     but WITHOUT ANY WARRANTY; without even the implied warranty of
 19     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 20     GNU General Public License for more details.
 21 
 22     You should have received a copy of the GNU General Public License along
 23     with this program; if not, write to the Free Software Foundation, Inc.,
 24     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 25 
 26 */
 27 
 28 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
 29 
 30 $wpt_version = '0.16';
 31 
 32 
 33 /**
 34  * Main Theater for WordPress class.
 35  *
 36  * With the Theater for WordPress plugin it is possible to manage and publish _events_ that have one of more _dates_.
 37  *
 38  * So if you run a theater then 'The Sound Of Music' is an event and the show this weekend is a date.
 39  *
 40  * ## Getting started
 41  *
 42  * ### Events
 43  * <code>
 44  * // Retrieve a list of all events.
 45  * $events = new Theater_Event_List;
 46  * foreach ( $events() as $event ) {
 47  *      // $event is a Theater_Event object.     
 48  *      echo $event->title();
 49  * }
 50  * </code>
 51  *
 52  * <code>
 53  * // Output a formatted list of all events.
 54  * $events = new Theater_Event_List;
 55  * echo $events;
 56  * </code>
 57  *
 58  * See [Theater_Event_List()](class-Theater_Event_List.html) for more examples.
 59  *
 60  * ### Event dates
 61  * <code>
 62  * // Retrieve a list of all event dates.
 63  * $dates = new Theater_Event_Date_List;
 64  * foreach ( $dates() as $date ) {
 65  *      // $date is a Theater_Event_Date object.     
 66  *      echo $date->title();
 67  * }
 68  * </code>
 69  *
 70  * <code>
 71  * // Output a formatted list of all dates.
 72  * $dates = new Theater_Event_Date_List;
 73  * echo $dates;
 74  * </code>
 75  *
 76  * See [Theater_Event_Date_List()](class-Theater_Event_Date_List.html) for more examples.
 77  *
 78  * ## Extending Theater for WordPress
 79  * You can safely add extra functionality by using the `theater/loaded` action hook:
 80  * <code>
 81  * function theater_example_loader() {
 82  *      // Add your custom code below...
 83  * }
 84  * add_action( 'theater/loaded', 'theater_example_loader' );
 85  * </code>
 86  * See this [Example Extension](https://github.com/slimndap/wp-theatre-example-extension) for a full example.
 87  *
 88  * @package     Theater
 89  * @version     0.16
 90  * @author      Jeroen Schmit <jeroen@slimndap.com>
 91  * @copyright   2016 [Slim & Dapper](http://slimndap.com)
 92  * @license     https://opensource.org/licenses/GPL-3.0 GNU General Public License
 93  *
 94  */
 95 class Theater {
 96 
 97     /**
 98      * The single instance of the class.
 99      *
100      * @var Theater for WordPress
101      * @since 0.16
102      * @internal
103      */
104     protected static $_instance = null;
105 
106     function __construct() {
107         
108     }
109 
110     /**
111      * Returns the main Theater for WordPress Instance.
112      *
113      * Ensures only one instance of Theater for WordPress is loaded or can be loaded.
114      *
115      * @since 0.16
116      * @static
117      * @internal
118      * @return  Theater Main Theater instance.
119      */
120     static function instance() {
121         if ( is_null( self::$_instance ) ) {
122             self::$_instance = new self();
123         }
124         return self::$_instance;        
125     }
126 
127     /**
128      * init function.
129      * 
130      * @since   0.16
131      * @return  void
132      * @internal
133      */
134     function init() {
135         // Set version
136         global $wpt_version;
137         $this->wpt_version = $wpt_version;
138 
139         $this->define_constants();
140 
141         // Includes
142         $this->includes();
143 
144         // Setup
145         Theater_Setup::init();
146 
147         $this->admin = new WPT_Admin();
148         Theater_Admin_Plugins::init();
149         
150         $this->order = new WPT_Order();
151         $this->status = new WPT_Status();
152         $this->feeds = new WPT_Feeds();
153         $this->transient = new WPT_Transient();
154         $this->listing_page = new WPT_Listing_Page();
155         $this->calendar = new WPT_Calendar();
156         $this->context = new WPT_Context();
157         $this->filter = new WPT_Filter();
158 
159         $this->event_admin = new WPT_Event_Admin();
160         $this->event_editor = new WPT_Event_Editor();
161 
162         $this->production_permalink = new WPT_Production_Permalink();
163         Theater_Event_Date_Link::init();
164 
165         Theater_Widgets::init();
166 
167         $this->productions_admin = new WPT_Productions_Admin();
168 
169         $this->cart = new WPT_Cart();
170         $this->tags = new WPT_Tags();
171         $this->extensions_updater= new WPT_Extensions_Updater();
172         $this->extensions_promo= new WPT_Extensions_Promo();
173         if (is_admin()) {
174         } else {
175             $this->frontend = new WPT_Frontend();
176         }
177         
178         $this->deprecated_properties();
179 
180         // Options
181         $this->wpt_language_options = get_option( 'wpt_language' );
182         $this->wpt_Listing_page_options = get_option( 'wpt_Listing_page' );
183         $this->wpt_style_options = get_option( 'wpt_style' );
184         $this->wpt_tickets_options = get_option( 'wpt_tickets' );
185         $this->deprecated_options();
186 
187         // Plugin (de)activation hooks
188         register_activation_hook( __FILE__, array($this, 'activate' ));
189         register_deactivation_hook( __FILE__, array($this, 'deactivate' ));
190 
191         // Plugin update hooks
192         if ($wpt_version!=get_option('wpt_version')) {
193             update_option('wpt_version', $wpt_version);
194             add_action('admin_init',array($this,'update'));
195         }
196 
197         // Hook wpt_loaded action.
198         add_action ('plugins_loaded', array($this,'do_theater_loaded_action') );
199         
200     }
201 
202     /**
203      * define_constants function.
204      * 
205      * @access protected
206      * @return void
207      * @internal
208      */
209     protected function define_constants() {
210         if ( ! defined( 'THEATER_PLUGIN_BASENAME' ) ) {
211             define( 'THEATER_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );       
212         }
213         if ( ! defined( 'THEATER_VERSION' ) ) {
214             define( 'THEATER_VERSION', $this->wpt_version );    
215         }
216     }
217 
218     /**
219      * Include required core files used in admin and on the frontend.
220      *
221      * @access public
222      * @return void
223      * @internal
224      */
225     function includes() {
226         require_once(dirname(__FILE__) . '/functions/abstract/class-theater-item.php');
227         require_once(dirname(__FILE__) . '/functions/abstract/class-theater-list.php');
228 
229         require_once(dirname(__FILE__) . '/functions/template/wpt_template.php');
230         require_once(dirname(__FILE__) . '/functions/template/wpt_template_placeholder.php');
231         require_once(dirname(__FILE__) . '/functions/template/wpt_template_placeholder_filter.php');
232 
233         require_once(dirname(__FILE__) . '/functions/event/class-theater-event.php');
234         require_once(dirname(__FILE__) . '/functions/event/class-theater-event-field.php');
235         require_once(dirname(__FILE__) . '/functions/event/class-theater-event-date.php');
236         require_once(dirname(__FILE__) . '/functions/event/class-theater-event-date-link.php');
237         require_once(dirname(__FILE__) . '/functions/event/class-theater-event-list.php');
238         require_once(dirname(__FILE__) . '/functions/event/class-theater-event-date-list.php');
239 
240 
241         require_once(dirname(__FILE__) . '/functions/wpt_production_permalink.php');
242         require_once(dirname(__FILE__) . '/functions/wpt_production_template.php');
243         require_once(dirname(__FILE__) . '/functions/wpt_production_widget.php');
244 
245         require_once(dirname(__FILE__) . '/functions/wpt_productions_admin.php');
246         require_once(dirname(__FILE__) . '/functions/wpt_productions_list_table.php');
247 
248         require_once(dirname(__FILE__) . '/functions/deprecated/class-wp-theatre.php');
249         require_once(dirname(__FILE__) . '/functions/deprecated/class-wpt-production.php');
250         require_once(dirname(__FILE__) . '/functions/deprecated/class-wpt-event.php');
251         require_once(dirname(__FILE__) . '/functions/wpt_event_admin.php');
252         require_once(dirname(__FILE__) . '/functions/wpt_event_editor.php');
253         require_once(dirname(__FILE__) . '/functions/wpt_event_template.php');
254 
255         require_once(dirname(__FILE__) . '/functions/wpt_events_widget.php');
256 
257         require_once(dirname(__FILE__) . '/functions/setup/class-theater-setup.php');
258         require_once(dirname(__FILE__) . '/functions/wpt_season.php');
259 
260         require_once(dirname(__FILE__) . '/functions/wpt_widget.php');
261         require_once(dirname(__FILE__) . '/functions/widgets/class-theater-widgets.php');
262 
263         require_once(dirname(__FILE__) . '/functions/wpt_admin.php');
264         require_once(dirname(__FILE__) . '/functions/admin/class-theater-admin-plugins.php');
265 
266         require_once(dirname(__FILE__) . '/functions/wpt_order.php');
267         require_once(dirname(__FILE__) . '/functions/wpt_status.php');
268         require_once(dirname(__FILE__) . '/functions/wpt_feeds.php');
269         require_once(dirname(__FILE__) . '/functions/wpt_transient.php');
270         require_once(dirname(__FILE__) . '/functions/wpt_listing_page.php');
271         require_once(dirname(__FILE__) . '/functions/wpt_calendar.php');
272         require_once(dirname(__FILE__) . '/functions/wpt_context.php');
273         require_once(dirname(__FILE__) . '/functions/wpt_filter.php');
274         require_once(dirname(__FILE__) . '/functions/wpt_cart.php');
275         require_once(dirname(__FILE__) . '/functions/wpt_tags.php');
276 
277         require_once(dirname(__FILE__) . '/functions/extensions/wpt_extensions_updater.php');
278         require_once(dirname(__FILE__) . '/functions/extensions/wpt_extensions_promo.php');
279 
280         require_once(dirname(__FILE__) . '/functions/wpt_importer.php');
281 
282 
283         if (is_admin()) {
284         } else {
285             require_once(dirname(__FILE__) . '/functions/wpt_frontend.php');
286         }
287         require_once(dirname(__FILE__) . '/integrations/wordpress-seo.php');
288         require_once(dirname(__FILE__) . '/integrations/jetpack-featured-content.php');
289 
290     }
291 
292     /**
293      * @deprecated  0.16
294      * @internal
295      */
296     public function seasons($PostClass = false) {
297         return $this->get_seasons($PostClass);
298     }
299 
300     /**
301      * activate function.
302      * 
303      * @access public
304      * @internal
305      * @return void
306      */
307     function activate() {
308         wp_schedule_event( time(), 'wpt_schedule', 'wpt_cron');
309 
310         //defines the post types so the rules can be flushed.
311         $this->setup->init();
312 
313         //and flush the rules.
314         flush_rewrite_rules();
315     }
316 
317     /**
318      * deactivate function.
319      * 
320      * @access public
321      * @return void
322      * @internal
323      */
324     function deactivate() {
325         wp_clear_scheduled_hook('wpt_cron');
326         delete_post_meta_by_key($this->order->meta_key);
327         flush_rewrite_rules();
328     }
329 
330     /**
331      * update function.
332      * 
333      * @access public
334      * @return void
335      * @internal
336      */
337     function update() {
338         $this->activate();
339     }
340 
341 
342 
343     /**
344      * Fires the `theater/loaded` action.
345      *
346      * Use this action to safely load plugins that depend on Theater for WordPress.
347      *
348      * @since   0.x
349      * @return  void
350      */
351     function do_theater_loaded_action() {
352         /**
353          * Fires after Theater for WordPress is fully loaded.
354          * @since   0.16
355          */
356         do_action('theater/loaded');
357         
358         /**
359          * @deprecated  0.16
360          */
361         do_action('wpt_loaded');
362     }
363 
364     /*
365      * Private functions.
366      */
367 
368     /**
369      * @internal
370      */
371     private function get_seasons($PostClass=false) {
372         $args = array(
373             'post_type'=>WPT_Season::post_type_name,
374             'posts_per_page' => -1,
375             'orderby' => 'title'
376         );
377 
378         $posts = get_posts($args);
379 
380         $seasons = array();
381         for ($i=0;$i<count($posts);$i++) {
382             $seasons[] = new WPT_Season($posts[$i], $PostClass);
383         }
384         return $seasons;
385     }
386 
387 
388     /**
389      * @deprecated 0.4
390      * @internal
391      */
392     function compile_events($args=array()) {
393         return $this->events->html($args);
394     }
395 
396     /**
397      * @deprecated 0.4
398      * @internal
399      */
400     private function get_events($PostClass = false) {
401         return $this->events();
402     }
403 
404     /**
405      * @deprecated 0.4
406      * @internal
407      */
408     function render_events($args=array()) {
409         echo $this->compile_events($args);
410     }
411 
412     /**
413      * @deprecated 0.4
414      * @internal
415      */
416     private function get_productions($PostClass = false) {
417         return $this->productions();
418     }
419 
420     /**
421      * @deprecated 0.4
422      * @internal
423      */
424     function render_productions($args=array()) {
425         return $this->productions->html_Listing();
426     }
427     
428     /*
429      * For backward compatibility purposes
430      * Use old theatre options for style options and tickets options.
431      * As of v0.8 style options and tickets options are stored seperately.
432      */
433     
434     /**
435      * @deprecated 0.8
436      * @internal
437      */
438     function deprecated_options() {
439         if (empty($this->wpt_style_options)) {
440             $this->wpt_style_options = get_option( 'theatre' );
441         }
442         if (empty($this->wpt_tickets_options)) {
443             $this->wpt_tickets_options = get_option( 'theatre' );
444         }
445     }
446     
447     /**
448      * @deprecated 0.8
449      * @internal
450      */
451     protected function deprecated_properties() {
452         $this->productions = new Theater_Event_List;    
453         $this->events = new Theater_Event_Date_List;    
454     }
455 }
456 
457 /**
458  * Main instance of Theater for WordPress.
459  *
460  * @since  0.16
461  * @package Theater
462  * @return  Theater The main instance of Theater for WordPress to prevent the need to use globals.
463  */
464 function Theater() {
465     return Theater::instance();
466 }
467 
468 Theater()->init();
469 ?>
470 
Theater for WordPress Code Reference API documentation generated by ApiGen