PluginProbe
Redirection / 2.2.13
Redirection v2.2.13
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / models / monitor.php

monitor.php in Redirection 2.2.13, at models/monitor.php

61 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Red_Monitor {
4 var $monitor_post;
5
6 function Red_Monitor( $options ) {
7 if ( $options['monitor_post'] > 0 ) {
8 $this->monitor_post = $options['monitor_post'];
9
10 // Only monitor if permalinks enabled
11 if ( get_option( 'permalink_structure' ) ) {
12 add_action( 'post_updated', array( &$this, 'post_updated' ), 11, 3 );
13 add_action( 'delete_post', array( &$this, 'post_deleted' ) );
14 add_action( 'edit_form_advanced', array( &$this, 'insert_old_post' ) );
15 add_action( 'edit_page_form', array( &$this, 'insert_old_post' ) );
16 }
17 }
18 }
19
20 function insert_old_post() {
21 global $post;
22
23 $url = parse_url( get_permalink() );
24 $url = $url['path'];
25 ?>
26 <input type="hidden" name="redirection_slug" value="<?php echo esc_attr( $url ) ?>"/>
27 <?php
28 }
29
30 function post_updated( $post_id, $post, $post_before ) {
31 if ( isset( $_POST['redirection_slug'] ) ) {
32 $after = parse_url( get_permalink( $post_id ) );
33 $after = $after['path'];
34 $before = esc_url( $_POST['redirection_slug'] );
35 $site = parse_url( get_site_url() );
36
37 if ( in_array( $post->post_status, array( 'publish', 'static' ) ) && $before != $after && $before != '/' && $before != $site['path'].'/' ) {
38 Red_Item::create( array(
39 'source' => $before,
40 'target' => $after,
41 'match' => 'url',
42 'red_action' => 'url',
43 'group' => $this->monitor_post
44 ) );
45 }
46 }
47 }
48
49 function post_deleted ($id)
50 {
51 $post = get_post ($id);
52 if ($post->post_status == 'publish' || $post->post_status == 'static')
53 {
54 $url = get_permalink ($id);
55 $slug = parse_url ($url);
56
57 // Red_Item::create (array ('source' => $slug['path'], 'target' => '', 'match' => 'url', 'red_action' => 'error', 'group' => $this->monitor_post, 'action_code' => 410));
58 }
59 }
60 }
61