Functions Reference

  • JNext lesson
  • KPrevious lesson
  • FSearch lessons
  • EscClear search

Core Forms provides a set of global PHP functions for working with forms, submissions, polls, and email logs. All functions are defined in src/functions.php.

Form Functions

cf_get_forms( $args = array() )

Retrieve multiple forms.

$forms = cf_get_forms();
$forms = cf_get_forms( array( 'posts_per_page' => 10 ) );

Parameters:

  • $args (array) – Arguments passed to WP_Query. Defaults to all published core-form posts.

Returns: Array of Form objects.

cf_get_form( $form_id_or_slug )

Get a single form by ID, slug, or WP_Post object.

$form = cf_get_form( 123 );
$form = cf_get_form( 'contact-form' );
$form = cf_get_form( $post );

Parameters:

  • $form_id_or_slug (int|string|WP_Post) – Form ID, slug, or post object.

Returns: Form object.

Throws: Exception if the form is not found or the post is not a core-form type.

cf_get_form_by_slug( $slug )

Get a form by slug only. Unlike cf_get_form(), this always does a slug lookup even for numeric strings.

$form = cf_get_form_by_slug( 'contact-form' );

Parameters:

  • $slug (string) – The form post slug.

Returns: Form object.

Throws: Exception if no form matches the slug.

Submission Functions

cf_get_form_submissions( $form_id, $args = array() )

Get submissions for a specific form.

$submissions = cf_get_form_submissions( 123 );
$submissions = cf_get_form_submissions( 123, array(
    'offset' => 0,
    'limit'  => 50,
) );

Parameters:

  • $form_id (int) – The form post ID.
  • $args (array) – Optional. offset (default 0) and limit (default 1000).

Returns: Array of Submission objects, keyed by submission ID, ordered by date descending.

cf_get_form_submission( $submission_id )

Get a single submission by ID.

$submission = cf_get_form_submission( 456 );
echo $submission->data['email'];

Parameters:

  • $submission_id (int) – The submission ID.

Returns: Submission object.

cf_get_all_submissions( $args = array() )

Get submissions across all forms with filtering.

$submissions = cf_get_all_submissions( array(
    'form_id'   => 0,
    'search'    => 'john',
    'is_spam'   => false,
    'date_from' => '2024-01-01',
    'date_to'   => '2024-12-31',
    'offset'    => 0,
    'limit'     => 50,
    'orderby'   => 'submitted_at',
    'order'     => 'DESC',
) );

Parameters:

  • form_id (int) – Filter by form ID. 0 for all forms.
  • search (string) – Search term to match against submission data.
  • is_spam (bool|null) – Filter by spam status. null for all, true for spam, false for non-spam.
  • date_from (string) – Start date (Y-m-d format).
  • date_to (string) – End date (Y-m-d format).
  • offset (int) – Pagination offset.
  • limit (int) – Maximum results.
  • orderby (string) – Order by column: submitted_at, form_id, or id.
  • order (string) – ASC or DESC.

Returns: Array of Submission objects.

cf_count_form_submissions( $form_id )

Count submissions for a specific form.

$count = cf_count_form_submissions( 123 );

Returns: Integer count.

cf_count_all_submissions( $args = array() )

Count submissions across all forms with the same filtering options as cf_get_all_submissions().

$total = cf_count_all_submissions( array( 'is_spam' => false ) );

Returns: Integer count.

cf_search_submissions( $search, $form_id = 0, $args = array() )

Search submissions by content.

$results = cf_search_submissions( 'john@example.com' );
$results = cf_search_submissions( 'john', 123 );

Parameters:

  • $search (string) – Search term.
  • $form_id (int) – Optional form ID to limit search.
  • $args (array) – Additional query arguments.

Returns: Array of Submission objects.

Reply Functions

cf_get_submission_replies( $submission_id )

Get all replies for a submission.

$replies = cf_get_submission_replies( 456 );
foreach ( $replies as $reply ) {
    echo $reply->subject . ': ' . $reply->message;
}

Returns: Array of Reply objects, ordered by date descending.

