PluginProbe
Redirection / 2.4.2
Redirection v2.4.2
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.4.2, at models/monitor.php

51 lines 1.5 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 private $monitor_group_id;
5
6 function __construct( $options ) {
7 if ( $options['monitor_post'] > 0 ) {
8 $this->monitor_group_id = intval( $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( 'edit_form_advanced', array( &$this, 'insert_old_post' ) );
14 add_action( 'edit_page_form', array( &$this, 'insert_old_post' ) );
15 }
16 }
17 }
18
19 public function insert_old_post() {
20 global $post;
21
22 $url = parse_url( get_permalink() );
23 $url = $url['path'];
24 ?>
25 <input type="hidden" name="redirection_slug" value="<?php echo esc_attr( $url ) ?>"/>
26 <?php
27 }
28
29 public function post_updated( $post_id, $post, $post_before ) {
30 if ( $post->post_status !== 'publish' || is_post_type_hierarchical( $post->post_type ) )
31 return;
32
33 if ( isset( $_POST['redirection_slug'] ) ) {
34 $after = parse_url( get_permalink( $post_id ) );
35 $after = $after['path'];
36 $before = esc_url( $_POST['redirection_slug'] );
37 $site = parse_url( get_site_url() );
38
39 if ( in_array( $post->post_status, array( 'publish', 'static' ) ) && $before !== $after && $before !== '/' && ( !isset( $site['path'] ) || ( isset( $site['path'] ) && $before !== $site['path'].'/' ) ) ) {
40 Red_Item::create( array(
41 'source' => $before,
42 'target' => $after,
43 'match' => 'url',
44 'red_action' => 'url',
45 'group_id' => $this->monitor_group_id
46 ) );
47 }
48 }
49 }
50 }
51