Skip to content

Commit beff7ca

Browse files
authored
Merge pull request #45 from passle/develop
Version v2.0.0 Release
2 parents 32ba232 + 7b56b80 commit beff7ca

24 files changed

+472
-37
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ vendor/
1717

1818
# ZIP output
1919
build/
20+
.vs/

class/Actions/UpdateFeaturedPostAction.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ class UpdateFeaturedPostAction
99
{
1010
public static function execute(string $post_shortcode, bool $is_featured_on_passle_page, bool $is_featured_on_post_page)
1111
{
12+
Utils::clear_featured_posts();
13+
14+
// if the shortcode is empty it means the featured post has been removed and therefore no need to continue.
15+
if (empty($post_shortcode)) return;
16+
1217
$posts = get_posts([
1318
"post_type" => PASSLESYNC_POST_TYPE,
1419
"numberposts" => 1,
@@ -23,7 +28,6 @@ public static function execute(string $post_shortcode, bool $is_featured_on_pass
2328
if (empty($posts)) return new WP_Error("404", "No post exists with the shortcode specified");
2429
$post = $posts[0];
2530

26-
Utils::clear_featured_posts();
2731

2832
if ($is_featured_on_passle_page) {
2933
update_post_meta($post->ID, "post_is_featured_on_passle_page", true);

class/Controllers/SettingsController.php

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static function update_api_settings(WP_REST_Request $request)
3232
$params["simulateRemoteHosting"],
3333
$params["includePasslePostsOnHomePage"],
3434
$params["includePasslePostsOnTagPage"],
35+
$params["includePassleTagGroups"],
3536
PASSLESYNC_DOMAIN_EXT,
3637
get_site_url(),
3738
);

class/Models/Admin/Options.php

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Options implements JsonSerializable
1616
public bool $simulate_remote_hosting;
1717
public bool $include_passle_posts_on_home_page;
1818
public bool $include_passle_posts_on_tag_page;
19+
public bool $include_passle_tag_groups;
1920
public string $domain_ext;
2021
public string $site_url;
2122

@@ -30,6 +31,7 @@ public function __construct(
3031
bool $simulate_remote_hosting,
3132
bool $include_passle_posts_on_home_page,
3233
bool $include_passle_posts_on_tag_page,
34+
bool $include_passle_tag_groups,
3335
string $domain_ext,
3436
string $site_url
3537
) {
@@ -42,6 +44,7 @@ public function __construct(
4244
$this->simulate_remote_hosting = $simulate_remote_hosting;
4345
$this->include_passle_posts_on_home_page = $include_passle_posts_on_home_page;
4446
$this->include_passle_posts_on_tag_page = $include_passle_posts_on_tag_page;
47+
$this->include_passle_tag_groups = $include_passle_tag_groups;
4548
$this->domain_ext = $domain_ext;
4649
$this->site_url = $site_url;
4750
}
@@ -58,6 +61,7 @@ public function jsonSerialize()
5861
"simulateRemoteHosting" => $this->simulate_remote_hosting,
5962
"includePasslePostsOnHomePage" => isset($this->include_passle_posts_on_home_page) ? $this->include_passle_posts_on_home_page : false,
6063
"includePasslePostsOnTagPage" => isset($this->include_passle_posts_on_tag_page) ? $this->include_passle_posts_on_tag_page : false,
64+
"includePassleTagGroups" => isset($this->include_passle_tag_groups) ? $this->include_passle_tag_groups : false,
6165
"domainExt" => $this->domain_ext,
6266
"siteUrl" => $this->site_url,
6367
];

class/Models/PassleAuthor.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ class PassleAuthor
2424
public string $role;
2525
/** The profile description for this person. */
2626
public string $description;
27-
/** The person's email address. */
27+
/** The person's email address. Obsolete. Please use $public_email_address or $primary_email_address instead. */
2828
public string $email_address;
29+
/** The person's email address set as public on their profile. */
30+
public string $public_email_address;
31+
/** The person's email address set as primary on their profile. Can be used as an identifier. */
32+
public string $primary_email_address;
2933
/** The person's phone number. */
3034
public string $phone_number;
3135
/** The URL to the person's LinkedIn profile. */
@@ -107,6 +111,8 @@ private function initialize_wp_author()
107111
$this->role = $this->wp_author->post_excerpt ?? "";
108112
$this->description = $this->wp_author->post_content ?? "";
109113
$this->email_address = $this->meta["email_address"][0] ?? "";
114+
$this->public_email_address = $this->meta["public_email_address"][0] ?? "";
115+
$this->primary_email_address = $this->meta["primary_email_address"][0] ?? "";
110116
$this->phone_number = $this->meta["phone_number"][0] ?? "";
111117
$this->linkedin_profile_link = $this->meta["linkedin_profile_link"][0] ?? "";
112118
$this->facebook_profile_link = $this->meta["facebook_profile_link"][0] ?? "";
@@ -149,6 +155,8 @@ private function initialize_post_author()
149155
$this->role = $this->post_author["role"] ?? "";
150156
$this->description = "";
151157
$this->email_address = "";
158+
$this->public_email_address = "";
159+
$this->primary_email_address = "";
152160
$this->phone_number = "";
153161
$this->linkedin_profile_link = "";
154162
$this->facebook_profile_link = "";

class/PassleSync.php

+45-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Passle\PassleSync;
44

55
use Passle\PassleSync\Services\CptRegistryService;
6+
use Passle\PassleSync\Services\TaxonomyRegistryService;
67
use Passle\PassleSync\Services\EmbedService;
78
use Passle\PassleSync\Services\MenuService;
89
use Passle\PassleSync\Services\OptionsService;
@@ -14,8 +15,13 @@
1415
use Passle\PassleSync\Services\ThemeService;
1516
use Passle\PassleSync\Services\UpgradeService;
1617

18+
use Passle\PassleSync\Services\Content\Passle\PassleTagGroupsContentService;
19+
use Passle\PassleSync\Services\Content\Passle\PasslePostsContentService;
20+
1721
class PassleSync
1822
{
23+
private const TAG_GROUPS_CACHE_CLEAN_EVENT_NAME = "passle_sync_clear_tag_groups_cache_event";
24+
1925
public static function initialize()
2026
{
2127
MenuService::init();
@@ -30,8 +36,14 @@ public static function initialize()
3036
TemplateService::init();
3137
UpgradeService::init();
3238

33-
register_activation_hook(__FILE__, [static::class, "activate"]);
34-
register_deactivation_hook(__FILE__, [static::class, "deactivate"]);
39+
$options = OptionsService::get();
40+
41+
if ($options->include_passle_tag_groups) {
42+
TaxonomyRegistryService::init();
43+
self::schedule_tag_groups_cache_cleanup();
44+
} else {
45+
self::unschedule_tag_groups_cache_cleanup();
46+
}
3547
}
3648

3749
public static function activate()
@@ -42,5 +54,36 @@ public static function activate()
4254
public static function deactivate()
4355
{
4456
flush_rewrite_rules();
57+
self::unschedule_tag_groups_cache_cleanup();
58+
}
59+
60+
/*
61+
* The following code deals with scheduling tag groups cache cleanup, so when a new
62+
* tag group is created in Passle, at some point within the hour, it is also created in WP
63+
* following the init event.
64+
* If a Resource class is created for passle tag groups, this code will need to be moved probably.
65+
*/
66+
public static function schedule_tag_groups_cache_cleanup()
67+
{
68+
if (!wp_next_scheduled(self::TAG_GROUPS_CACHE_CLEAN_EVENT_NAME)) {
69+
wp_schedule_event(time(), "hourly", self::TAG_GROUPS_CACHE_CLEAN_EVENT_NAME);
70+
}
71+
add_action(self::TAG_GROUPS_CACHE_CLEAN_EVENT_NAME, [static::class, "tag_groups_cache_cleanup"]);
72+
}
73+
74+
public static function tag_groups_cache_cleanup()
75+
{
76+
PassleTagGroupsContentService::overwrite_cache(array());
77+
// This needs to happen so next time posts sync their tag mappings are updated
78+
PasslePostsContentService::overwrite_cache(array());
79+
}
80+
81+
public static function unschedule_tag_groups_cache_cleanup()
82+
{
83+
$timestamp = wp_next_scheduled(self::TAG_GROUPS_CACHE_CLEAN_EVENT_NAME);
84+
if ($timestamp) {
85+
wp_unschedule_event($timestamp, self::TAG_GROUPS_CACHE_CLEAN_EVENT_NAME);
86+
}
4587
}
4688
}
89+

class/PostTypes/CptBase.php

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public static function create_post_type()
5757
],
5858
"hierarchical" => false,
5959
"supports" => ["title", "custom-fields"],
60-
"taxonomies" => ["post_tag"],
6160
"has_archive" => true,
6261
"rewrite" => false,
6362
"query_var" => true,

class/PostTypes/PasslePostCpt.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ class PasslePostCpt extends CptBase
1111

1212
protected static function get_cpt_args(): array
1313
{
14-
return [
15-
"menu_icon" => "dashicons-admin-post",
16-
"taxonomies" => ["post_tag"],
14+
$args = [
15+
"menu_icon" => "dashicons-admin-post"
1716
];
17+
18+
if (OptionsService::get()->include_passle_tag_groups) {
19+
$args["taxonomies"] = ["tag_group", "post_tag"];
20+
} else {
21+
$args["taxonomies"] = ["post_tag"];
22+
}
23+
24+
return $args;
1825
}
1926

2027
protected static function get_permalink_template(): string

class/Services/Content/Passle/PassleContentServiceBase.php

+27-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function get_cache()
2323
return $items;
2424
}
2525

26-
public static function overwite_cache(array $data)
26+
public static function overwrite_cache(array $data)
2727
{
2828
$cache_storage_key = static::get_resource_instance()->get_cache_storage_key();
2929

@@ -52,12 +52,14 @@ public static function update_cache(array $data)
5252
}
5353
}
5454

55-
static::overwite_cache($existing_items);
55+
static::overwrite_cache($existing_items);
5656
}
5757

5858
public static function fetch_all()
5959
{
60-
$passle_shortcodes = OptionsService::get()->passle_shortcodes;
60+
$options = OptionsService::get();
61+
62+
$passle_shortcodes = $options->passle_shortcodes;
6163

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

78-
static::overwite_cache($result);
80+
static::overwrite_cache($result);
7981
return $result;
8082
} else {
81-
static::overwite_cache(array());
83+
static::overwrite_cache(array());
8284
return array();
8385
}
8486
}
8587

8688
public static function fetch_all_by_passle(string $passle_shortcode)
8789
{
8890
$resource = static::get_resource_instance();
91+
$options = OptionsService::get();
92+
93+
$path = "passlesync/{$resource->name_plural}";
94+
95+
$parameters = array(
96+
"PassleShortcode" => $passle_shortcode,
97+
"ItemsPerPage" => "100"
98+
);
99+
100+
if ($options->include_passle_tag_groups) {
101+
$parameters["IncludeTagGroups"] = "true";
102+
}
89103

90104
$url = (new UrlFactory())
91-
->path("passlesync/{$resource->name_plural}")
92-
->parameters([
93-
"PassleShortcode" => $passle_shortcode,
94-
"ItemsPerPage" => "100"
95-
])
96-
->build();
105+
->path($path)
106+
->parameters($parameters)
107+
->build();
97108

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

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

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

134+
if ($options->include_passle_tag_groups) {
135+
$params["IncludeTagGroups"] = "true";
136+
}
137+
122138
$factory = new UrlFactory();
123139
$url = $factory
124140
->path("passlesync/{$resource->name_plural}")

0 commit comments

Comments
 (0)