Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////DODAWANIE PLIK PHP//////////////////////////////////
- <article id="post-<?php the_ID(); ?>" <?php post_class('entry clearfix'); ?> role="article">
- <div class="post_content clearfix">
- <?php
- $options = array(
- 'post_id' => 'rand()', // post id to get field groups from and save data to
- 'field_groups' => array( 27 ), // this will find the field groups for this post (post ID's of the acf post objects)
- 'form' => true, // set this to false to prevent the <form> tag from being created
- 'form_attributes' => array( // attributes will be added to the form element
- 'id' => 'post',
- 'class' => '',
- 'action' => '',
- 'method' => 'post',
- ),
- 'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
- 'html_before_fields' => '', // html inside form before fields
- 'html_after_fields' => '', // html inside form after fields
- 'submit_value' => 'Wyślij', // value for submit field
- 'updated_message' => 'Wpis został dodany prawidłowo.', // default updated message. Can be false to show no message
- );
- //Sprawdzenie id zalogowanego użytkownika
- if ( is_user_logged_in() ) {
- $user_ID = get_current_user_id();
- //Funckja licząca statusy wpisów.
- global $wp_query;
- $curauth = $user_ID;
- $post_count_draft = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '" . $curauth . "' AND post_type = 'post' AND post_status = 'draft'");
- $post_count_publish = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '" . $curauth . "' AND post_type = 'post' AND post_status = 'publish'");
- //Jeśli więcej niż 1 wpis, zakaż dodawania więcej.
- if (($post_count_draft > 0) OR ($post_count_publish > 0)) {
- echo '<h2 class="notice">Wpis został dodany prawidłowo.</h2>';
- echo '<h2 class="notice">Możesz tylko dodać jeden wpis, wróć na stronę główną.</h2>';
- }
- else {
- acf_form( $options );
- }
- }
- else {
- echo '<h2 class="warning">Tylko dla zalogowanych użytkowników.</h2>';
- echo wp_login_form();
- echo wp_register('', '');
- }
- ?>
- </div> <!-- end .post_content -->
- </article> <!-- end .entry -->
- //////////////////////////////////PLIK Z FUNKCJĄ PHP//////////////////////////////////
- if ( function_exists( 'add_image_size' ) )
- add_theme_support( 'post-thumbnails' );
- if ( function_exists( 'add_image_size' ) ) {
- add_image_size( 'galeria1', 9999, 630, false );
- }
- if ( function_exists( 'add_image_size' ) ) {
- add_image_size( 'okladka', 630, 210, false );
- }
- function add_new_post( $post_id )
- {
- if( $post_id == 'rand()' ) {
- // Create a new post
- $post = array(
- 'post_title' => $_POST["fields"]['field_52e8ce62f6982'],
- 'post_status' => 'draft',
- 'post_category' => array(6),
- 'post_type' => 'post'
- );
- // insert the post
- $post_id = wp_insert_post( $post );
- return $post_id;
- }
- }
- add_filter('acf/pre_save_post' , 'add_new_post' );
- function acf_set_featured_image( $value, $post_id, $field ){
- // echo '<pre>'. print_r($value,1).'<br/>'.print_r($_POST,1).'</pre>'; die();
- if($value != ''){
- //Add the value which is the image ID to the _thumbnail_id meta data for the current post
- add_post_meta($post_id, '_thumbnail_id', $value);
- }
- return $value;
- }
- // acf/update_value/name={$field_name} - filter for a specific field based on it's name
- add_filter('acf/update_value/name=zdjecie1', 'acf_set_featured_image', 10, 3);
- function acf_set_miejsce( $value, $post_id, $field ){
- // echo '<pre>'. print_r($value,1).'<br/>'.print_r($field,1).'</pre>'; die();
- if($value['address'] != ''){
- //Add the value which is the image ID to the _thumbnail_id meta data for the current post
- add_post_meta($post_id, 'codespacing_progress_map_address', $value['address']);
- }
- if($value['lat'] != ''){
- //Add the value which is the image ID to the _thumbnail_id meta data for the current post
- add_post_meta($post_id, 'codespacing_progress_map_lat', $value['lat']);
- }
- if($value['lng'] != ''){
- //Add the value which is the image ID to the _thumbnail_id meta data for the current post
- add_post_meta($post_id, 'codespacing_progress_map_lng', $value['lng']);
- }
- return $value;
- }
- // acf/update_value/name={$field_name} - filter for a specific field based on it's name
- add_filter('acf/update_value/name=miejsce_kradziezy', 'acf_set_miejsce', 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement