prefix . '_' . $event, [ $this, $event ] ); } } /** * Checks if the user has the permission to perform the requested action and verifies the nonce. * * @param string $option The name of the option to check the nonce against. * @param string $scope The capability required to perform the action. Default is 'manage_options'. * @param string $security The security to check the nonce against. Default is 'security'. * @return void * * @since 2.5.0 */ public function check_permission_nonce( $action, $capability = 'manage_options', $query_arg = 'security' ) { $nonce = sanitize_text_field( wp_unslash( $_POST[ $query_arg ] ?? '' ) ); if ( ! wp_verify_nonce( $nonce, $action ) ) { wp_send_json_error( [ 'message' => static::NONCE_ERROR ] ); } if ( ! current_user_can( $capability ) ) { wp_send_json_error( [ 'message' => static::PERMISSION_ERROR ] ); } } /** * Save setting - Sanitizes form inputs. * * @param array $input_settings setting data. * @return array The sanitized form inputs. */ public function sanitize_form_inputs( $input_settings = [] ) { $new_settings = []; if ( ! empty( $input_settings ) ) { foreach ( $input_settings as $key => $value ) { $new_key = sanitize_text_field( $key ); if ( is_array( $value ) ) { $new_settings[ $new_key ] = $this->sanitize_form_inputs( $value ); } else { $new_settings[ $new_key ] = sanitize_text_field( $value ); } } } return $new_settings; } }