Advertisement
Guest User

Untitled

a guest
Feb 14th, 2014
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.72 KB | None | 0 0
  1. //////////////////////////////////DODAWANIE PLIK PHP//////////////////////////////////
  2.  
  3.         <article id="post-<?php the_ID(); ?>" <?php post_class('entry clearfix'); ?> role="article">
  4.             <div class="post_content clearfix">
  5.  
  6.                         <?php
  7.                         $options = array(
  8.                             'post_id' => 'rand()', // post id to get field groups from and save data to
  9.                             'field_groups' => array( 27 ), // this will find the field groups for this post (post ID's of the acf post objects)
  10.                             'form' => true, // set this to false to prevent the <form> tag from being created
  11.                             'form_attributes' => array( // attributes will be added to the form element
  12.                                 'id' => 'post',
  13.                                 'class' => '',
  14.                                 'action' => '',
  15.                                 'method' => 'post',
  16.                             ),
  17.                             'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
  18.                             'html_before_fields' => '', // html inside form before fields
  19.                             'html_after_fields' => '', // html inside form after fields
  20.                             'submit_value' => 'Wyślij', // value for submit field
  21.                             'updated_message' => 'Wpis został dodany prawidłowo.', // default updated message. Can be false to show no message
  22.                         );
  23.                         //Sprawdzenie id zalogowanego użytkownika
  24.                         if ( is_user_logged_in() ) {
  25.                             $user_ID = get_current_user_id();
  26.                             //Funckja licząca statusy wpisów.
  27.                             global $wp_query;
  28.                             $curauth = $user_ID;
  29.                             $post_count_draft = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '" . $curauth . "' AND post_type = 'post' AND post_status = 'draft'");
  30.                             $post_count_publish = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '" . $curauth . "' AND post_type = 'post' AND post_status = 'publish'");
  31.                             //Jeśli więcej niż 1 wpis, zakaż dodawania więcej.
  32.                             if (($post_count_draft > 0) OR ($post_count_publish > 0)) {
  33.                                 echo '<h2 class="notice">Wpis został dodany prawidłowo.</h2>';
  34.                                 echo '<h2 class="notice">Możesz tylko dodać jeden wpis, wróć na stronę główną.</h2>';
  35.                             }
  36.                             else {
  37.                                 acf_form( $options );
  38.                             }
  39.                         }
  40.                         else {
  41.                             echo '<h2 class="warning">Tylko dla zalogowanych użytkowników.</h2>';
  42.                             echo wp_login_form();
  43.                             echo wp_register('', '');
  44.                         }
  45.                         ?>
  46.         </div>  <!-- end .post_content -->
  47.     </article> <!-- end .entry -->
  48.  
  49.  
  50.  
  51.  
  52. //////////////////////////////////PLIK Z FUNKCJĄ PHP//////////////////////////////////
  53.  
  54.  
  55. if ( function_exists( 'add_image_size' ) )
  56.     add_theme_support( 'post-thumbnails' );
  57.  
  58. if ( function_exists( 'add_image_size' ) ) {
  59.     add_image_size( 'galeria1', 9999, 630, false );
  60. }
  61.  
  62. if ( function_exists( 'add_image_size' ) ) {
  63.     add_image_size( 'okladka', 630, 210, false );
  64. }
  65.    
  66. function add_new_post( $post_id )
  67. {
  68.     if( $post_id == 'rand()' ) {
  69.         // Create a new post
  70.         $post = array(
  71.             'post_title' => $_POST["fields"]['field_52e8ce62f6982'],
  72.             'post_status'  => 'draft',
  73.             'post_category' => array(6),
  74.             'post_type'  => 'post'
  75.         );
  76.  
  77.         // insert the post
  78.         $post_id = wp_insert_post( $post );
  79.  
  80.         return $post_id;
  81.  
  82.     }
  83. }
  84. add_filter('acf/pre_save_post' , 'add_new_post' );
  85.    
  86.    
  87.    
  88. function acf_set_featured_image( $value, $post_id, $field  ){
  89. //    echo '<pre>'. print_r($value,1).'<br/>'.print_r($_POST,1).'</pre>'; die();
  90.     if($value != ''){
  91.         //Add the value which is the image ID to the _thumbnail_id meta data for the current post
  92.         add_post_meta($post_id, '_thumbnail_id', $value);
  93.     }
  94.  
  95.     return $value;
  96. }
  97. // acf/update_value/name={$field_name} - filter for a specific field based on it's name
  98. add_filter('acf/update_value/name=zdjecie1', 'acf_set_featured_image', 10, 3);
  99.  
  100.  
  101.  
  102. function acf_set_miejsce( $value, $post_id, $field  ){
  103.    // echo '<pre>'. print_r($value,1).'<br/>'.print_r($field,1).'</pre>'; die();
  104.     if($value['address'] != ''){
  105.         //Add the value which is the image ID to the _thumbnail_id meta data for the current post
  106.         add_post_meta($post_id, 'codespacing_progress_map_address', $value['address']);
  107.     }
  108.      if($value['lat'] != ''){
  109.         //Add the value which is the image ID to the _thumbnail_id meta data for the current post
  110.         add_post_meta($post_id, 'codespacing_progress_map_lat', $value['lat']);
  111.        
  112.     }
  113.      if($value['lng'] != ''){
  114.         //Add the value which is the image ID to the _thumbnail_id meta data for the current post
  115.         add_post_meta($post_id, 'codespacing_progress_map_lng', $value['lng']);
  116.     }
  117.     return $value;
  118. }
  119. // acf/update_value/name={$field_name} - filter for a specific field based on it's name
  120. add_filter('acf/update_value/name=miejsce_kradziezy', 'acf_set_miejsce', 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement