Example #1
0
}, 10, 2);
// @link https://developer.wordpress.org/reference/functions/get_post_permalink/
add_filter('post_type_link', function ($permalink, $post, $leavename) {
    $postType = get_post_type_object($post->post_type);
    $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());
    });
Example #2
0
 /**
  * Get the URL.
  *
  * @param array|bool $parameters
  * @param bool $full
  * @return string
  *
  * @throws \Exception
  */
 public function url($parameters = [], $full = false)
 {
     if (is_bool($parameters)) {
         list($parameters, $full) = [[], $parameters];
     } elseif (!is_array($parameters)) {
         $parameters = [$parameters];
     }
     switch (true) {
         case $this->original instanceof PostType:
             return posts_url($this->original, $parameters, $full);
         case $this->original instanceof DateArchive:
         case $this->original instanceof TermEntity:
             $parameters += $this->original->forUrl();
             return posts_url($this->postType, $parameters, $full);
         case $this->original instanceof PostEntity:
             return post_url($this->original, $parameters, $full);
     }
     throw new Exception("Could not determine the URL.");
 }