error_reporting(0);
ini_set('display_errors', 0);
// date_default_timezone_set(get_option('timezone_string'));
setlocale(LC_ALL, tt('pl_PL.utf8','en_US'));
setlocale(LC_NUMERIC, 'C');
add_action('init', 'myStartSession', 1);
function myStartSession() {
if(!session_id() && !is_admin()) {
session_start();
}
}
function acf_post_object_custom_query( $args, $field, $post_id )
{
$args['orderby'] = null;
$args['posts_per_page'] = 20000;
// unset($args['post_type']);
// error_log(print_r($args,true));
// error_log(print_r($field,true));
// error_log(print_r($post_id,true));
return $args;
}
if (is_admin()) {
add_filter( 'acf/fields/post_object/query', 'acf_post_object_custom_query', 10, 3 );
}
add_action( 'after_setup_theme', 'msz_theme_setup' );
function msz_theme_setup() {
add_image_size( 'postlink', 440 ); // 440 pixels wide (and unlimited height)
}
for ($i=1;$i<=20;$i++) {
add_shortcode( 'ludzie'.$i, function($atts) use ($i) {
global $hide_block_ludzie_at_bottom;
$hide_block_ludzie_at_bottom=true;
global $from_shortcode, $ludzie_label_nr;
$from_shortcode=true; $ludzie_label_nr=$i;
ob_start();
get_template_part('block','ludzie');
return ob_get_clean();
unset($from_shortcode); unset($ludzie_label_nr);
});
}
add_shortcode( 'ludzie', function($atts) {
global $hide_block_ludzie_at_bottom;
$hide_block_ludzie_at_bottom=true;
global $from_shortcode;
$from_shortcode=true;
global $block_ludzie_show_labels;
$block_ludzie_show_labels=true;
ob_start();
get_template_part('block','ludzie');
return ob_get_clean();
$from_shortcode=false;
$block_ludzie_show_labels=false;
});
add_shortcode( 'statystyki', function() {
return '
';
});
add_shortcode( 'logosy', function() {
return '';
});
add_shortcode( 'pliki', function() {
global $hide_block_zalaczniki_at_bottom;
$hide_block_zalaczniki_at_bottom=true;
return '';
});
function wpdocs_register_meta_boxes() {
global $post;
if (isset($post) && has_category('event',$post)) {
add_meta_box( 'lista_zapisow', "Lista zapisów", 'msz_lista_zapisow', 'post' );
}
}
add_action( 'add_meta_boxes', 'wpdocs_register_meta_boxes' );
function msz_lista_zapisow( $post ) {
$meta=get_post_meta($post->ID,'Rejestracja');
?>
Pobierz dane jako CSV
Imię i nazwisko | Email | Data wydarzenia | Data rejestracji |
$fields=get_field('dodatkowe_pola_formularza',$post->ID);
if ($fields) foreach ($fields as $f) {
$label=$f['nazwa_pola'];
$name=sanitize_title($f['nazwa_pola']);
echo ''.$label.' | ';
} ?>
foreach ($meta as $row) {
echo '';
echo ''.str_replace(';;',' | ',$row).' | ';
echo '
';
}
echo '
';
}
add_filter('acf/load_value/type=textarea', function($value,$post_id,$field) {
if (!is_admin() && $field['name']=='lead') return sierotki($value);
return $value;
}, 10, 3);
/*
* Add columns to post list
*/
function add_acf_columns ( $columns ) {
return array_merge ( $columns, array (
'related_parent' => 'Nadrzędny wpis'
// ,'end_date' => __ ( 'Ends' )
) );
}
add_filter ( 'manage_post_posts_columns', 'add_acf_columns' );
/*
* Add columns to post list
*/
function post_custom_column ( $column, $post_id ) {
switch ( $column ) {
case 'related_parent':
$rel=get_field('nadrzedny_wpis',$post_id);
if ($rel) foreach ($rel as $r) {
?>
}
break;
}
}
add_action ( 'manage_post_posts_custom_column', 'post_custom_column', 10, 2 );
/*
* Add columns to post list
*/
function add_acf_columns_logosy ( $columns ) {
return array_merge ( $columns, array (
'pix' => 'Obrazek'
// ,'end_date' => __ ( 'Ends' )
) );
}
add_filter ( 'manage_logosy_posts_columns', 'add_acf_columns_logosy' );
/*
* Add columns to post list
*/
function logosy_custom_column ( $column, $post_id ) {
switch ( $column ) {
case 'pix':
$pix=get_featured_image('thumbnail',$post_id);
if ($pix) {
?>
}
break;
}
}
add_action ( 'manage_logosy_posts_custom_column', 'logosy_custom_column', 10, 2 );
function post_save_postprocessing( $post_id ) {
if (has_category('event',$post_id)) {
$eventdata=get_field('rep_program',$post_id);
delete_post_meta( $post_id, 'eventdate' );
delete_post_meta( $post_id, 'eventdate_end' );
if ($eventdata) foreach ($eventdata as $event) {
add_post_meta($post_id,'eventdate',date('Y-m-d',strtotime($event['data'])));
if (isset($event['data_koniec'])) {
$data_koniec=$event['data_koniec'];
} else {
$data_koniec=$event['data'];
}
if (strtotime($data_koniec)post_type=='post') {
// $content=$p->post_content;
// wp_update_post( array( 'ID' => $post_id, 'post_content' => $content ) );
// }
// add_action( 'save_post', 'post_save_postprocessing' );
}
add_action( 'save_post', 'post_save_postprocessing' );
function getDates($year)
{
$dates = array();
date("L", mktime(0,0,0, 7,7, $year)) ? $days = 366 : $days = 365;
for($i = 1; $i <= $days; $i++){
$month = date('m', mktime(0,0,0,1,$i,$year));
$wk = date('W', mktime(0,0,0,1,$i,$year));
$wkDay = date('D', mktime(0,0,0,1,$i,$year));
$day = date('d', mktime(0,0,0,1,$i,$year));
$dates[$month][$wk][$wkDay] = $day;
}
return $dates;
}
function array_msort($array, $cols)
{
$colarr = array();
foreach ($cols as $col => $order) {
$colarr[$col] = array();
foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); }
}
$eval = 'array_multisort(';
foreach ($cols as $col => $order) {
$eval .= '$colarr[\''.$col.'\'],'.$order.',';
}
$eval = substr($eval,0,-1).');';
eval($eval);
$ret = array();
foreach ($colarr as $col => $arr) {
foreach ($arr as $k => $v) {
$k = substr($k,1);
if (!isset($ret[$k])) $ret[$k] = $array[$k];
$ret[$k][$col] = $array[$k][$col];
}
}
return $ret;
}
function flat_title($title) {
$title=str_replace('
'," ",$title);
$title=str_replace('||'," ",$title);
return $title;
}
add_filter('the_title', 'msz_title_filter', 10, 2);
function msz_title_filter($title, $pid=false) {
if (!$pid) return $title;
if (!is_admin()) {
if (!$title) $title="BEZ TYTUŁU";
$title=str_replace('||','
',$title);
if (get_post_type($pid)=='ludzie') return msz_format_autor($title);
}
return sierotki($title);
}
add_filter('the_content', 'msz_content_filter', 10, 2);
function msz_content_filter($txt, $pid=false) {
if (!is_admin()) {
$txt=sierotki($txt);
}
return $txt;
}
function msz_format_autor($autor) {
// zmienia kowalski, jan na jan kowalski
$autor=explode(',',$autor);
if (count($autor)>1) {
return trim($autor[1]).' '.trim($autor[0]);
} else {
return implode(' ',$autor);
}
}
function msz_lead($sierotki=true) {
global $post;
$l=get_field('lead',$post->ID); if ($l) return $l;
$l=get_field('meta_description_seo',$post->ID); if($l) return $l;
$l=truncate(strip_tags(apply_filters('the_content',$post->post_content)),140);
if ($sierotki) return sierotki($l);
return $l;
}
add_action('wp-less_init', function($WPLess) {
$WPLess->getCompiler()->setFormatter('compressed');
} );
function dateV($format,$timestamp=null){
$to_convert = array(
'l'=>array('dat'=>'N','str'=>array('Poniedziałek','Wtorek','Środa','Czwartek','Piątek','Sobota','Niedziela')),
'F'=>array('dat'=>'n','str'=>array('styczeń','luty','marzec','kwiecień','maj','czerwiec','lipiec','sierpień','wrzesień','październik','listopad','grudzień')),
'f'=>array('dat'=>'n','str'=>array('stycznia','lutego','marca','kwietnia','maja','czerwca','lipca','sierpnia','września','października','listopada','grudnia'))
);
if ($pieces = preg_split('#[:/.\-, ]#', $format)){
if ($timestamp === null) { $timestamp = time(); }
foreach ($pieces as $datepart){
if (array_key_exists($datepart,$to_convert)){
$replace[] = $to_convert[$datepart]['str'][(date($to_convert[$datepart]['dat'],$timestamp)-1)];
}else{
$replace[] = date($datepart,$timestamp);
}
}
$result = strtr($format,array_combine($pieces,$replace));
return $result;
}
}
add_filter('post_gallery','customFormatGallery',10,2);
function customFormatGallery($string,$attr){
// wszystkie obrazki dostają takie proporcje jak pierwszy w galerii
// [columns] => 2 [ids] => 28237,28236,28235,28234 [orderby] => post__in [include] => 28237,28236,28235,28234 )
if (!isset($attr['ids'])) return false;
$ids=explode(',',$attr['ids']);
if (!isset($attr['columns'])) $attr['columns']=3;
ob_start();
?>
// $posts = get_posts(array('include' => $attr['ids'],'post_type' => 'attachment'));
// foreach($posts as $nr=>$imagePost) {
foreach ($ids as $nr=>$id) {
$imagePost=get_post($id);
// if (is_user_logged_in()) mszdebug($imagePost);
$tn=wp_get_attachment_image_src($imagePost->ID,'postlink');
$pix=wp_get_attachment_image_src($imagePost->ID, wp_is_mobile() ? 'large' : 'large');
if ($nr==0) $pix0=$pix;
?>
WordPress › Błąd