Example #1
0
    /**
     * Get the mod rewitre rules for Luminous.
     *
     * @uses \Luminous\Bridge\Post\Entities\AttachmentEntity::attachmentPath()
     * @uses \get_stylesheet_directory_uri()
     * @uses \is_child_theme()
     * @uses \wp_upload_dir()
     * @uses \home_url()
     *
     * @return string
     */
    function luminous_mod_rewrite_rules()
    {
        $rewriteBase = parse_url(home_url('/'), PHP_URL_PATH);
        $uploadUrlReal = wp_upload_dir()['baseurl'];
        $uploadUrlBase = AttachmentEntity::attachmentPath($uploadUrlReal);
        $uploadDir = parse_url($uploadUrlReal, PHP_URL_PATH);
        $publicUrlReal = get_stylesheet_directory_uri() . (is_child_theme() ? '/public' : '/luminous-scaffolding/public');
        $publicDirPath = base_path('public');
        $publicDir = parse_url($publicUrlReal, PHP_URL_PATH);
        return <<<EOT
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteBase {$rewriteBase}

    # Redirect Trailing Slashes
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/\$ /\$1 [L,R=301]

    # uploads
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^{$uploadUrlBase}/(.*)\$ {$uploadDir}/\$1 [L]

    # public
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond {$publicDirPath}%{REQUEST_URI} -f
    RewriteRule ^(.*)\$ {$publicDir}/\$1 [L]

    # WordPress
    RewriteRule ^index\\.php\$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . /index.php [L]
</IfModule>
EOT;
    }
Example #2
0
    $draft = isset($post->post_status) && in_array($post->post_status, ['draft', 'pending', 'auto-draft', 'future']);
    if (!$postType->public || $draft) {
        return $permalink;
    }
    $placeholder = $leavename ? "%{$post->post_type}%" : null;
    $parameters = $placeholder ? ['post__path' => $placeholder, 'post__slug' => $placeholder] : [];
    return post_url(app('wp')->post($post), $parameters, true);
}, 10, 3);
// @link https://developer.wordpress.org/reference/functions/get_term_link/
add_filter('term_link', function ($termlink, $term, $taxonomy) {
    $term = app('wp')->term($term, $taxonomy);
    return posts_url($term->type->post_type, $term->forUrl(), true);
}, 10, 3);
// @link https://developer.wordpress.org/reference/hooks/wp_get_attachment_url/
add_filter('wp_get_attachment_url', function ($url, $postId) {
    return url(AttachmentEntity::attachmentPath($url), true);
}, 10, 2);
// -----------------------------------------------------------------------------
// Last Modified
// -----------------------------------------------------------------------------
foreach (['save_post', 'deleted_post'] as $_action) {
    add_action($_action, function ($id) {
        if (wp_is_post_revision($id)) {
            return;
        }
        update_option(WP::OPTION_LAST_MODIFIED, time());
    });
}
foreach (['comment_post', 'edit_comment', 'deleted_comment'] as $_action) {
    add_action($_action, function ($id, $approved = null) {
        if (!is_null($approved) && $approved !== 1) {