: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$table_data = $wpdb->get_results($obj_query, ARRAY_A);
foreach($table_data as $data_item) {
foreach($data_item as $label => $val ) {
$generic_object_array[$data_item['id']]->_settings[$label] = maybe_unserialize( $val );
$meta_query = "SELECT * FROM {$this->_meta_table_name} WHERE parent_id IN (" . implode(',', $id_array) . ")";
$meta_data = $wpdb->get_results($meta_query, ARRAY_A);
foreach($meta_data as $meta) {
// if( ! isset($generic_object_array[$meta['parent_id']]->_settings[$meta['meta_key']])) {
$generic_object_array[$meta['parent_id']]->_settings[$meta['meta_key']] = maybe_unserialize( $meta['meta_value'] );
$obj_array = array_values($generic_object_array);
* Check to see if we've completed stage 1 of our db update.
$sql = "SHOW COLUMNS FROM {$this->_db->prefix}nf3_fields LIKE 'field_key'";
$results = $this->_db->get_results( $sql );
* If we don't have the field_key column, we need to remove our new columns.
* Also, set our db stage 1 tracker to false.
if ( empty ( $results ) ) {
$this->db_stage_1_complete = false;
$data = array ( 'updated_at' => current_time( 'mysql' ));
// If the ID is not set, assign an ID
$data[ 'created_at' ] = current_time( 'mysql' ) ;
$data['parent_id'] = $this->_parent_id;
// Create a new row in the database
$result = $this->_db->insert(
$this->_id = $this->_db->insert_id;
$result = $this->_db->get_row( "SELECT * FROM $this->_table_name WHERE id = $this->_id" );
$this->_insert_row( array( 'id' => $this->_id ) );
// If a Temporary ID is set, return it along with the newly assigned ID.
return array( $this->_tmp_id => $this->_id );
public function _insert_row( $data = array() )
$data[ 'created_at' ] = current_time( 'mysql' );
$data['parent_id'] = $this->_parent_id;
// Create a new row in the database
$result = $this->_db->insert(
public function cache( $cache = '' )
// Set the Cache Flag Property.
// Return the current object for method chaining.
* Set the Parent ID and Parent Type properties
public function add_parent( $parent_id, $parent_type )
$this->_parent_id = $parent_id;
$this->_parent_type = $parent_type;
// Return the current object for method chaining.
//-----------------------------------------------------
//-----------------------------------------------------
protected function _save_setting( $key, $value )
// If the setting is a column, save the settings to the model's table.
if( in_array( $key, $this->_columns ) ){
if( in_array( $key, array( 'show_title', 'clear_complete', 'hide_complete', 'logged_in' ) ) ) {
// gotta set the format for the columns that use bit type
if( 'form' === $this->_type && 'title' == $key ) {
// Don't update the form_title. Duplicating issue for now
if( 'form_title' !== $key ) {
$update_model = $this->_db->update(
* if it's not a form, you can return, but we are still saving some
* settings for forms in the form_meta table
if( 'form' != $this->_type
|| ( 'form' == $this->_type && 'title' == $key ) ) {
$meta_row = $this->_db->get_row(
FROM `$this->_meta_table_name`
WHERE `parent_id` = $this->_id
// for forms we need to update the meta_key and meta_value columns
if( 'form' == $this->_type || $this->db_stage_1_complete ) {
$update_values[ 'meta_key' ] = $key;
$update_values[ 'meta_value' ] = $value;
$result = $this->_db->update(
'parent_id' => $this->_id
'parent_id' => $this->_id
// for forms we need to update the meta_key and meta_value columns
if( 'form' == $this->_type || $this->db_stage_1_complete ) {
$insert_values[ 'meta_key' ] = $key;
$insert_values[ 'meta_value' ] = $value;
$result = $this->_db->insert(
protected function _save_settings()
if( ! $this->_settings ) return;
foreach( $this->_settings as $key => $value ) {
$value = maybe_serialize( $value );
$this->_results[] = $this->_save_setting( $key, $value );
$this->_save_parent_relationship();
* Save Parent Relationship
protected function _save_parent_relationship()
// ID, Type, Parent ID, and Parent Type are required for creating a relationship.
if( ! $this->_id || ! $this->_type || ! $this->_parent_id || ! $this->_parent_type ) return $this;
// Check to see if a relationship exists.
FROM $this->_relationships_table
WHERE `child_id` = $this->_id
AND `child_type` = '$this->_type'
// If a relationship does not exists, then create one.
if( 0 == $this->_db->num_rows ) {
$this->_relationships_table,
'child_id' => $this->_id,
'child_type' => $this->_type,
'parent_id' => $this->_parent_id,
'parent_type' => $this->_parent_type
// Return the current object for method chaining.
* @param string $parent_id
protected function build_meta_query( $parent_id = '', array $where = array() )
$join_statement = array();
$where_statement = array();
if( $where AND is_array( $where ) ) {
$where_conditions = array();
foreach ($where as $key => $value) {
$conditions['key'] = $key;
$conditions['value'] = $value;
$where_conditions[] = $conditions;
for ($i = 0; $i < $count; $i++) {
$join_statement[] = "INNER JOIN " . $this->_meta_table_name . " as meta$i on meta$i.parent_id = " . $this->_table_name . ".id";
$where_statement[] = "( meta$i.key = '" . $where_conditions[$i]['key'] . "' AND meta$i.value = '" . $where_conditions[$i]['value'] . "' )";
$join_statement = implode( ' ', $join_statement );
$where_statement = implode( ' AND ', $where_statement );
// TODO: Breaks SQL. Needs more testing.
// if( $where_statement ) $where_statement = "AND " . $where_statement;
$where_statement = "$this->_table_name.parent_id = $parent_id $where_statement";
if( ! empty( $where_statement ) ) {
$where_statement = "WHERE $where_statement";
return "SELECT DISTINCT $this->_table_name.id FROM $this->_table_name $join_statement $where_statement";