PluginProbe
UpStream: a Project Management Plugin for WordPress / 2.1.0
UpStream: a Project Management Plugin for WordPress v2.1.0
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / includes / class-factory.php

class-factory.php in UpStream: a Project Management Plugin for WordPress 2.1.0, at includes/class-factory.php

84 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Abstract factory class.
4 *
5 * @package UpStream
6 */
7
8 namespace UpStream;
9
10 use Upstream_Counter;
11
12 // Prevent direct access.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Abstract factory class.
19 *
20 * @since 1.24.0
21 */
22 abstract class Factory {
23 /**
24 * Counters.
25 *
26 * @var array
27 */
28 protected static $counters = array();
29
30 /**
31 * Create milestone data.
32 *
33 * @param string $name Milestone name.
34 *
35 * @return Milestone
36 */
37 public static function create_milestone( $name ) {
38 $post_id = wp_insert_post(
39 array(
40 'post_type' => Milestone::POST_TYPE,
41 'post_title' => sanitize_text_field( $name ),
42 'post_status' => 'publish',
43 )
44 );
45
46 return self::get_milestone( $post_id );
47 }
48
49 /**
50 * Get milestone data.
51 *
52 * @param int|\WP_Post $post WP post data.
53 *
54 * @return Milestone
55 */
56 public static function get_milestone( $post ) {
57 return new Milestone( $post );
58 }
59
60 /**
61 * Get project activity.
62 *
63 * @return \UpStream_Project_Activity
64 */
65 public static function get_activity() {
66 return \UpStream_Project_Activity::getInstance();
67 }
68
69 /**
70 * Get project counter
71 *
72 * @param int|array $project_ids Project IDs.
73 *
74 * @return Upstream_Counter
75 */
76 public static function get_project_counter( $project_ids ) {
77 if ( ! isset( self::$counters[ $project_ids ] ) ) {
78 self::$counters[ $project_ids ] = new Upstream_Counter( $project_ids );
79 }
80
81 return self::$counters[ $project_ids ];
82 }
83 }
84