cf_count_submission_replies( $submission_id )

Count replies for a submission.

Returns: Integer count.

cf_get_default_reply_email()

Get the default “From” email for replies. Returns the value from plugin settings, or falls back to the WordPress admin email.

Returns: Email address string.

Settings Function

cf_get_settings()

Get the global plugin settings.

$settings = cf_get_settings();
$nonce_enabled = $settings['enable_nonce'];
$recaptcha_key = $settings['google_recaptcha']['site_key'];

Returns: Associative array with these keys:

  • enable_nonce (int) – Whether nonce verification is enabled.
  • load_stylesheet (int) – Whether to load the form stylesheet on every page.
  • wrapper_tag (string) – HTML tag for wrapping field groups.
  • google_recaptcha (array) – site_key and secret_key.
  • cloudflare_turnstile (array) – site_key and secret_key.
  • reply_from_email (string) – Default reply sender email.

Template Functions

cf_template( $template )

Process template tags ({{namespace.property}}) in a string.

$greeting = cf_template( 'Hello {{user.display_name}}!' );

Parameters:

  • $template (string) – String containing template tags.

Returns: String with tags replaced.

cf_replace_data_variables( $string, $submission, $escape_function = null )

Replace data variables ([field_name]) in a string using submission data.

$message = cf_replace_data_variables( 'Hello [name]!', $submission );
$safe = cf_replace_data_variables( '[name]', $submission, 'esc_html' );

Parameters:

  • $string (string) – String containing data variables.
  • $submission (Submission) – The submission object.
  • $escape_function (callable|null) – Optional function to escape the replacement values.

Returns: String with variables replaced.

Utility Functions

cf_array_get( $array, $key, $default = null )

Get a value from an array using dot notation.

$value = cf_array_get( $data, 'user.email', 'default@example.com' );

cf_field_value( $value, $limit = 0, $escape_function = 'esc_html' )

Format a submission field value for display. Handles files, dates, arrays, and plain strings.

cf_is_file( $value )

Returns true if the value looks like a file upload (array with name, size, and type keys).

cf_is_date( $value )

Returns true if the value looks like a date string from an <input type="date"> field.

cf_human_filesize( $size, $precision = 2 )

Convert bytes to a human-readable file size string (e.g., “1.5MB”).

cf_get_admin_tabs( $form )

Get the array of admin tabs for a form edit screen. Returns a filterable array of tab slugs and labels.

Email Log Functions

cf_log_email( $data )

Log an email attempt.

$log_id = cf_log_email( array(
    'form_id'       => 123,
    'submission_id' => 456,
    'to_email'      => 'user@example.com',
    'from_email'    => 'admin@example.com',
    'subject'       => 'New submission',
    'message'       => 'You have a new submission.',
    'headers'       => '',
    'status'        => 'pending',
    'action_type'   => 'email',
) );

Returns: Log ID (int) or false on failure.

cf_update_email_log_status( $log_id, $status, $error_message = null )

Update the status of an email log entry.

cf_update_email_log_status( $log_id, 'sent' );
cf_update_email_log_status( $log_id, 'failed', 'SMTP connection refused' );

cf_get_email_logs( $args = array() )

Get email logs with filtering. Supports form_id, submission_id, status, search, date_from, date_to, offset, limit, orderby, and order.

cf_count_email_logs( $args = array() )

Count email logs with the same filtering options.

cf_delete_old_email_logs( $days_old = 90 )

Delete email logs older than the specified number of days.

Returns: Number of rows deleted.

Poll Functions

cf_get_poll( $poll_id )

Get a poll by its ID.

Returns: Poll object or null.

cf_get_poll_by_post_id( $post_id )

Get a poll by its associated post ID.

Returns: Poll object or null.

cf_get_poll_by_slug( $slug )

Get a poll by its post slug.

Returns: Poll object or null.

cf_get_poll_results( $poll_id )

Get vote counts for each option.

Returns: Associative array of option_index => vote_count.

cf_get_poll_total_votes( $poll_id )

Get the total number of votes for a poll.

Returns: Integer count.