Noptin_Form::get_data_by( string $field, string|int $value )
Fetch a form from the db/cache
Parameters Parameters
- $field
(string) (Required) The field to query against: At the moment only ID is allowed.
- $value
(string|int) (Required) The field value.
Return Return
(array|false) array of form details on success. False otherwise.
Source Source
File: includes/class-noptin-form.php
public function get_data_by( $field, $value ) { // 'ID' is an alias of 'id'... if ( 'id' === strtolower( $field ) ) { // Make sure the value is numeric to avoid casting objects, for example, to int 1. if ( ! is_numeric( $value ) ) { return false; } // Ensure this is a valid form id. $value = intval( $value ); if ( $value < 1 ) { return false; } } else { return false; } // Maybe fetch from cache. $form = wp_cache_get( $value, 'noptin_forms' ); if ( $form ) { return $form; } // Fetch the post object from the db. $post = get_post( $value ); if ( ! $post || 'noptin-form' !== $post->post_type ) { return false; } // Init the form. $form = array( 'optinName' => $post->post_title, 'optinStatus' => ( 'draft' !== $post->post_status ), 'id' => $post->ID, 'optinHTML' => $post->post_content, 'optinType' => get_post_meta( $post->ID, '_noptin_optin_type', true ), ); $state = get_post_meta( $post->ID, '_noptin_state', true ); if ( ! is_array( $state ) ) { $state = array(); } $form = array_merge( $state, $form ); // Update the cache with out data. wp_cache_add( $post->ID, $form, 'noptin_forms' ); return $this->sanitize_form_data( $form ); }
Expand full source code Collapse full source code View on GitHub