1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
<?php
namespace SIW\Batch;
use SIW\Util;
class Update_SEO_Noindex extends Job {
protected $action = 'update_seo_noindex';
protected $name = 'bijwerken SEO noindex';
protected $category = 'algemeen';
protected function select_data() {
$post_types = [
'vacatures',
'agenda',
'product'
];
$data = get_posts(
[
'post_type' => $post_types,
'fields' => 'ids',
'posts_per_page' => -1,
]
);
return $data;
}
protected function task( $post_id ) {
if ( ! Util::post_exists( $post_id ) ) {
return false;
}
$current_noindex = $this->get_noindex( $post_id );
$post_type = get_post_type( $post_id );
switch ( $post_type ) {
case 'vacatures':
$deadline = date( 'Y-m-d', get_post_meta( $post_id, 'siw_vacature_deadline', true ) );
$new_noindex = date( 'Y-m-d' ) > $deadline;
break;
case 'agenda':
$event_end = date( 'Y-m-d', get_post_meta( $post_id, 'siw_agenda_eind', true ) );
$new_noindex = date( 'Y-m-d' ) > $event_end;
break;
case 'product':
$product = wc_get_product( $post_id );
$new_noindex = ! $product->is_visible();
break;
default:
return false;
}
if ( $current_noindex != $new_noindex ) {
$this->set_noindex( $post_id, $new_noindex );
$this->increment_processed_count();
}
return false;
}
protected function get_noindex( int $post_id ) {
return (bool) get_post_meta( $post_id, '_genesis_noindex', true );
}
protected function set_noindex( int $post_id, bool $value = false ) {
$noindex = $value ? 1 : 0;
update_post_meta( $post_id, '_genesis_noindex', $noindex );
}
}