|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
namespace lsx_health_plan\classes; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Contains the related articles functions post type |
|
6
|
|
|
* |
|
7
|
|
|
* @package lsx-health-plan |
|
8
|
|
|
*/ |
|
9
|
|
|
class Articles { |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Holds class instance |
|
13
|
|
|
* |
|
14
|
|
|
* @var object \lsx_health_plan\classes\Articles() |
|
15
|
|
|
*/ |
|
16
|
|
|
protected static $instance = null; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* An array of the post types for the Global Defaults field. |
|
20
|
|
|
* |
|
21
|
|
|
* @var array |
|
22
|
|
|
*/ |
|
23
|
|
|
//public $default_types = array( 'exercise', 'recipe', 'meal', 'workout', 'plan' ); |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Constructor. |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct() { |
|
|
|
|
|
|
29
|
|
|
$this->default_types = array( |
|
|
|
|
|
|
30
|
|
|
\lsx_health_plan\functions\get_option( 'endpoint_meal', 'meal' ), |
|
31
|
|
|
\lsx_health_plan\functions\get_option( 'endpoint_exercise_single', 'exercise' ), |
|
32
|
|
|
\lsx_health_plan\functions\get_option( 'endpoint_recipe_single', 'recipe' ), |
|
33
|
|
|
\lsx_health_plan\functions\get_option( 'endpoint_workout', 'workout' ), |
|
34
|
|
|
\lsx_health_plan\functions\get_option( 'endpoint_plan', 'plan' ), |
|
35
|
|
|
); |
|
36
|
|
|
add_action( 'cmb2_admin_init', array( $this, 'related_articles_metabox' ) ); |
|
37
|
|
|
} |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Return an instance of this class. |
|
41
|
|
|
* |
|
42
|
|
|
* @since 1.0.0 |
|
43
|
|
|
* |
|
44
|
|
|
* @return object \lsx_health_plan\classes\Articles() A single instance of this class. |
|
45
|
|
|
*/ |
|
46
|
|
|
public static function get_instance() { |
|
47
|
|
|
// If the single instance hasn't been set, set it now. |
|
48
|
|
|
if ( null === self::$instance ) { |
|
|
|
|
|
|
49
|
|
|
self::$instance = new self(); |
|
50
|
|
|
} |
|
|
|
|
|
|
51
|
|
|
return self::$instance; |
|
52
|
|
|
} |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Define the related articles member metabox and field configurations. |
|
56
|
|
|
*/ |
|
57
|
|
|
public function related_articles_metabox() { |
|
58
|
|
|
foreach ( $this->default_types as $type => $default_type ) { |
|
|
|
|
|
|
59
|
|
|
$cmb = new_cmb2_box( |
|
60
|
|
|
array( |
|
61
|
|
|
'id' => $default_type . '_related_articles_metabox', |
|
|
|
|
|
|
62
|
|
|
'title' => __( 'Related Articles', 'lsx-health-plan' ), |
|
63
|
|
|
'object_types' => array( $default_type ), // Post type. |
|
64
|
|
|
'context' => 'normal', |
|
65
|
|
|
'priority' => 'low', |
|
66
|
|
|
'show_names' => true, |
|
67
|
|
|
) |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
$cmb->add_field( |
|
71
|
|
|
array( |
|
72
|
|
|
'name' => __( 'Related Articles', 'lsx-health-plan' ), |
|
73
|
|
|
'desc' => __( 'Connect the related articles that applies to this ', 'lsx-health-plan' ) . $default_type, |
|
74
|
|
|
'id' => $default_type . '_connected_articles', |
|
75
|
|
|
'type' => 'post_search_ajax', |
|
76
|
|
|
'limit' => 3, |
|
77
|
|
|
'sortable' => true, |
|
78
|
|
|
'query_args' => array( |
|
79
|
|
|
'post_type' => array( 'post' ), |
|
80
|
|
|
'post_status' => array( 'publish' ), |
|
81
|
|
|
'posts_per_page' => 3, |
|
82
|
|
|
), |
|
83
|
|
|
) |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
} |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|