has_access_and_refresh_token() ) { $this->api = new ConvertKit_API_V4( CONVERTKIT_OAUTH_CLIENT_ID, CONVERTKIT_OAUTH_CLIENT_REDIRECT_URI, $settings->get_access_token(), $settings->get_refresh_token(), $settings->debug_enabled(), $context ); } // Get last query time and existing resources. $this->last_queried = get_option( $this->settings_name . '_last_queried' ); $this->resources = get_option( $this->settings_name ); } /** * Fetches resources (forms, landing pages or tags) from the API, storing them in the options table * with a last queried timestamp. * * If the refresh results in a 401, removes the access and refresh tokens from the settings. * * @since 3.1.2 * * @return WP_Error|array */ public function refresh() { // Call parent refresh method. $result = parent::refresh(); // If an error occurred, maybe delete credentials from the Plugin's settings // if the error is a 401 unauthorized. if ( is_wp_error( $result ) ) { convertkit_maybe_delete_credentials( $result, CONVERTKIT_OAUTH_CLIENT_ID ); } return $result; } /** * Returns all inline forms based on the sort order. * * @since 2.7.3 * * @return bool|array */ public function get_inline() { // If the ConvertKit WordPress Libraries are < 1.3.6 (e.g. loaded by an outdated // addon), or a WordPress site updates this Plugin before other ConvertKit Plugins, // get_by() won't be available and will cause an E_ERROR, crashing the site. // @see https://wordpress.org/support/topic/error-1795/. if ( ! method_exists( $this, 'get_by' ) ) { // @phpstan-ignore-line Older WordPress Libraries won't have this function. return false; } return $this->get_by( 'format', array( 'inline' ) ); } /** * Returns whether any inline forms exist in the options table. * * @since 2.7.3 * * @return bool */ public function inline_exist() { return (bool) $this->get_inline(); } /** * Returns all non-inline forms based on the sort order. * * @since 2.2.4 * * @return bool|array */ public function get_non_inline() { // If the ConvertKit WordPress Libraries are < 1.3.6 (e.g. loaded by an outdated // addon), or a WordPress site updates this Plugin before other ConvertKit Plugins, // get_by() won't be available and will cause an E_ERROR, crashing the site. // @see https://wordpress.org/support/topic/error-1795/. if ( ! method_exists( $this, 'get_by' ) ) { // @phpstan-ignore-line Older WordPress Libraries won't have this function. return false; } return $this->get_by( 'format', array( 'modal', 'slide in', 'sticky bar' ) ); } /** * Returns whether any non-inline forms exist in the options table. * * @since 2.2.4 * * @return bool */ public function non_inline_exist() { if ( ! $this->get_non_inline() ) { return false; } return true; } /** * Returns all non-legacy forms (any v4 format: inline, modal, slide in * or sticky bar) based on the sort order. Legacy forms lack a `format` * key and are therefore excluded. * * @since 3.3.7 * * @return bool|array */ public function get_non_legacy() { // If the ConvertKit WordPress Libraries are < 1.3.6 (e.g. loaded by an outdated // addon), or a WordPress site updates this Plugin before other ConvertKit Plugins, // get_by() won't be available and will cause an E_ERROR, crashing the site. // @see https://wordpress.org/support/topic/error-1795/. if ( ! method_exists( $this, 'get_by' ) ) { // @phpstan-ignore-line Older WordPress Libraries won't have this function. return false; } return $this->get_by( 'format', array( 'inline', 'modal', 'slide in', 'sticky bar' ) ); } /** * Returns whether any non-legacy forms exist in the options table. * * @since 3.3.7 * * @return bool */ public function non_legacy_exist() { return (bool) $this->get_non_legacy(); } /** * Determines if the given Form ID is a legacy Form or Landing Page. * * @since 2.5.0 * * @param int $id Form or Landing Page ID. */ public function is_legacy( $id ) { // Get Form. $form = $this->get_by_id( (int) $id ); // Return false if no Form exists. if ( ! $form ) { return false; } // If the `format` key exists, this is not a legacy Form. if ( array_key_exists( 'format', $form ) ) { return false; } return true; } /** * Returns a CSS class(es). * @param string $selected_option ', esc_attr( $value ), selected( $selected_option, $value, false ), esc_attr( $label ) ); } } // Iterate through resources, if they exist, building ', esc_attr( $form['id'] ), selected( $selected_option, $form['id'], false ), esc_attr( $form['name'] ), ( ! empty( $form['format'] ) ? esc_attr( $form['format'] ) : 'inline' ) ); } } // Close select. $html .= ''; // If no description is provided, return the select field now. if ( ! $description ) { return $html; } // Append description before returning field. if ( ! is_array( $description ) ) { return $html . '

' . $description . '

'; } // Return description lines in a paragraph, using breaklines for each description entry in the array. return $html . '

' . implode( '
', $description ) . '

'; } /** * Outputs a CSS class(es). * @param string $selected_option