| Server IP : 65.109.86.83 / Your IP : 37.27.51.148 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_PrettyLinks_Importer extends Red_Plugin_Importer {
/**
* Import redirects from Pretty Links.
*
* @param int $group_id Target group ID.
* @return int Number of imported redirects.
*/
public function import_plugin( $group_id ) {
global $wpdb;
$count = 0;
$redirects = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}prli_links" );
foreach ( $redirects as $redirect ) {
$created = $this->create_for_item( $group_id, $redirect );
if ( $created instanceof Red_Item ) {
$count++;
}
}
return $count;
}
/**
* Create a Redirection item for a Pretty Links row.
*
* @param int $group_id Target group ID.
* @param stdClass $link Row from prli_links.
* @return Red_Item|WP_Error Created redirect or error.
*/
private function create_for_item( $group_id, $link ) {
$item = array(
'url' => '/' . $link->slug,
'action_data' => array( 'url' => $link->url ),
'regex' => false,
'group_id' => $group_id,
'match_type' => 'url',
'action_type' => 'url',
'title' => $link->name,
'action_code' => $link->redirect_type,
);
return Red_Item::create( $item );
}
/**
* Get importer summary for Pretty Links.
*
* @return ImporterInfo|false
*/
public function get_data() {
$data = get_option( 'prli_db_version' );
if ( $data !== false ) {
global $wpdb;
return [
'id' => 'pretty-links',
'name' => 'PrettyLinks',
'total' => (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}prli_links" ),
];
}
return false;
}
}