Last active
August 22, 2019 19:11
-
-
Save eto4detak/db7ac42ae0d9c169a371913d5cc1ef6f to your computer and use it in GitHub Desktop.
wp php code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// добавить к запросу | |
function devise_number_displayed_posts($query) { | |
if (is_admin() || !$query->is_main_query()) { | |
return; | |
} | |
if (is_tax('category-catalogs')) { | |
$query->set('posts_per_page', 16); | |
return; | |
} | |
if (is_tax('product_cat')) { | |
$screen_width = isset($_COOKIE['screen_width']) ? $_COOKIE['screen_width'] : ''; | |
$term_array=get_queried_object(); | |
$br_col = art_get_term_br_col($term_array->term_id); | |
if (!empty($br_col[0]) && empty($br_col[1])){ | |
$count = art_get_count_row_page($screen_width, '_row_brand_'); | |
if(!empty($count)){ | |
$query->set('posts_per_page', $count); | |
} | |
return; | |
} | |
elseif(!empty($br_col[0]) && !empty($br_col[1])){ | |
$count = art_get_count_row_page($screen_width, '_row_group_'); | |
if(!empty($count)){ | |
$query->set('posts_per_page', $count); | |
} | |
return; | |
} | |
if($screen_width){ | |
$count = art_get_count_row_page($screen_width); | |
if(!empty($count)){ | |
$query->set('posts_per_page', $count); | |
return; | |
} | |
} | |
} | |
if(is_category()){ | |
$screen_width = isset($_COOKIE['screen_width']) ? $_COOKIE['screen_width'] : ''; | |
$count = art_get_count_row_cat($screen_width); | |
if(!empty($count)){ | |
$query->set('posts_per_page', $count); | |
return; | |
} | |
} | |
} | |
add_action('pre_get_posts', 'devise_number_displayed_posts', 1); | |
////////////////////////////post//////////////////////////// | |
$args = array( | |
'post_type' => array( 'post',), | |
'posts_per_page' => 12, | |
); | |
$the_query = new WP_Query( $args ); | |
// The Loop | |
global $post; | |
if ( $the_query->have_posts() ) : | |
while ( $the_query->have_posts() ) : $the_query->the_post();?> | |
<li class="col-lg-3 col-md-4 col-xs-6 col"> | |
<div class="img-centered"> | |
<?php the_post_thumbnail('medium'); ?> | |
</div> | |
<div class="sobitiya-rubrik"> | |
<?php | |
foreach( get_the_category() as $category ){ | |
echo '<a href="' . get_term_link( $category->cat_ID ) . '" class="btn small red">'. $category->cat_name . '</a>'; | |
} | |
?> | |
</div> | |
<div class="sobitiya-caption"> | |
<div class="date"><?php echo $post->post_date; ?></div> | |
<div class="h2"><a href="<?php echo get_permalink( $post->ID ); ?>"><?php echo $post->post_title; ?></a></div> | |
</div> | |
</li> | |
<?php | |
endwhile; | |
endif; | |
wp_reset_postdata(); | |
/*======================================================== | |
* register_sidebar | |
========================================================*/ | |
register_sidebar( array( | |
'name' => "Sidebar add question", | |
'id' => 'add_question-sidebar', | |
'description' => 'Эти виджеты будут показаны на странице задать вопрос', | |
'before_widget' => '<div id="%1$s" class="widget %2$s">', | |
'after_widget' => '</div>', | |
'before_title' => '<h3 class="widget_title">', | |
'after_title' => '</h3>' | |
) ); | |
/*======================================================== | |
* filter | |
========================================================*/ | |
$posted = array( | |
'user_name' => esc_html($_POST['user_name']), | |
'email' => esc_html($_POST['email']), | |
'pass1' => esc_html($_POST['pass1']), | |
'pass2' => esc_html($_POST['pass2']), | |
'redirect_to' => esc_url($_POST['redirect_to']), | |
'ask_captcha' => (isset($_POST['ask_captcha']) && $_POST['ask_captcha'] != ""?esc_html($_POST['ask_captcha']):""), | |
'country' => (isset($_POST['country']) && $_POST['country'] != ""?esc_html($_POST['country']):""), | |
'city' => (isset($_POST['city']) && $_POST['city'] != ""?esc_html($_POST['city']):""), | |
'age' => (isset($_POST['age']) && $_POST['age'] != ""?esc_html($_POST['age']):""), | |
'phone' => (isset($_POST['phone']) && $_POST['phone'] != ""?esc_html($_POST['phone']):""), | |
'sex' => (isset($_POST['sex']) && $_POST['sex'] != ""?esc_html($_POST['sex']):""), | |
'first_name' => (isset($_POST['first_name']) && $_POST['first_name'] != ""?esc_html($_POST['first_name']):""), | |
'last_name' => (isset($_POST['last_name']) && $_POST['last_name'] != ""?esc_html($_POST['last_name']):""), | |
'display_name' => (isset($_POST['display_name']) && $_POST['display_name'] != ""?esc_html($_POST['display_name']):""), | |
'agree_terms' => (isset($_POST['agree_terms']) && $_POST['agree_terms'] != ""?esc_html($_POST['agree_terms']):""), | |
'agree_terms' => (isset($_POST['agree_terms']) && $_POST['agree_terms'] != ""?esc_html($_POST['agree_terms']):""), | |
'agree_terms' => (isset($_POST['agree_terms']) && $_POST['agree_terms'] != ""?esc_html($_POST['agree_terms']):""), | |
); | |
function add_extra_social_links( $user ){ ?> | |
<h3>Дополнительные данные пользователя</h3> | |
<table class="form-table"> | |
<tr> | |
<th><label for="adress_prof">АДРЕС</label></th> | |
<td><input type="text" name="adress_prof" value="<?php echo esc_attr(get_the_author_meta( 'adress_prof', $user->ID )); ?>" class="regular-text" /></td> | |
</tr> | |
<tr> | |
<th><label for="email_prof">КОНТАКТЫ (Email)</label></th> | |
<td><input type="text" name="email_prof" value="<?php echo esc_attr(get_the_author_meta( 'email_prof', $user->ID )); ?>" class="regular-text" /> | |
<input type="text" name="email_prof2" value="<?php echo esc_attr(get_the_author_meta( 'email_prof2', $user->ID )); ?>" class="regular-text" /></td> | |
</tr> | |
<tr> | |
<th><label for="tel_prof">Технический одел и сервис (тел:.)</label></th> | |
<td><input type="text" name="tel_prof" value="<?php echo esc_attr(get_the_author_meta( 'tel_prof', $user->ID )); ?>" class="regular-text" /> | |
<input type="text" name="tel_prof2" value="<?php echo esc_attr(get_the_author_meta( 'tel_prof2', $user->ID )); ?>" class="regular-text" /></td> | |
</tr> | |
<tr> | |
<th><label for="tel_prof_zap">Отдел запчастей (тел:.)</label></th> | |
<td><input type="text" name="tel_prof_zap" value="<?php echo esc_attr(get_the_author_meta( 'tel_prof_zap', $user->ID )); ?>" class="regular-text" /></td> | |
</tr> | |
</table> | |
<?php | |
} | |
/*======================================================== | |
* author | |
========================================================*/ | |
add_action( 'personal_options_update', 'my_save_extra_profile_fields' ); | |
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' ); | |
function my_save_extra_profile_fields( $user_id ) { | |
if ( !current_user_can( 'edit_user', $user_id ) ) | |
return false; | |
update_usermeta( $user_id, 'twitter', $_POST['twitter'] ); | |
} | |
add_action('show_user_profile', 'my_author_box'); | |
add_action('edit_user_profile', 'my_author_box'); | |
/* display custom profile field */ | |
function my_author_box($user) { ?> | |
<table class="form-table"> | |
<tr> | |
<th><label for="you_avatar"><?php _e("Your avatar","vbegy")?></label></th> | |
<td> | |
<input type="text" size="36" class="upload upload_meta regular-text" value="<?php echo esc_attr( get_the_author_meta('you_avatar', $user->ID ) ); ?>" id="you_avatar" name="you_avatar"> | |
<input id="you_avatar_button" class="upload_image_button button upload-button-2" type="button" value="Upload Image"> | |
</td> | |
</tr> | |
<?php if (get_the_author_meta('you_avatar', $user->ID )) {?> | |
<tr> | |
<th><label><?php _e("Your avatar","vbegy")?></label></th> | |
<td> | |
<div class="you_avatar"><img alt="" src="<?php echo esc_attr( get_the_author_meta('you_avatar', $user->ID ) ); ?>"></div> | |
</td> | |
</tr> | |
<?php } ?> | |
<tr> | |
<th><label for="country"><?php _e("Country","vbegy")?></label></th> | |
<td> | |
<select name="country" id="country"> | |
<option value=""><?php _e( 'Select a country…', 'vbegy' )?></option> | |
<?php foreach( vpanel_get_countries() as $key => $value ) | |
echo '<option value="' . esc_attr( $key ) . '"' . selected( esc_attr( get_the_author_meta( 'country', $user->ID ) ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';?> | |
</select> | |
</td> | |
</tr> | |
<tr> | |
<th><label for="city"><?php _e("City","vbegy")?></label></th> | |
<td> | |
<input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'city', $user->ID ) ); ?>" class="regular-text"><br> | |
</td> | |
</tr> | |
<tr> | |
<th><label for="age"><?php _e("Age","vbegy")?></label></th> | |
<td> | |
<input type="text" name="age" id="age" value="<?php echo esc_attr( get_the_author_meta( 'age', $user->ID ) ); ?>" class="regular-text"><br> | |
</td> | |
</tr> | |
<tr> | |
<th><label for="phone"><?php _e("Phone","vbegy")?></label></th> | |
<td> | |
<input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text"><br> | |
</td> | |
</tr> | |
<tr> | |
<?php | |
$sex = esc_attr(get_the_author_meta( 'sex', $user->ID ) ); | |
?> | |
<th><label><?php _e("Sex","vbegy")?></label></th> | |
<td> | |
<input id="sex_male" name="sex" type="radio" value="1"'<?php echo (isset($sex) && ($sex == "male" || $sex == "1")?' checked="checked"':' checked="checked"')?>'> | |
<label for="sex_male"><?php _e("Male","vbegy")?></label> | |
<input id="sex_female" name="sex" type="radio" value="2"<?php echo (isset($sex) && ($sex == "female" || $sex == "2")?' checked="checked"':'')?>> | |
<label for="sex_female"><?php _e("Female","vbegy")?></label> | |
</td> | |
</tr> | |
<tr> | |
<th><label for="follow_email"><?php _e("Follow-up email","vbegy")?></label></th> | |
<td> | |
<input type="text" name="follow_email" id="follow_email" value="<?php echo esc_attr( get_the_author_meta( 'follow_email', $user->ID ) ); ?>" class="regular-text"><br> | |
</td> | |
</tr> | |
<?php $active_message = vpanel_options("active_message"); | |
if ($active_message == 1) {?> | |
<tr> | |
<?php $received_message = esc_attr( get_the_author_meta( 'received_message', $user->ID ) )?> | |
<th><label for="received_message"><?php _e("Received messages?","vbegy")?></label></th> | |
<td> | |
<input type="checkbox" name="received_message" id="received_message" value="1" <?php checked($received_message,($received_message == ""?"":1),true)?>><br> | |
</td> | |
</tr> | |
<?php } | |
if (is_super_admin(get_current_user_id()) && !is_super_admin($user->ID)) {?> | |
<tr> | |
<?php $block_message = esc_attr( get_the_author_meta( 'block_message', $user->ID ) )?> | |
<th><label for="block_message"><?php _e("block messages?","vbegy")?></label></th> | |
<td> | |
<input type="checkbox" name="block_message" id="block_message" value="1" <?php checked($block_message,1,true)?>><br> | |
</td> | |
</tr> | |
<?php }?> | |
</table> | |
<?php | |
} | |
function view_field($field,$name,$user) | |
{ | |
?> | |
<tr> | |
<th><label for="<?php echo $field; ?>"><?php echo $name;?></label></th> | |
<td> | |
<input type="text" size="36" class="regular-text" value="<?php echo esc_attr( get_the_author_meta("$field", $user->ID ) ); ?>" id="<?php echo $field; ?>" name="<?php echo $field; ?>"> | |
</td> | |
</tr> | |
<?php | |
} | |
/////////////////////////////////////////////////////////////////////////////////////////// | |
/////// notice | |
/////////////////////////////////////////////////////////////////////////////////////////// | |
// предупредить админа о создании нового авто | |
add_action('admin_notices', function(){ | |
$str_ids = get_option('notice_admin_auto'); | |
$html = ''; | |
$url = []; | |
$new_ids = []; | |
$str_new_ids = ''; | |
if(!empty($str_ids)){ | |
$ids = explode(',', $str_ids); | |
if(!empty($ids)){ | |
foreach( $ids as $id ){ | |
$cur_id = (int) $id; | |
if(!empty($cur_id)){ | |
$post = get_post($cur_id); | |
if($post->post_status === 'pending'){ | |
$new_ids[] = $cur_id; | |
echo '<pre class="aaa" style="display:none">'; | |
var_dump($post); | |
echo '</pre>'; | |
$html .= '<li class="notice-admin-pending">'.esc_html(get_the_author_meta('user_nicename', $post->post_author)).' added new car: <a href="'.get_permalink($cur_id).'">'.$post->post_title.'</li></a>'; | |
} | |
} | |
} | |
} | |
} | |
if(!empty($new_ids)){ | |
foreach ($new_ids as $id) { | |
$str_new_ids .= $id . ','; | |
} | |
} | |
update_option('notice_admin_auto', $str_new_ids); | |
if(!empty($html)){ | |
echo '<div class="update-nag"><p>'.esc_attr__('The post waiting for the approval of the administrator', 'autozone').'.</p><ul>'.$html.'</ul></div>'; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment