Untitled
unknown
php
3 years ago
6.6 kB
12
Indexable
if (isset($_POST['new_post']) == '1') {
$post_title = $_POST['nome'];
$post_category = $_POST['categoria'];
$post_content = $_POST['descritivo'];
$post_telefone = $_POST['telefone'];
$post_estado = $_POST['estado'];
$post_municipio = $_POST['municipio'];
$post_tag = $_POST['orderName'];
$post_status;
$telefone = 'field_63e6507ecd392';
$estado = 'field_63e6723f0e842';
$municipio = 'field_63e672450e843';
$new_post = array(
'ID' => '',
'post_category' => array($post_category),
'post_content' => $post_content,
'post_title' => $post_title,
'post_status' => 'publish',
'tags_input' => $post_tag,
);
$post_id = wp_insert_post($new_post);
update_field( $telefone, $post_telefone, $post_id );
update_field( $estado, $post_estado, $post_id );
update_field( $municipio, $post_municipio, $post_id );
/*Função para envio de foto*/
$uploaddir = wp_upload_dir();
$file = $_FILES['foto'];
// $files = $_FILES['galeria'];
$uploadfile = $uploaddir['path'] . '/' . basename($file['name']);
move_uploaded_file($file['tmp_name'], $uploadfile);
$filename = basename($uploadfile);
$wp_filetype = wp_check_filetype(basename($filename), null);
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', $filename),
'post_content' => '',
'post_status' => 'inherit',
);
$attach_id = wp_insert_attachment($attachment, $uploadfile);
set_post_thumbnail( $post_id, $attach_id );
wp_redirect(get_permalink($post_id));
if($post_tag == 'Plano Gold') {
global $wpdb;
$wpdb->insert("wpx0_highlights", array(
"object_id" => $post_id,
));
}
exit();
}
if (isset($_POST['edit_post']) == '1') {
$post_title = $_POST['nome'];
$post_category = $_POST['categoria'];
$post_content = $_POST['descritivo'];
$post_telefone = $_POST['telefone'];
$post_estado = $_POST['estado'];
$post_municipio = $_POST['municipio'];
$post_id = $_POST['post_id'];
$telefone = 'field_63e6507ecd392';
$estado = 'field_63e6723f0e842';
$municipio = 'field_63e672450e843';
$edit_post = array(
'ID' => $post_id,
'post_category' => array($post_category),
'post_content' => $post_content,
'post_title' => $post_title,
'post_status' => 'publish',
);
wp_update_post( $edit_post );
update_field( $telefone, $post_telefone, $post_id );
update_field( $estado, $post_estado, $post_id );
update_field( $municipio, $post_municipio, $post_id );
/*Função para envio de foto*/
$uploaddir = wp_upload_dir();
$file = $_FILES['foto'];
// $files = $_FILES['galeria'];
$uploadfile = $uploaddir['path'] . '/' . basename($file['name']);
move_uploaded_file($file['tmp_name'], $uploadfile);
$filename = basename($uploadfile);
$wp_filetype = wp_check_filetype(basename($filename), null);
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', $filename),
'post_content' => '',
'post_status' => 'inherit',
);
$attach_id = wp_insert_attachment($attachment, $uploadfile);
set_post_thumbnail( $post_id, $attach_id );
exit();
}
function has_bought( $value = 0 ) {
if ( ! is_user_logged_in() && $value === 0 ) {
return false;
}
global $wpdb;
// Based on user ID (registered users)
if ( is_numeric( $value) ) {
$meta_key = '_customer_user';
$meta_value = $value == 0 ? (int) get_current_user_id() : (int) $value;
}
// Based on billing email (Guest users)
else {
$meta_key = '_billing_email';
$meta_value = sanitize_email( $value );
}
$paid_order_statuses = array_map( 'esc_sql', wc_get_is_paid_statuses() );
$count = $wpdb->get_var( $wpdb->prepare("
SELECT COUNT(p.ID) FROM {$wpdb->prefix}posts AS p
INNER JOIN {$wpdb->prefix}postmeta AS pm ON p.ID = pm.post_id
WHERE p.post_status IN ( 'wc-" . implode( "','wc-", $paid_order_statuses ) . "' )
AND p.post_type LIKE 'shop_order'
AND pm.meta_key = '%s'
AND pm.meta_value = %s
LIMIT 1
", $meta_key, $meta_value ) );
// Return a boolean value based on orders count
return $count > 0;
}
function get_first_highlight() {
global $wpdb;
return $wpdb->get_results("
SELECT wp.* FROM `wpx0_highlights` wp ORDER BY wp.id ASC limit 1
");
}
function change_last_highlight() {
global $wpdb;
$result = get_first_highlight()[0];
$wpdb->delete("wpx0_highlights", [
"id" => $result->id
]);
$wpdb->insert("wpx0_highlights", array(
"object_id" => $result->object_id,
));
}
add_action('update_news_date', 'update_news_date_func');
function update_news_date_func() {
global $wpdb;
$results = $wpdb->get_results("
SELECT wp.*, wt.name FROM `wpx0_posts` wp INNER JOIN wpx0_term_relationships wtr ON wtr.object_id = wp.ID INNER JOIN wpx0_terms wt ON wt.term_id = wtr.term_taxonomy_id WHERE post_type = 'post' AND (wt.slug = 'plano-gold' AND hour(timediff(now(), post_date)) BETWEEN 6 AND 7) OR (wt.slug = 'plano-silver' AND hour(timediff(now(), post_date)) BETWEEN 8 AND 9)");
foreach($results as $result) {
$wpdb->update("wpx0_posts", ["post_date" => current_datetime()->date], ["ID" => $result->ID]);
}
change_last_highlight();
}
if(!is_user_logged_in()) {
echo "<script>window.onload = function() {
if(document.body.contains(document.querySelector('.button.header-button.button-size-medium.button-style-filled'))) {
document.querySelector('.button.header-button.button-size-medium.button-style-filled').setAttribute('href', 'https://pointmodel.com.br/linkprovisorio/minha-conta/');
}
}</script>";
} else {
if( has_bought() ):
echo "<script>window.onload = function() {
if(document.body.contains(document.querySelector('.button.header-button.button-size-medium.button-style-filled'))) {
document.querySelector('.button.header-button.button-size-medium.button-style-filled').setAttribute('href', 'https://pointmodel.com.br/linkprovisorio/crie-seu-point/');
}
}</script>";
endif;
}Editor is loading...