Developer Documentation
NgSurvey Constructs
Two important constructs of NgSurvey are Settings API, Question Types and Extensions.
While question types allow you to add new question types to the NgSurvey core, extensions allow you to extend the functionality. Both question types & extensions are standard WordPress plugins which make use of action hooks and filters to define the new functionality.
Settings APIs are classes which defines the custom settings needed by your extensions. The settings defined by each settings class will be displayed on a new tab in settings page.
NgSurvey provides useful abstract classes to ease the development with few default tasks which are explained in the respective documentation of constructs.
- Learn more about how to create a question type here.
- Learn more about how to create an extension here.
- Learn more about defining your own settings page.
Action Hooks
Besides the question type/extension action hooks, NgSurvey has few other action hooks.
ngsurvey_settings_saved
This action hook is executed after the NgSurvey settings are saved. The hook carry no parameters.
Available since v1.0.0
ngsurvey_survey_complete
This action hook executed after the user completes the survey response. The survey ID and response ID are passed as parameters with this action hook.
Available since v1.0.0
ngsurvey_response_before_action_buttons
This action is executed just before the response form buttons are shown. This action hook is helpful to display any content above the action buttons. The template data object (holds survey object and pages list) is passed to this action hook.
Available since v1.0.0
Filters
Following are the list of filters supported by NgSurvey.
ngsurvey_ajax
Apply the filter to get the data from the implementing extensions and push it to the caller. Using this filter, extensions can execute their custom actions and get the data they need. By reaching this method means all security is passed by using NgSurvey nounce.
- The implementing functions make sure to exectute only intended operation.
- Send a operation request parameter and validate it before applying operation on the data.
Parameters:
- $data – the return value after applying the filters
- $operation – The operation/task that should be executed
Available since v1.0.0
ngsurvey_settings_classes
Use this filter to add your plugin settings to NgSurvey settings page.
Parameters:
- $settings – The list of settings classes. Append your settings class to this and return it.
Available since v1.0.0
ngsurvey_metabox_options
Add your own custom options to the survey metabox using this filter.
Parameters:
- $options – The list of options objects.
Available since v1.0.0
ngsurvey_metabox_defaults
Add your own option’s default values to the survey metabox using this filter.
Parameters:
- $defaults – The associative array of default values.
Available since v1.0.0
ngsurvey_check_survey_key
Use this filter to check the survey key from your custom unique key implementation and inform the survey engine about its existence.
Parameters:
- $status->exists – Boolean value indicates if this key is already found with any other plugin implementing this filter
- $survey_id – the survey ID
- $survey_key – The unique that should be validated
Available since v1.0.0
ngsurvey_response_geographic_data
Gets the demographic data of the user who is responding to this survey. This filter can be used to populate the user city, state and country details by the implementing plugins. An array argument will be passed to this filter which contains the following default values. The plugins should check if there are any values already populated by other plugins.
- ip_address – IP address of the user
- country – empty value
- state – empty value
- city – empty value
Parameters:
- $geographic – associative array with values mentioned above
Available since v1.0.0
ngsurvey_render_scripts & ngsurvey_render_styles
These filters can be used to force render the NgSurvey scripts and styles from third-party plugins. For example, if you would like to display survey in a custom plugin by using do_shortcode action. By default, NgSurvey adds the scripts and styles only on survey pages on the front-end which can be overridden using these filters.
Parameters
- is_rendered – boolean, if you want to render scripts/styles return true from your hook
Available since 1.0.6.