-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathqubely.php
236 lines (205 loc) · 6.8 KB
/
qubely.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
/*
* Plugin Name: Qubely - Advanced Gutenberg Blocks
* Plugin URI: https://www.themeum.com/
* Description: The one and only Gutenberg block plugin you will ever need.
* Version: 1.8.12
* Author: Themeum
* Author URI: https://www.themeum.com/
* Text Domain: qubely
* Requires at least: 5.3
* Tested up to: 6.6.2
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
// Language Load
add_action('init', 'qubely_language_load');
function qubely_language_load()
{
load_plugin_textdomain('qubely', false, basename(dirname(__FILE__)) . '/languages/');
}
// Define Version
define('QUBELY_VERSION', '1.8.12');
// Define License
define('QUBELY_LICENSE', 'free');
// Define Dir URL
define('QUBELY_DIR_URL', plugin_dir_url(__FILE__));
// Define Physical Path
define('QUBELY_DIR_PATH', plugin_dir_path(__FILE__));
// Include Require File
require_once QUBELY_DIR_PATH . 'core/initial-setup.php'; // Initial Setup Data
/**
* Add qubely admin options page
*/
require_once QUBELY_DIR_PATH . 'core/Options.php'; // Loading QUBELY Blocks Main Files
// Page Template Added
require_once QUBELY_DIR_PATH . 'core/Template.php';
if (class_exists('QUBELY_Options')) {
new QUBELY_Options();
}
// Version Check & Include Core
if (!version_compare(PHP_VERSION, '5.4', '>=')) {
add_action('admin_notices', ['QUBELY_Initial_Setup', 'php_error_notice']); // PHP Version Check
} elseif (!version_compare(get_bloginfo('version'), '4.7', '>=')) {
add_action('admin_notices', ['QUBELY_Initial_Setup', 'wordpress_error_notice']); // WordPress Version Check
} else {
require_once QUBELY_DIR_PATH . 'core/QUBELY.php'; // Loading QUBELY Blocks Main Files
}
function qubely_blocks_add_orderby($params)
{
$params['orderby']['enum'][] = 'rand';
$params['orderby']['enum'][] = 'menu_order';
return $params;
}
/**
* Create API fields for additional info
*
* @since 1.0.9
*/
function qubely_register_rest_fields()
{
$post_types = QUBELY_MAIN::get_post_types();
foreach ($post_types as $key => $value) {
// Featured image.
register_rest_field(
$value['value'],
'qubely_featured_image_url',
[
'get_callback' => 'qubely_get_featured_image_url',
'update_callback' => null,
'schema' => [
'description' => __('Different sized featured images'),
'type' => 'array',
],
]
);
// Author info.
register_rest_field(
$value['value'],
'qubely_author',
[
'get_callback' => 'qubely_get_author_info',
'update_callback' => null,
'schema' => null,
]
);
// Add comment info.
register_rest_field(
$value['value'],
'qubely_comment',
[
'get_callback' => 'qubely_get_comment_info',
'update_callback' => null,
'schema' => null,
]
);
// Category links.
register_rest_field(
$value['value'],
'qubely_category',
[
'get_callback' => 'qubely_get_category_list',
'update_callback' => null,
'schema' => [
'description' => __('Category list links'),
'type' => 'string',
],
]
);
// Excerpt.
register_rest_field(
$value['value'],
'qubely_excerpt',
[
'get_callback' => 'qubely_get_excerpt',
'update_callback' => null,
'schema' => null,
]
);
}
}
// Author.
function qubely_get_author_info($object)
{
$author = (isset($object['author'])) ? $object['author'] : '';
$author_data['display_name'] = get_the_author_meta('display_name', $author);
$author_data['author_link'] = get_author_posts_url($author);
return $author_data;
}
// Comment.
function qubely_get_comment_info($object)
{
$comments_count = wp_count_comments($object['id']);
return $comments_count->total_comments;
}
// Category list.
if (!function_exists('qubely_get_category_list')) {
function qubely_get_category_list($object)
{
$taxonomies = get_post_taxonomies($object['id']);
if ('post' === get_post_type()) {
return get_the_category_list(esc_html__(' '), '', $object['id']);
} else {
if (!empty($taxonomies)) {
return get_the_term_list($object['id'], $taxonomies[0], ' ');
}
}
}
}
// Feature image.
function qubely_get_featured_image_url($object)
{
$featured_images = [];
if (!isset($object['featured_media'])) {
return $featured_images;
} else {
$image = wp_get_attachment_image_src($object['featured_media'], 'full', false);
if (is_array($image)) {
$featured_images['full'] = $image;
$featured_images['landscape'] = wp_get_attachment_image_src($object['featured_media'], 'qubely_landscape', false);
$featured_images['portraits'] = wp_get_attachment_image_src($object['featured_media'], 'qubely_portrait', false);
$featured_images['thumbnail'] = wp_get_attachment_image_src($object['featured_media'], 'qubely_thumbnail', false);
$image_sizes = QUBELY_MAIN::get_all_image_sizes();
foreach ($image_sizes as $key => $value) {
$size = $value['value'];
$featured_images[$size] = wp_get_attachment_image_src(
$object['featured_media'],
$size,
false
);
}
return $featured_images;
}
}
}
// Excerpt.
function qubely_get_excerpt($object)
{
$excerpt = wp_trim_words(get_the_excerpt($object['id']));
if (!$excerpt) {
$excerpt = null;
}
return $excerpt;
}
add_action('rest_api_init', 'qubely_register_rest_fields');
/**
* Order by
*/
function qubely_resigter_rest_order_by_fields()
{
$post_types = QUBELY_MAIN::get_post_types();
foreach ($post_types as $key => $type) {
add_filter("rest_{$type['value']}_collection_params", 'qubely_blocks_add_orderby', 10, 1);
}
}
add_action('init', 'qubely_resigter_rest_order_by_fields');
function qubely_blog_posts_image_sizes()
{
add_image_size('qubely_landscape', 1200, 750, true);
add_image_size('qubely_portrait', 540, 320, true);
add_image_size('qubely_thumbnail', 140, 100, true);
}
add_action('after_setup_theme', 'qubely_blog_posts_image_sizes');