Repository navigation
Expand file tree
/
Copy pathfunctions.php
More file actions
278 lines (243 loc) · 10.6 KB
/
Copy pathfunctions.php
File metadata and controls
278 lines (243 loc) · 10.6 KB
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
/**
* CredibleBlog functions and definitions
*/
/**
* Theme Support & Menus
*/
if ( ! function_exists( 'credibleblog_setup' ) ) :
function credibleblog_setup() {
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'credibleblog' ),
'footer' => __( 'Footer Menu', 'credibleblog' ),
) );
add_theme_support( 'custom-logo', array(
'height' => 100,
'width' => 400,
'flex-width' => true,
'flex-height' => true,
) );
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
) );
}
endif;
add_action( 'after_setup_theme', 'credibleblog_setup' );
/**
* Register widget area.
*/
function credibleblog_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar Utama', 'credibleblog' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Tambahkan widget di sini.', 'credibleblog' ),
'before_widget' => '<section id="%1$s" class="widget card-glass %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Sidebar Iklan', 'credibleblog' ),
'id' => 'sidebar-ads',
'description' => esc_html__( 'Ruang untuk iklan vertical.', 'credibleblog' ),
'before_widget' => '<div id="%1$s" class="ads-clean-wrapper %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="screen-reader-text">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Sidebar Komentar (Kanan)', 'credibleblog' ),
'id' => 'sidebar-comments',
'description' => esc_html__( 'Widget area di kanan kolom komentar.', 'credibleblog' ),
'before_widget' => '<div id="%1$s" class="ads-clean-wrapper %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="screen-reader-text">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Sidebar Komentar (Kiri)', 'credibleblog' ),
'id' => 'sidebar-comments-left',
'description' => esc_html__( 'Widget area di kiri kolom komentar.', 'credibleblog' ),
'before_widget' => '<div id="%1$s" class="ads-clean-wrapper %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="screen-reader-text">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'credibleblog_widgets_init' );
/**
* Enqueue scripts and styles.
*/
/**
* 1. Balance Grid: Set posts_per_page to 6 (cycle size)
*/
function credibleblog_balance_grid( $query ) {
if ( $query->is_home() && $query->is_main_query() && ! is_admin() ) {
$query->set( 'posts_per_page', 6 );
}
}
add_action( 'pre_get_posts', 'credibleblog_balance_grid' );
/**
* 2. Load More Scripts & Localization
*/
/**
* 2. Load More Scripts & Localization (Merged with main scripts)
*/
function credibleblog_scripts() {
// Styles
wp_enqueue_style( 'credibleblog-fonts', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Outfit:wght@600;700;800&display=swap', array(), null );
wp_enqueue_style( 'credibleblog-style', get_stylesheet_uri(), array('credibleblog-fonts'), wp_get_theme()->get( 'Version' ) );
wp_enqueue_style( 'credibleblog-interactions', get_template_directory_uri() . '/assets/css/interactions.css', array('credibleblog-style'), '1.0.0' );
wp_enqueue_style( 'credibleblog-layouts', get_template_directory_uri() . '/assets/css/blog-layouts.css', array('credibleblog-style'), '1.0.0' );
wp_enqueue_style( 'credibleblog-share-style', get_template_directory_uri() . '/assets/css/share.css', array(), '1.1.0' );
wp_enqueue_style( 'credibleblog-components', get_template_directory_uri() . '/assets/css/frontend-components.css', array('credibleblog-style'), '1.0.0' );
// Swiper.js for Carousel (Only on Single Post)
if ( is_single() ) {
wp_enqueue_style( 'swiper', get_template_directory_uri() . '/assets/css/swiper-bundle.min.css', array(), '11.0.0' );
}
// Scripts & Localization
// Scripts & Localization
// 1. Theme Toggle (Core)
wp_enqueue_script( 'cb-theme-toggle', get_template_directory_uri() . '/assets/js/modules/theme-toggle.js', array(), '1.0.0', true );
// 2. Search
wp_enqueue_script( 'cb-search', get_template_directory_uri() . '/assets/js/modules/search.js', array(), '1.0.0', true );
// 3. Reading Progress & Sticky Header
wp_enqueue_script( 'cb-reading', get_template_directory_uri() . '/assets/js/modules/reading-progress.js', array(), '1.0.0', true );
// 4. Copy Link
wp_enqueue_script( 'cb-copy-link', get_template_directory_uri() . '/assets/js/modules/copy-link.js', array(), '1.0.0', true );
// 5. Load More
wp_enqueue_script( 'cb-load-more', get_template_directory_uri() . '/assets/js/modules/load-more.js', array(), '1.0.0', true );
// 6. Newsletter
wp_enqueue_script( 'cb-newsletter', get_template_directory_uri() . '/assets/js/modules/newsletter.js', array(), '1.0.0', true );
// 7. Card Interaction Activation (Share & More)
wp_enqueue_script( 'cb-card-actions', get_template_directory_uri() . '/assets/js/modules/card-actions.js', array(), '1.0.0', true );
// 8. Related Articles Carousel
if ( is_single() ) {
wp_enqueue_script( 'swiper-js', get_template_directory_uri() . '/assets/js/swiper-bundle.min.js', array(), '11.0.0', true );
wp_enqueue_script( 'cb-related-carousel', get_template_directory_uri() . '/assets/js/modules/related-carousel.js', array('swiper-js'), '1.0.0', true );
}
// 9. Mobile Drawers
if ( is_single() ) {
wp_enqueue_script( 'cb-mobile-drawers', get_template_directory_uri() . '/assets/js/modules/mobile-drawers.js', array(), '1.0.0', true );
}
// 8. Threaded Comments
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
// 9. 404 Page Styles
if ( is_404() ) {
wp_enqueue_style( 'credibleblog-404', get_template_directory_uri() . '/assets/css/404.css', array('credibleblog-style'), '1.0.0' );
}
// Localize data for AJAX (Attached to Load More, but available globally)
wp_localize_script( 'cb-load-more', 'credibleblog_ajax', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'load_more_nonce' ),
'max_pages' => $GLOBALS['wp_query']->max_num_pages ?? 1,
'current_lang' => cb_get_current_language(), // Pass PHP lang state to JS
));
}
add_action( 'wp_enqueue_scripts', 'credibleblog_scripts' );
/**
* 3. AJAX Load More Handler
*/
function credibleblog_load_more_posts() {
// Verify Nonce
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'load_more_nonce' ) ) {
wp_send_json_error( array( 'message' => __( 'Security check failed.', 'credibleblog' ) ) );
}
$paged = isset( $_POST['page'] ) ? intval( $_POST['page'] ) : 1;
$lang = isset( $_POST['lang'] ) ? sanitize_text_field( $_POST['lang'] ) : 'id';
$paged++; // Load *next* page
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'paged' => $paged,
'meta_query' => array(
array(
'key' => '_cb_content_lang',
'value' => $lang,
'compare' => '=',
),
),
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
$post_index = ($paged - 1) * 6; // Global index start
while ( $query->have_posts() ) : $query->the_post();
$post_index++;
$cycle_pos = ($post_index - 1) % 6 + 1;
credibleblog_render_grid_item( $cycle_pos );
endwhile;
// Safety Close
$remainder = $post_index % 6;
if ( $remainder == 1 ) { echo '</div></div>'; }
elseif ( $remainder == 2 ) { echo '</div>'; }
endif;
wp_reset_postdata();
die();
}
add_action( 'wp_ajax_credibleblog_load_more', 'credibleblog_load_more_posts' );
add_action( 'wp_ajax_nopriv_credibleblog_load_more', 'credibleblog_load_more_posts' );
/* Widget CSS dipindahkan ke assets/css/frontend-components.css */
/**
* Load Modular Files
*/
require get_template_directory() . '/inc/customizer.php';
require get_template_directory() . '/inc/template-tags.php';
require get_template_directory() . '/inc/toc.php';
require get_template_directory() . '/inc/seo.php';
require get_template_directory() . '/inc/i18n.php';
require get_template_directory() . '/inc/i18n-content.php';
require get_template_directory() . '/inc/newsletter.php';
require get_template_directory() . '/inc/contact.php';
require get_template_directory() . '/inc/optimization.php';
require get_template_directory() . '/inc/content-management.php';
require get_template_directory() . '/inc/performance.php';
require get_template_directory() . '/inc/inline-related-posts.php';
require_once get_template_directory() . '/inc/setup.php';
require_once get_template_directory() . '/inc/whitelabel.php';
/**
* Enqueue Admin Theme Styles
* Load CSS kustom untuk area admin WordPress.
*/
function credibleblog_admin_styles() {
wp_enqueue_style(
'credibleblog-admin-theme',
get_template_directory_uri() . '/assets/css/admin.css',
array(),
wp_get_theme()->get( 'Version' )
);
}
add_action( 'admin_enqueue_scripts', 'credibleblog_admin_styles' );
/**
* Sembunyikan Admin Bar secara default untuk menjaga estetika desain premium.
*/
add_filter( 'show_admin_bar', '__return_false' );
/**
* Output Share Bar in Footer (Fixed Position)
*/
function credibleblog_share_bar_footer() {
if ( is_single() ) {
get_template_part( 'template-parts/post/content-share' );
}
}
add_action( 'wp_footer', 'credibleblog_share_bar_footer' );
/**
* Fallback for Footer Menu
*/
function cb_footer_menu_fallback() {
echo '<ul class="footer-links">';
echo '<li><a href="#">' . esc_html( cb_t( 'privacy' ) ) . '</a></li>';
echo '<li><a href="#">' . esc_html( cb_t( 'terms' ) ) . '</a></li>';
echo '</ul>';
}