Skip to content

Instantly share code, notes, and snippets.

View rahularyan's full-sized avatar
🏠
Working from home

Rahul Arya rahularyan

🏠
Working from home
View GitHub Profile
<?php
function my_ap_activity_actions( $actions ) {
$actions['new_q']['verb'] = 'A question was asked';
return $actions;
}
add_filter( 'ap_activity_actions', 'my_ap_activity_actions' );
<?php
/**
* Save a upload field.
*/
function my_save_pdf_uploads( $post_id ) {
$field = $form->find('pdf');
$field->save_uploads();
foreach( $field->uploaded_files as $filename => $id ) {
update_post_meta( $post_id, 'my_custom_pdf', $id );
#anspress .ap-category-item .ap-cat-img-c .ap-category-icon{
display: none;
}
<?php
$form = anspress()->get_form( 'question' );
$values = array(
'post_title' => 'Question title goes here',
'post_content' => 'Question description goes here',
'is_private' => false, // True if not private.
'category' => 5, // Id of taxonomy term.
'tags' => array(
<?php
// Make sure post is inserted.
if ( ! is_wp_error( $post_id ) ) {
$form = anspress()->get_form( 'question' );
$values = $form->get_values();
$qameta = array(
'last_updated' => current_time( 'mysql' ), // When last question was active.
'answers' => ap_count_published_answers( $post_id ), // numbers of answers.
'anonymous_name' => sanitize_text_field( $values['anonymous_name']['value'] ), // Anonymous user name.
'selected' => false, // Answer id if have a selected answer.
<?php
AP_Form_Hooks::submit_question_form( true );
<?php
// Get question form object.
$form = anspress()->get_form( 'question' );
// Values.
$values = array(
'post_title' => 'Question title goes here',
'post_content' => 'Question description goes here',
'is_private' => false, // True if not private.
'category' => 5, // Id of taxonomy term.
<?php
function my_ap_the_title( $title, $ID ) {
$post = ap_get_post( $ID );
if ( 'question' === $post->post_type && ! empty( ap_selected_answer( $ID ) ) ) {
return $title . ' [solved]';
}
}
add_filter( 'the_title', 'my_ap_the_title', 10, 2 );
<?php
/**
* This hook will make question description field optional.
*
* @param array $form Form arguments.
* @return array
*/
function my_ap_make_question_description_optional( $form ) {
$validate = $form['fields']['post_content']['validate'];
<?php
/**
* Override ap_user_can_ask function.
*
* @param string|boolean $ret Return empty string to continue operation.
* @param integer $user_id
* @return string|false
*/
function my_filter_ap_user_can_ask( $ret, $user_id ) {