Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Rahul Aryan rahularyan

🏠
Working from home
View GitHub Profile
@rahularyan
rahularyan / pre-commit
Created Oct 1, 2018
Auto increment version number using git-hook on commit
View pre-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 Apr 25, 2018
Get AnsPress questions using WP REST api
View rest-questions.php
<?php
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* The version 1 endpoint for AnsPress questions.
*/
View functions.php
<?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 Feb 13, 2018
AnsPress: output custom questions list
View functions.php
<?php
$args = array(
'post__in' => [ 1, 2, 3 ];
);
anspress()->questions = new Question_Query( $args );
ap_get_template_part( 'archive' );
@rahularyan
rahularyan / category.php
Created Feb 11, 2018
Display single question category of AnsPress
View category.php
<?php
$category_id = 1; // Replace it.
$question_args = array(
'tax_query' => array(
array(
'taxonomy' => 'question_category',
'field' => 'id',
'terms' => array( $category_id ),
),
View functions.php
<?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' );
View functions.php
<?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' );
View functions.php
<?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 );
View functions.php
<?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' );
View functions.php
<?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 );
You can’t perform that action at this time.