Sindbad~EG File Manager

Current Path : /home/xiedrke/entrepot/wp-content/plugins/realpress/app/Controllers/
Upload File :
Current File : /home/xiedrke/entrepot/wp-content/plugins/realpress/app/Controllers/PermalinkController.php

<?php

namespace RealPress\Controllers;

use RealPress\Helpers\Settings;
use RealPress\Models\UserModel;

class PermalinkController {

	public function __construct() {
		add_filter( 'author_link', array( $this, 'change_author_link' ), 9999, 2 );
		add_filter( 'author_rewrite_rules', array( $this, 'author_rewrite_rules' ) );
		add_filter( 'realpress/filter/config/post_types', array( $this, 'change_property_slug' ) );
		add_filter( 'realpress/filter/config/taxonomies', array( $this, 'change_taxonomies_slug' ) );
	}

	/**
	 * @param $link
	 * @param $user_id
	 *
	 * @return array|mixed|string|string[]
	 */
	public function change_author_link( $link, $user_id ) {
		$roles = UserModel::get_field( $user_id, 'roles' );
		$slug  = Settings::get_agent_slug();
		if ( empty( $slug ) ) {
			$link;
		}

		if ( is_array( $roles ) && in_array( REALPRESS_AGENT_ROLE, $roles ) ) {
			global $wp_rewrite;
			$link = str_replace( $wp_rewrite->author_base, $slug, $link );
		}

		return $link;
	}

	/**
	 * @return void
	 */
	public function author_rewrite_rules( $author_rewrite ) {
		$slug = Settings::get_agent_slug();
		if ( empty( $slug ) ) {
			return;
		}
		$regex                    = $slug . '/([^/]+)/?$';
		$author_rewrite[ $regex ] = 'index.php?author_name=$matches[1]';

		return $author_rewrite;
	}

	/**
	 * @param $config
	 *
	 * @return array
	 */
	public function change_property_slug( $config ) {
		$config[ REALPRESS_PROPERTY_CPT ]['rewrite']['slug'] = Settings::get_setting_detail( 'group:slug:fields:property' );

		return $config;
	}

	/**
	 * @param $taxonomies
	 *
	 * @return array
	 */
	public function change_taxonomies_slug( $taxonomies ) {
		foreach ( $taxonomies as $name => $args ) {
			$taxonomies[ $name ]['rewrite']['slug'] = Settings::get_setting_detail( 'group:slug:fields:' . $name );
		}

		return $taxonomies;
	}
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists