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
// AnsPress select field.
array(
...
'type' => 'select',
// If you have custom list of option then you can pass array directly.
'options' => array(
'select-1' => __( 'Select option label 1' ),
'select-2' => __( 'Select option label 2' ),
),
<?php
// AnsPress radio field.
array(
...
'type' => 'radio',
'options' => array(
'radio-1' => __( 'Radio for something' ),
'radio-2' => __( 'Radio for otherthing ),
),
...
<?php
// AnsPress checkbox field.
array(
...
'type' => 'checkbox',
// If you have only one checkbox then you dont need to pass
// options args.
'options' => array(
'check-1' => __( 'Checkbox for something' ),
'check-2' => __( 'Checkbox for otherthing ),
@rahularyan
rahularyan / textarea-field.php
Created October 25, 2017 16:22
AnsPress textarea field
<?php
// AnsPress textarea field.
array(
...
'type' => 'textarea',
'attr' => array(
'rows' => 10,
),
...
);
@rahularyan
rahularyan / text-field.php
Last active October 26, 2017 04:16
AnsPress text field
<?php
// AnsPress form text field example.
$fields['key_of_field'] => array(
'type' => 'input',
'subtype' => 'text',
'label' => __( 'Custom text field' ),
'attr' => array( // custom HTML tag attributes.
'placeholder' => __( 'Placeholder text goes here' ),
'class' => 'css-class',
),
<?php
// Url field.
$form['fields']['website'] = array(
'label' => __( 'Your website' ),
'desc' => __( 'Enter link to your website.' ),
'subtype' => 'url', // Default type is set to input.
'attr' => array(
'placeholder' => 'https://mydomain.com/',
),
@rahularyan
rahularyan / override-ask-form.php
Created October 24, 2017 01:45
Add custom fields to AnsPress ask form.
<?php
/**
* Add custom fields to AnsPress question form.
*
* This hook will add two new fields in ask form.
*
* @param array $form Form arguments.
* @return void
*/
function my_custom_question_field( $form ) {
<?php
/**
* Register a custom form by "sample_form" name in AnsPress.
*
* @return array
*/
function my_custom_form_in_ap() {
$form = array(
'fields' => array(
'input_field_1' => array( // This is a unique key for field.
<?php
/**
* Login dropdown in header.
* @since 2.0
*/
?>
<ul id="login-sign" class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php _e('Login', 'ab'); ?></a>
<?php
// Thsi query will order users by reputation by default.
$user_args = array(
'ap_query' => true,
'role__not_in' => [ 'administrator', 'ap_moderator' ],
'number' => $number,
);
$ap_user_query = get_users( $user_args );