Skip to content

Commit

Permalink
Merge pull request #45 from passle/develop
Browse files Browse the repository at this point in the history
Version v2.0.0 Release
  • Loading branch information
klikas authored Feb 5, 2024
2 parents 32ba232 + 7b56b80 commit beff7ca
Show file tree
Hide file tree
Showing 24 changed files with 472 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ vendor/

# ZIP output
build/
.vs/
6 changes: 5 additions & 1 deletion class/Actions/UpdateFeaturedPostAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class UpdateFeaturedPostAction
{
public static function execute(string $post_shortcode, bool $is_featured_on_passle_page, bool $is_featured_on_post_page)
{
Utils::clear_featured_posts();

// if the shortcode is empty it means the featured post has been removed and therefore no need to continue.
if (empty($post_shortcode)) return;

$posts = get_posts([
"post_type" => PASSLESYNC_POST_TYPE,
"numberposts" => 1,
Expand All @@ -23,7 +28,6 @@ public static function execute(string $post_shortcode, bool $is_featured_on_pass
if (empty($posts)) return new WP_Error("404", "No post exists with the shortcode specified");
$post = $posts[0];

Utils::clear_featured_posts();

if ($is_featured_on_passle_page) {
update_post_meta($post->ID, "post_is_featured_on_passle_page", true);
Expand Down
1 change: 1 addition & 0 deletions class/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static function update_api_settings(WP_REST_Request $request)
$params["simulateRemoteHosting"],
$params["includePasslePostsOnHomePage"],
$params["includePasslePostsOnTagPage"],
$params["includePassleTagGroups"],
PASSLESYNC_DOMAIN_EXT,
get_site_url(),
);
Expand Down
4 changes: 4 additions & 0 deletions class/Models/Admin/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Options implements JsonSerializable
public bool $simulate_remote_hosting;
public bool $include_passle_posts_on_home_page;
public bool $include_passle_posts_on_tag_page;
public bool $include_passle_tag_groups;
public string $domain_ext;
public string $site_url;

Expand All @@ -30,6 +31,7 @@ public function __construct(
bool $simulate_remote_hosting,
bool $include_passle_posts_on_home_page,
bool $include_passle_posts_on_tag_page,
bool $include_passle_tag_groups,
string $domain_ext,
string $site_url
) {
Expand All @@ -42,6 +44,7 @@ public function __construct(
$this->simulate_remote_hosting = $simulate_remote_hosting;
$this->include_passle_posts_on_home_page = $include_passle_posts_on_home_page;
$this->include_passle_posts_on_tag_page = $include_passle_posts_on_tag_page;
$this->include_passle_tag_groups = $include_passle_tag_groups;
$this->domain_ext = $domain_ext;
$this->site_url = $site_url;
}
Expand All @@ -58,6 +61,7 @@ public function jsonSerialize()
"simulateRemoteHosting" => $this->simulate_remote_hosting,
"includePasslePostsOnHomePage" => isset($this->include_passle_posts_on_home_page) ? $this->include_passle_posts_on_home_page : false,
"includePasslePostsOnTagPage" => isset($this->include_passle_posts_on_tag_page) ? $this->include_passle_posts_on_tag_page : false,
"includePassleTagGroups" => isset($this->include_passle_tag_groups) ? $this->include_passle_tag_groups : false,
"domainExt" => $this->domain_ext,
"siteUrl" => $this->site_url,
];
Expand Down
10 changes: 9 additions & 1 deletion class/Models/PassleAuthor.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ class PassleAuthor
public string $role;
/** The profile description for this person. */
public string $description;
/** The person's email address. */
/** The person's email address. Obsolete. Please use $public_email_address or $primary_email_address instead. */
public string $email_address;
/** The person's email address set as public on their profile. */
public string $public_email_address;
/** The person's email address set as primary on their profile. Can be used as an identifier. */
public string $primary_email_address;
/** The person's phone number. */
public string $phone_number;
/** The URL to the person's LinkedIn profile. */
Expand Down Expand Up @@ -107,6 +111,8 @@ private function initialize_wp_author()
$this->role = $this->wp_author->post_excerpt ?? "";
$this->description = $this->wp_author->post_content ?? "";
$this->email_address = $this->meta["email_address"][0] ?? "";
$this->public_email_address = $this->meta["public_email_address"][0] ?? "";
$this->primary_email_address = $this->meta["primary_email_address"][0] ?? "";
$this->phone_number = $this->meta["phone_number"][0] ?? "";
$this->linkedin_profile_link = $this->meta["linkedin_profile_link"][0] ?? "";
$this->facebook_profile_link = $this->meta["facebook_profile_link"][0] ?? "";
Expand Down Expand Up @@ -149,6 +155,8 @@ private function initialize_post_author()
$this->role = $this->post_author["role"] ?? "";
$this->description = "";
$this->email_address = "";
$this->public_email_address = "";
$this->primary_email_address = "";
$this->phone_number = "";
$this->linkedin_profile_link = "";
$this->facebook_profile_link = "";
Expand Down
47 changes: 45 additions & 2 deletions class/PassleSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Passle\PassleSync;

use Passle\PassleSync\Services\CptRegistryService;
use Passle\PassleSync\Services\TaxonomyRegistryService;
use Passle\PassleSync\Services\EmbedService;
use Passle\PassleSync\Services\MenuService;
use Passle\PassleSync\Services\OptionsService;
Expand All @@ -14,8 +15,13 @@
use Passle\PassleSync\Services\ThemeService;
use Passle\PassleSync\Services\UpgradeService;

use Passle\PassleSync\Services\Content\Passle\PassleTagGroupsContentService;
use Passle\PassleSync\Services\Content\Passle\PasslePostsContentService;

class PassleSync
{
private const TAG_GROUPS_CACHE_CLEAN_EVENT_NAME = "passle_sync_clear_tag_groups_cache_event";

public static function initialize()
{
MenuService::init();
Expand All @@ -30,8 +36,14 @@ public static function initialize()
TemplateService::init();
UpgradeService::init();

register_activation_hook(__FILE__, [static::class, "activate"]);
register_deactivation_hook(__FILE__, [static::class, "deactivate"]);
$options = OptionsService::get();

if ($options->include_passle_tag_groups) {
TaxonomyRegistryService::init();
self::schedule_tag_groups_cache_cleanup();
} else {
self::unschedule_tag_groups_cache_cleanup();
}
}

public static function activate()
Expand All @@ -42,5 +54,36 @@ public static function activate()
public static function deactivate()
{
flush_rewrite_rules();
self::unschedule_tag_groups_cache_cleanup();
}

/*
* The following code deals with scheduling tag groups cache cleanup, so when a new
* tag group is created in Passle, at some point within the hour, it is also created in WP
* following the init event.
* If a Resource class is created for passle tag groups, this code will need to be moved probably.
*/
public static function schedule_tag_groups_cache_cleanup()
{
if (!wp_next_scheduled(self::TAG_GROUPS_CACHE_CLEAN_EVENT_NAME)) {
wp_schedule_event(time(), "hourly", self::TAG_GROUPS_CACHE_CLEAN_EVENT_NAME);
}
add_action(self::TAG_GROUPS_CACHE_CLEAN_EVENT_NAME, [static::class, "tag_groups_cache_cleanup"]);
}

public static function tag_groups_cache_cleanup()
{
PassleTagGroupsContentService::overwrite_cache(array());
// This needs to happen so next time posts sync their tag mappings are updated
PasslePostsContentService::overwrite_cache(array());
}

public static function unschedule_tag_groups_cache_cleanup()
{
$timestamp = wp_next_scheduled(self::TAG_GROUPS_CACHE_CLEAN_EVENT_NAME);
if ($timestamp) {
wp_unschedule_event($timestamp, self::TAG_GROUPS_CACHE_CLEAN_EVENT_NAME);
}
}
}

1 change: 0 additions & 1 deletion class/PostTypes/CptBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public static function create_post_type()
],
"hierarchical" => false,
"supports" => ["title", "custom-fields"],
"taxonomies" => ["post_tag"],
"has_archive" => true,
"rewrite" => false,
"query_var" => true,
Expand Down
13 changes: 10 additions & 3 deletions class/PostTypes/PasslePostCpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ class PasslePostCpt extends CptBase

protected static function get_cpt_args(): array
{
return [
"menu_icon" => "dashicons-admin-post",
"taxonomies" => ["post_tag"],
$args = [
"menu_icon" => "dashicons-admin-post"
];

if (OptionsService::get()->include_passle_tag_groups) {
$args["taxonomies"] = ["tag_group", "post_tag"];
} else {
$args["taxonomies"] = ["post_tag"];
}

return $args;
}

protected static function get_permalink_template(): string
Expand Down
38 changes: 27 additions & 11 deletions class/Services/Content/Passle/PassleContentServiceBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function get_cache()
return $items;
}

public static function overwite_cache(array $data)
public static function overwrite_cache(array $data)
{
$cache_storage_key = static::get_resource_instance()->get_cache_storage_key();

Expand Down Expand Up @@ -52,12 +52,14 @@ public static function update_cache(array $data)
}
}

static::overwite_cache($existing_items);
static::overwrite_cache($existing_items);
}

public static function fetch_all()
{
$passle_shortcodes = OptionsService::get()->passle_shortcodes;
$options = OptionsService::get();

$passle_shortcodes = $options->passle_shortcodes;

/** @var array[] $results */
$results = array_map(fn ($passle_shortcode) => static::fetch_all_by_passle($passle_shortcode), $passle_shortcodes);
Expand All @@ -75,25 +77,34 @@ public static function fetch_all()
// Set the default sync state to unsynced
array_walk($result, fn (&$i) => $i["SyncState"] = 0);

static::overwite_cache($result);
static::overwrite_cache($result);
return $result;
} else {
static::overwite_cache(array());
static::overwrite_cache(array());
return array();
}
}

public static function fetch_all_by_passle(string $passle_shortcode)
{
$resource = static::get_resource_instance();
$options = OptionsService::get();

$path = "passlesync/{$resource->name_plural}";

$parameters = array(
"PassleShortcode" => $passle_shortcode,
"ItemsPerPage" => "100"
);

if ($options->include_passle_tag_groups) {
$parameters["IncludeTagGroups"] = "true";
}

$url = (new UrlFactory())
->path("passlesync/{$resource->name_plural}")
->parameters([
"PassleShortcode" => $passle_shortcode,
"ItemsPerPage" => "100"
])
->build();
->path($path)
->parameters($parameters)
->build();

$responses = static::get_all_paginated($url);

Expand All @@ -114,11 +125,16 @@ public static function fetch_by_shortcode(string $entity_shortcode)
public static function fetch_multiple_by_shortcode(array $entity_shortcodes)
{
$resource = static::get_resource_instance();
$options = OptionsService::get();

$params = [
$resource->get_api_parameter_shortcode_name() => join(",", $entity_shortcodes)
];

if ($options->include_passle_tag_groups) {
$params["IncludeTagGroups"] = "true";
}

$factory = new UrlFactory();
$url = $factory
->path("passlesync/{$resource->name_plural}")
Expand Down
Loading

0 comments on commit beff7ca

Please sign in to comment.