php - Attach middleware to specific existing route -
is there way attach middleware specific route in wordpress or in php? i'd run middleware function before allowing access uploads folder check if user has access file before allowing them download it.
i come background in node.js/express if helps i'd this:
app.use('/wp-content/uploads', function(req, res, next) { // stuff req , call next continue, // or use res end request early. });
there various wordpress plugins restricting access content or downloads, based on logic of been registered or not , privileges user has.
basic logic behind them :
// redirect guests function guest_redirect() { $guest_routes = array( 'member-login', 'member-account', 'member-register', 'member-password-lost', 'member-password-reset' ); // force login or registration if ( !is_user_logged_in() && !is_page($guest_routes) ) { wp_redirect( 'member-login' ); exit; } } add_action( 'template_redirect', 'guest_redirect' ); also, wordpress has rest api (official doc here need). however, using own custom thing production site using rest api without testing can risky , complicated use.
Comments
Post a Comment