-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass-wiki-wiki-utils.php
104 lines (86 loc) · 2.42 KB
/
class-wiki-wiki-utils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* Utility class to wrap generic functions
*
* @since 0.1.0
*/
class Wiki_Wiki_Utils {
/**
* Default initialization for the plugin:
* - Registers the default textdomain.
*/
public static function init() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'wiki_wiki' );
load_textdomain( 'wiki_wiki', WP_LANG_DIR . '/wiki_wiki/wiki_wiki-' . $locale . '.mo' );
load_plugin_textdomain( 'wiki_wiki', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
Wiki_Wiki_Post_Type::init(); // Load our CPT so the rewrite rules can be flushed on activation
}
/**
* Activate the plugin
*/
public static function activate() {
self::init();
flush_rewrite_rules();
}
/**
* Deactivate the plugin
* Uninstall routines should be in uninstall.php
*/
public static function deactivate() {
}
/**
* Add all front-end scripts and styles
*/
public static function load_resources() {
// Scripts
wp_enqueue_script( 'jquery' );
// Load only on Add Wiki page
// @todo Add in checks against wiki pages and load conditionally
wp_enqueue_script( 'wiki-wiki', WIKI_WIKI_URL . 'assets/js/add-wiki.min.js', array( 'wp-util' ), WIKI_WIKI_VERSION, true );
}
/**
* Add all admin scripts and styles
*/
public static function load_admin_resources() {
// Stylesheets
wp_enqueue_style( 'wiki-wiki-admin-styles', WIKI_WIKI_URL . 'assets/css/wiki_wiki.admin.min.css', array(), WIKI_WIKI_VERSION );
// Scripts
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'wiki-wiki-admin-scripts', WIKI_WIKI_URL . 'assets/js/wiki_wiki.admin.min.js', array( 'jquery' ), WIKI_WIKI_VERSION, true );
}
/**
* Return an array of post objects
*
* @return array|bool
*/
public static function get_wiki_pages() {
$args = array(
'post_type' => 'wiki_wiki',
);
$wikis = new WP_Query( $args );
return $wikis->posts;
}
/**
* Allows us to fetch wiki pages and return only certain values from the post object
*
* @param array $args The name of the post object keys we want to return.
*
* @return array|bool
*/
public static function get_wiki_pages_custom( $args = array() ) {
$wikis = self::get_wiki_pages();
if ( ! empty( $args ) ) {
$wiki = array();
$new_wikis = '';
foreach ( $wikis as $wiki_data ) {
foreach ( $args as $key ) {
$wiki[ $key ] = $wiki_data->{$key};
}
$new_wikis[] = (object) $wiki;
}
return $new_wikis;
} else {
return false;
}
}
}