api_key = $option['api_key']; } if ( $this->uses_api_key() || empty( $option['api_key'] ) ) { add_action( 'admin_notices', array( $this, 'display_deprecated_key_notice' ) ); } } /** * Returns service title * * @return mixed */ public function get_title() { return __( 'Airtable', 'add-on-cf7-for-airtable' ); } /** * Returns true if the api key is defined * * @return bool */ public function is_active() { return (bool) $this->get_api_key(); } /** * Returns the api key * * @return mixed|string */ public function get_api_key() { return $this->api_key; } /** * Returns the service categories * * @return string[] */ public function get_categories() { return array( 'collaboration_platform' ); } /** * Returns the service icon * * @return string */ public function icon() { return ''; } /** * Returns the link to the Airtable website * * @return string|void */ public function link() { echo wp_kses_post( wpcf7_link( 'https://airtable.com', 'airtable.com' ) ); } /** * Sends a debug information for a remote request to the PHP error log. * * @param string $url URL to retrieve. * @param array $request Request arguments. * @param array|WP_Error $response The response or WP_Error on failure. * @return void */ protected function log( $url, $request, $response ) { wpcf7_log_remote_request( $url, $request, $response ); } /** * Returns the integration admin page. * * @param string|array|object $args Args. * @return mixed */ protected function menu_page_url( $args = '' ) { $args = wp_parse_args( $args, array() ); $url = menu_page_url( 'wpcf7-integration', false ); $url = add_query_arg( array( 'service' => 'wpc_airtable' ), $url ); if ( ! empty( $args ) ) { $url = add_query_arg( $args, $url ); } return $url; } /** * Saves integration form data. * * @return void */ protected function save_data() { \WPCF7::update_option( Options\get_option_key( 'airtable_service' ), array( 'api_key' => $this->api_key, ) ); } /** * Reset service data. * * @return void */ protected function reset_data() { $this->api_key = null; $this->save_data(); } /** * Integration form handler. * * @param string $action Action. * @return void */ public function load( $action = '' ) { if ( 'setup' === $action && isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] ) { check_admin_referer( 'wpc-wpcf7-airtable-setup' ); if ( ! empty( $_POST['reset'] ) ) { $this->reset_data(); $redirect_to = $this->menu_page_url( 'action=setup' ); } else { $this->api_key = isset( $_POST['api_key'] ) ? trim( sanitize_text_field( wp_unslash( $_POST['api_key'] ) ) ) : ''; $confirmed = ! empty( $this->api_key ); Helpers\process_airtable_test_request_response( $confirmed ? true : new \WP_Error( __( 'Invalid key values.', 'add-on-cf7-for-airtable' ) ) ); if ( true === $confirmed ) { $redirect_to = $this->menu_page_url( array( 'message' => 'success', ) ); $this->save_data(); } elseif ( false === $confirmed ) { $redirect_to = $this->menu_page_url( array( 'action' => 'setup', 'message' => 'unauthorized', ) ); } else { $redirect_to = $this->menu_page_url( array( 'action' => 'setup', 'message' => 'invalid', ) ); } } wp_safe_redirect( $redirect_to ); exit(); } } /** * Show admin notices. * * @param string $message Admin notice message. * @return void */ public function admin_notice( $message = '' ) { if ( 'unauthorized' === $message ) { printf( '
%1$s: %2$s
%1$s: %2$s
%s
' . sprintf(
/* translators: %s: html link */
esc_html( __( 'Store form submissions in Airtable table. For details, see %s.', 'add-on-cf7-for-airtable' ) ),
wp_kses_post(
str_replace(
'';
if ( $this->is_active() ) {
printf(
' %s %1$s%2$s
%s