class-fl-builder-service.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Base class for third party services.
  4. *
  5. * @since 1.5.4
  6. */
  7. abstract class FLBuilderService {
  8. /**
  9. * The ID for this service such as aweber or mailchimp.
  10. *
  11. * @since 1.5.4
  12. * @var string $id
  13. */
  14. public $id = '';
  15. /**
  16. * Test the API connection.
  17. *
  18. * @since 1.5.4
  19. * @param array $fields
  20. * @return array{
  21. * @type bool|string $error The error message or false if no error.
  22. * @type array $data An array of data used to make the connection.
  23. * }
  24. */
  25. abstract public function connect( $fields = array() );
  26. /**
  27. * Renders the markup for the connection settings.
  28. *
  29. * @since 1.5.4
  30. * @return string The connection settings markup.
  31. */
  32. abstract public function render_connect_settings();
  33. /**
  34. * Render the markup for service specific fields.
  35. *
  36. * @since 1.5.4
  37. * @param string $account The name of the saved account.
  38. * @param object $settings Saved module settings.
  39. * @return array {
  40. * @type bool|string $error The error message or false if no error.
  41. * @type string $html The field markup.
  42. * }
  43. */
  44. abstract public function render_fields( $account, $settings );
  45. /**
  46. * Get the saved data for a specific account.
  47. *
  48. * @since 1.5.4
  49. * @param string $account The account name.
  50. * @return array|bool The account data or false if it doesn't exist.
  51. */
  52. public function get_account_data( $account ) {
  53. $saved_services = FLBuilderModel::get_services();
  54. if ( isset( $saved_services[ $this->id ] ) && isset( $saved_services[ $this->id ][ $account ] ) ) {
  55. return $saved_services[ $this->id ][ $account ];
  56. }
  57. return false;
  58. }
  59. }