| Server IP : 65.109.86.83 / Your IP : 216.73.216.241 Web Server : nginx/1.14.1 System : Linux libra 4.18.0-553.51.1.el8_10.x86_64 #1 SMP Wed Apr 30 20:24:04 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.31 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,parse_ini_file,show_source MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/html/wp-content/plugins/redirection/models/importer/ |
Upload File : |
<?php
/**
* @phpstan-import-type ImporterInfo from Red_Plugin_Importer
*/
class Red_SeoRedirection_Importer extends Red_Plugin_Importer {
/**
* Import redirects from SEO Redirection.
*
* @param int $group_id Target group ID.
* @return int Number of imported redirects.
*/
public function import_plugin( $group_id ) {
global $wpdb;
if ( defined( 'REDIRECTION_TESTS' ) && REDIRECTION_TESTS ) {
return 0;
}
$count = 0;
$redirects = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}WP_SEO_Redirection" );
foreach ( $redirects as $redirect ) {
$item = $this->create_for_item( $group_id, $redirect );
if ( $item instanceof Red_Item ) {
$count++;
}
}
return $count;
}
/**
* Create a Redirection item for an SEO Redirection row.
*
* @param int $group_id Target group ID.
* @param stdClass $seo Row from WP_SEO_Redirection.
* @return Red_Item|WP_Error|false Created redirect, error, or false if disabled.
*/
private function create_for_item( $group_id, $seo ) {
if ( intval( $seo->enabled, 10 ) === 0 ) {
return false;
}
$data = array(
'url' => $seo->regex ? $seo->regex : $seo->redirect_from,
'action_data' => array( 'url' => $seo->redirect_to ),
'regex' => $seo->regex ? true : false,
'group_id' => $group_id,
'match_type' => 'url',
'action_type' => 'url',
'action_code' => intval( $seo->redirect_type, 10 ),
);
return Red_Item::create( $data );
}
/**
* Get importer summary for SEO Redirection.
*
* @return ImporterInfo|false
*/
public function get_data() {
global $wpdb;
$plugins = get_option( 'active_plugins', array() );
$found = false;
foreach ( $plugins as $plugin ) {
if ( strpos( $plugin, 'seo-redirection.php' ) !== false ) {
$found = true;
break;
}
}
if ( $found ) {
$total = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}WP_SEO_Redirection" );
return array(
'id' => 'seo-redirection',
'name' => 'SEO Redirection',
'total' => $total,
);
}
return false;
}
}