'', 'name' => '', 'type' => '', 'size' => 'full' ), $atts ) ); $content = ''; if( $name != '' ) { $id = acd_data_get_id_by_name( $name, $id ); } if( intval($id)>0 ) { $acd_type = sanitize_text_field( get_post_meta( $id, '_acd_type', true ) ); $acd_data = acd_data_sanitize_content_field( get_post_meta( $id, '_acd_data', true ), $acd_type ); if( $acd_type == 'list' ) { $list = array(); foreach( explode("\n", $acd_data) as $value ) { $list[] = '
  • '. $value . '
  • '; } $content = "'; } else if( $acd_type == 'thumbnail' ) { if( $type == 'url' ) { $content = get_the_post_thumbnail_url( $id, $size ); } else { $content = get_the_post_thumbnail( $id, $size ); } } else if( $acd_type == 'br' ) { $content = nl2br($acd_data); } else { $content = $acd_data; } } return $content; } add_shortcode( 'acd-data', 'acd_data_do_shortcode' ); /* * Since 1.0.0 * * Updated 1.0.4 * * return * * @array : scanned_tag */ function acd_data_wpcf7_form_tag( $scanned_tag, $replace ) { if( count($scanned_tag['options']) == 0 ) { return $scanned_tag; } $types = array( "select", "checkbox", "radio" ); foreach( $types as $value ) { $types[] = $value . '*'; } if( in_array( $scanned_tag['type'], $types ) ) { $acd_data_id = 0; foreach( $scanned_tag['options'] as $opt ) { if( preg_match('/(acd-data)/i', $opt) ) { $a = explode(':', $opt ); $acd_data_id = isset($a[1]) ? $a[1] : 0; break; } } if( $acd_data_id === 0 ){ return $scanned_tag; } $data = acd_data_get_content( $acd_data_id ); if( empty($data) || $data == '' ) { return $scanned_tag; } $values = array(); $labels = array(); foreach( explode("\n", $data) as $value ) { $value = sanitize_text_field($value); $a = explode(' : ', $value ); if( isset($a[1]) ) { $values[] = $a[0]; $labels[] = $a[1]; } else { $values[] = $value; $labels[] = $value; } } if( count($values) > 0 ){ $scanned_tag['raw_values'] = $values; $scanned_tag['values'] = $values; $scanned_tag['labels'] = $labels; } } return $scanned_tag; } add_filter('wpcf7_form_tag', 'acd_data_wpcf7_form_tag', 20, 2); /* * Since 1.0.3 * * return * * @string : data */ function acd_data_strip_tags( $data = '', $tags_more = array() ) { $allowed_tags = explode(',', 'ul,ol,li,span,strong,em,p,b,i,u' ); if( count($tags_more) ) { $allowed_tags = array_merge( $tags_more ); } $data = strip_tags( $data, $allowed_tags ); return trim( $data ); } /* * Since 1.0.3 * * return * * @string : data */ function acd_data_sanitize_content_field( $string = '', $type = '' ) { if ( is_object( $string ) || is_array( $string ) ) { return ''; } if( $type != 'script' ) { $string = preg_replace( '@<(script|style)[^>]*?>.*?@si', '', $string ); } // sanitize_textarea_field(); return trim( $string ); } /* * Since 1.0.4 * * return * * @string : data */ function acd_data_get_content( $id = 0, $type = 'textarea' ) { if( preg_match('/[a-z]/i', $id ) ) { $id = acd_data_get_id_by_name( $id ); } if( $id == 0 ) { return ''; } $content = get_post_meta( $id, '_acd_data', true ); if( $type == 'textarea' ) { $content = sanitize_textarea_field( $content ); } else if( $type == 'text' ) { $content = sanitize_text_field( $content ); } return $content; } /* * Since 1.0.4 * * return * * @number : id */ function acd_data_get_id_by_name( $name = '', $id = 0 ) { $p = get_page_by_path($name, $output = OBJECT, $post_type = 'acd-data' ); $id = is_object($p) && isset($p->ID) ? $p->ID : $id; return $id; } /* * Since 1.0.4 * * return * * @array : $field */ function acd_data_acf_prepare_field( $field ) { // Abort if it's native option if( $field['ID'] === 0 ) return $field; $types = array( "select", "checkbox", "radio" ); if( in_array( $field['type'], $types ) ) { $acd_data_id = 0; foreach( $field['choices'] as $opt ) { if( preg_match('/(acd-data)/i', $opt) ) { $a = explode(':', $opt ); $acd_data_id = isset($a[1]) ? $a[1] : 0; break; } } if( $acd_data_id === 0 ){ return $field; } $data = acd_data_get_content( $acd_data_id ); if( empty($data) || $data == '' ) { return $field; } $choices = []; foreach( explode("\n", $data) as $value ) { $value = sanitize_text_field($value); $a = explode(' : ', $value ); if( isset($a[1]) ) { $choices[ $a[0] ] = $a[1]; } else { $choices[ $value ] = $value; } } $field['choices'] = $choices; } return $field; } add_filter('acf/prepare_field', 'acd_data_acf_prepare_field', 1, 1); /* * Since 1.0.5 * */ function acd_debug( $content = '' ) { if( !function_exists('file_get_contents') || !function_exists('file_put_contents') ) return; $file = ABSPATH . '/acd-debug.txt'; $old = ''; if( file_exists($file) ) { $old = file_get_contents($file); } $content .= "\n\r" . $old; file_put_contents( $file, $content ); }