/** * Filters the post type link URL and returns a query-based representation, if set for the according post type. * * @since 3.0.0 * @wp-hook post_type_link * * @param string $post_link Post URL. * @param WP_Post $post Post object. * * @return string The (filtered) post type link URL. */ public function unprettify_permalink($post_link, WP_Post $post) { if (!$this->post_type_repository->is_post_type_active_and_query_based($post->post_type)) { return $post_link; } $post_type = get_post_type_object($post->post_type); if ($post_type->query_var && !$this->is_draft_or_pending($post)) { $args = [$post_type->query_var => $post->post_name]; } else { $args = ['p' => $post->ID]; } return site_url(add_query_arg($args, '')); }
/** * Updates the post type support settings. * * @since 3.0.0 * @wp-hook mlp_modules_save_fields * * @return bool Whether or not the settings were updated successfully. */ public function update_settings() { if (!$this->nonce->is_valid()) { return false; } $custom_post_types = $this->repository->get_custom_post_types(); if (!$custom_post_types || empty($_POST[self::SETTINGS_NAME])) { return $this->repository->unsupport_all_post_types(); } $custom_post_types = array_keys($custom_post_types); $settings = (array) $_POST[self::SETTINGS_NAME]; $custom_post_types = array_combine($custom_post_types, array_map(function ($slug) use($settings) { if (empty($settings[$slug])) { return PostTypeRepository::CPT_INACTIVE; } return empty($settings["{$slug}|links"]) ? PostTypeRepository::CPT_ACTIVE : PostTypeRepository::CPT_QUERY_BASED; }, $custom_post_types)); return $this->repository->set_supported_post_types($custom_post_types); }