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
@rahularyan
rahularyan / functions.php
Created February 17, 2021 18:05
Allow question title to be more than 100 characters
<?php
/**
* This hook will make question title to be more than 100 characters.
*
* @param array $form Form arguments.
* @return array
*/
function my_ap_make_question_description_optional( $form ) {
$validate = $form['fields']['post_title']['validate'];
<?php
/**
* Override AnsPress form category field selection list.
*
* @param mixed $form
* @return mixed
*/
function anspress_override_category_field( $form ){
$form['fields']['category'] = array(
'label' => __( 'Category', 'anspress-question-answer' ),
@rahularyan
rahularyan / pre-commit
Created October 1, 2018 14:40
Auto increment version number using git-hook on commit
#!/bin/sh
MESSAGE="$1"
VERSION_PATH=`git rev-parse --show-toplevel`"/style.css"
VER_TOKEN="Version:"
VER_STR=$(grep "$VER_TOKEN" $VERSION_PATH | awk '{print $2}' | tr -d '"')
VER_MAJ=$(echo $VER_STR | awk -F. '{print $1}')
VER_MIN=$(echo $VER_STR | awk -F. '{print $2}')
@rahularyan
rahularyan / rest-questions.php
Created April 25, 2018 04:04
Get AnsPress questions using WP REST api
<?php
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* The version 1 endpoint for AnsPress questions.
*/
<?php
/**
* Hook to filter comments form.
*
* @param array $form Comment form
*/
add_filter( 'ap_comment_form_fields', function( $form ) {
$form['fields']['content']['min_length'] = 1;
return $form;
@rahularyan
rahularyan / functions.php
Created February 13, 2018 02:35
AnsPress: output custom questions list
<?php
$args = array(
'post__in' => [ 1, 2, 3 ];
);
anspress()->questions = new Question_Query( $args );
ap_get_template_part( 'archive' );
@rahularyan
rahularyan / category.php
Created February 11, 2018 04:15
Display single question category of AnsPress
<?php
$category_id = 1; // Replace it.
$question_args = array(
'tax_query' => array(
array(
'taxonomy' => 'question_category',
'field' => 'id',
'terms' => array( $category_id ),
),
<?php
/**
* Filter AnsPress question permastruct.
*
* @param array $structure Question rules.
* @return array
*/
function my_ap_question_perm_structure( $structure ) {
add_rewrite_tag( '%question_category%', '([^/]+)' );
$question_slug = ap_get_page_slug( 'question' );
<?php
/**
* Filters question CPT args.
*/
function my_ap_question_cpt_args( $args ) {
$args['exclude_from_search'] = false;
return $args;
}
add_filter( 'ap_question_cpt_args', 'my_ap_question_cpt_args' );
<?php
function ap_ap_vote_btn_html( 'ap_vote_btn_html', $html, $post ) {
$html = str_replace( 'apicon-thumb-up', 'fa fa-angle-double-up', $html );
// $html = str_replace( 'apicon-thumb-down', 'fa fa-angle-double-up', $html );
return $html;
}
add_filter( 'ap_vote_btn_html', 'ap_ap_vote_btn_html', 10, 2 );