/
functions.php
156 lines (140 loc) · 6.09 KB
/
functions.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
<?php
/**
* This file contains theme script, styles and other theme related functions.
* This file can be overridden by creating a anspress directory in active theme folder.
*
* @license https://www.gnu.org/licenses/gpl-2.0.txt GNU Public License
* @author Rahul Aryan <rah12@live.com>
* @package AnsPress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Enqueue scripts.
*/
function ap_scripts_front() {
ap_assets();
if ( ! is_anspress() && ap_opt( 'load_assets_in_anspress_only' ) ) {
return;
}
ap_enqueue_scripts();
$custom_css = '
#anspress .ap-q-cells{
margin-' . ( is_rtl() ? 'right' : 'left' ) . ': ' . ( ap_opt( 'avatar_size_qquestion' ) + 10 ) . 'px;
}
#anspress .ap-a-cells{
margin-' . ( is_rtl() ? 'right' : 'left' ) . ': ' . ( ap_opt( 'avatar_size_qanswer' ) + 10 ) . 'px;
}';
wp_add_inline_style( 'anspress-main', $custom_css );
do_action( 'ap_enqueue' );
wp_enqueue_style( 'ap-overrides', ap_get_theme_url( 'css/overrides.css' ), array( 'anspress-main' ), AP_VERSION );
$aplang = array(
'loading' => __( 'Loading..', 'anspress-question-answer' ),
'sending' => __( 'Sending request', 'anspress-question-answer' ),
// translators: %s is file size in MB.
'file_size_error' => esc_attr( sprintf( __( 'File size is bigger than %s MB', 'anspress-question-answer' ), round( ap_opt( 'max_upload_size' ) / ( 1024 * 1024 ), 2 ) ) ),
'attached_max' => __( 'You have already attached maximum numbers of allowed attachments', 'anspress-question-answer' ),
'commented' => __( 'commented', 'anspress-question-answer' ),
'comment' => __( 'Comment', 'anspress-question-answer' ),
'cancel' => __( 'Cancel', 'anspress-question-answer' ),
'update' => __( 'Update', 'anspress-question-answer' ),
'your_comment' => __( 'Write your comment...', 'anspress-question-answer' ),
'notifications' => __( 'Notifications', 'anspress-question-answer' ),
'mark_all_seen' => __( 'Mark all as seen', 'anspress-question-answer' ),
'search' => __( 'Search', 'anspress-question-answer' ),
'no_permission_comments' => __( 'Sorry, you don\'t have permission to read comments.', 'anspress-question-answer' ),
);
echo '<script type="text/javascript">';
echo 'var ajaxurl = "' . esc_url( admin_url( 'admin-ajax.php' ) ) . '",';
echo 'ap_nonce = "' . esc_attr( wp_create_nonce( 'ap_ajax_nonce' ) ) . '",';
echo 'apTemplateUrl = "' . esc_url( ap_get_theme_url( 'js-template', false, false ) ) . '";';
echo 'apQuestionID = "' . (int) get_question_id() . '";';
echo 'aplang = ' . wp_json_encode( $aplang ) . ';';
echo 'disable_q_suggestion = "' . (bool) ap_opt( 'disable_q_suggestion' ) . '";';
echo '</script>';
}
add_action( 'wp_enqueue_scripts', 'ap_scripts_front', 1 );
/**
* Register widget positions.
*/
function ap_widgets_positions() {
register_sidebar(
array(
'name' => __( '(AnsPress) Before', 'anspress-question-answer' ),
'id' => 'ap-before',
'before_widget' => '<div id="%1$s" class="ap-widget-pos %2$s">',
'after_widget' => '</div>',
'description' => __( 'Widgets in this area will be shown before anspress body.', 'anspress-question-answer' ),
'before_title' => '<h3 class="ap-widget-title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => __( '(AnsPress) Question List Top', 'anspress-question-answer' ),
'id' => 'ap-top',
'before_widget' => '<div id="%1$s" class="ap-widget-pos %2$s">',
'after_widget' => '</div>',
'description' => __( 'Widgets in this area will be shown before questions list.', 'anspress-question-answer' ),
'before_title' => '<h3 class="ap-widget-title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => __( '(AnsPress) Sidebar', 'anspress-question-answer' ),
'id' => 'ap-sidebar',
'before_widget' => '<div id="%1$s" class="ap-widget-pos %2$s">',
'after_widget' => '</div>',
'description' => __( 'Widgets in this area will be shown in AnsPress sidebar except single question page.', 'anspress-question-answer' ),
'before_title' => '<h3 class="ap-widget-title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => __( '(AnsPress) Question Sidebar', 'anspress-question-answer' ),
'id' => 'ap-qsidebar',
'before_widget' => '<div id="%1$s" class="ap-widget-pos %2$s">',
'after_widget' => '</div>',
'description' => __( 'Widgets in this area will be shown in single question page sidebar.', 'anspress-question-answer' ),
'before_title' => '<h3 class="ap-widget-title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => __( '(AnsPress) Category Page', 'anspress-question-answer' ),
'id' => 'ap-category',
'before_widget' => '<div id="%1$s" class="ap-widget-pos %2$s">',
'after_widget' => '</div>',
'description' => __( 'Widgets in this area will be shown in category listing page.', 'anspress-question-answer' ),
'before_title' => '<h3 class="ap-widget-title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => __( '(AnsPress) Tag page', 'anspress-question-answer' ),
'id' => 'ap-tag',
'before_widget' => '<div id="%1$s" class="ap-widget-pos %2$s">',
'after_widget' => '</div>',
'description' => __( 'Widgets in this area will be shown in tag listing page.', 'anspress-question-answer' ),
'before_title' => '<h3 class="ap-widget-title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => __( '(AnsPress) Author page', 'anspress-question-answer' ),
'id' => 'ap-author',
'before_widget' => '<div id="%1$s" class="ap-widget-pos %2$s">',
'after_widget' => '</div>',
'description' => __( 'Widgets in this area will be shown in authors page.', 'anspress-question-answer' ),
'before_title' => '<h3 class="ap-widget-title">',
'after_title' => '</h3>',
)
);
}
add_action( 'widgets_init', 'ap_widgets_positions' );