Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
04cc382
Update phpstan.neon.dist to change paths from 'src/' to 'inc/'
ocean90 Jan 23, 2026
55bd2c2
Add detailed example functions for post types, post meta, and taxonom…
ocean90 Jan 23, 2026
57872bb
Increase memory limit for PHPStan analysis script in composer.json
ocean90 Jan 23, 2026
c90e645
Remove deprecated Legacy implementations
ocean90 Jan 23, 2026
600c49b
Add strict_types declarations
ocean90 Jan 23, 2026
21cab20
Type Admin helpers
ocean90 Jan 23, 2026
9794843
Type Container registry
ocean90 Jan 23, 2026
ac448b5
Fix Page get_callback phpdoc
ocean90 Jan 23, 2026
884f8e3
Type shortcode view contract
ocean90 Jan 23, 2026
7646d35
Align ShortcodeView attribute types
ocean90 Jan 23, 2026
91179c8
Widen ShortcodeView attribute keys
ocean90 Jan 23, 2026
8de801c
Type PostType NAME and args
ocean90 Jan 23, 2026
0d31acc
Type Taxonomy object types
ocean90 Jan 23, 2026
06f2cf4
Fix meta registration typings
ocean90 Jan 23, 2026
5e2f4a3
Type TermMetaAdminUI and taxonomy contract
ocean90 Jan 23, 2026
c534953
Exclude Squiz.Commenting.VariableComment.MissingVar rule
ocean90 Jan 23, 2026
a3ddf9b
Fix PHPCS issues
ocean90 Jan 23, 2026
f16ef04
Remove Shortcode and ShortcodeView classes
ocean90 Jan 23, 2026
6072839
Document factory-based registration
ocean90 Jan 23, 2026
640ae89
Remove FACTORIES.md documentation file
ocean90 Jan 25, 2026
1d8df61
Refactor render_column method to use filter instead of action and upd…
ocean90 Jan 26, 2026
d7bb20f
Fix PHPDoc annotations and add PostType NAME constant (#8)
Copilot Feb 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 237 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,240 @@
```
composer require wearerequired/common-php
```

## Example

```php
/**
* Bootstraps post type integrations.
*/
function bootstrap(): void {
add_action( 'init', __NAMESPACE__ . '\register_post_types' );
add_action( 'init', __NAMESPACE__ . '\register_post_meta' );
add_action( 'init', __NAMESPACE__ . '\register_taxonomies' );
add_action( 'init', __NAMESPACE__ . '\register_taxonomy_for_object_types', 11 );
}

/**
* Registers custom post types.
*/
function register_post_types() {
$post_types = new Container();

$post_types->add( Profession::NAME, new Profession() );
$post_types->add( School::NAME, new School() );
$post_types->add( Office::NAME, new Office() );
$post_types->add( Event::NAME, new Event() );
$post_types->add( Apprenticeship::NAME, new Apprenticeship() );
$post_types->add( TrialApprenticeship::NAME, new TrialApprenticeship() );
$post_types->add( Organization::NAME, new Organization() );

$post_types->bootstrap();
}

/**
* Registers post meta.
*/
function register_post_meta() {
$post_meta = new Container();

$post_meta->add( PostMeta\ImportID::KEY, new PostMeta\ImportID() );
$post_meta->add( PostMeta\ImportTimestamp::KEY, new PostMeta\ImportTimestamp() );

$post_meta->add( PostMeta\SchoolOfficeID::KEY, new PostMeta\SchoolOfficeID() );
$post_meta->add( PostMeta\SchoolTelNumber::KEY, new PostMeta\SchoolTelNumber() );
$post_meta->add( PostMeta\SchoolEmail::KEY, new PostMeta\SchoolEmail() );

$post_meta->add( PostMeta\OfficeStreet::KEY, new PostMeta\OfficeStreet() );
$post_meta->add( PostMeta\OfficePOBox::KEY, new PostMeta\OfficePOBox() );
$post_meta->add( PostMeta\OfficeEmail::KEY, new PostMeta\OfficeEmail() );
$post_meta->add( PostMeta\OfficeTelNumber::KEY, new PostMeta\OfficeTelNumber() );
$post_meta->add( PostMeta\OfficeFax::KEY, new PostMeta\OfficeFax() );
$post_meta->add( PostMeta\OfficeContactURL::KEY, new PostMeta\OfficeContactURL() );
$post_meta->add( PostMeta\OfficeOpeningHours::KEY, new PostMeta\OfficeOpeningHours() );
$post_meta->add( PostMeta\OfficeSendCopyToConsultant::KEY, new PostMeta\OfficeSendCopyToConsultant() );

$post_meta->add( PostMeta\EventAdditionalInfo::KEY, new PostMeta\EventAdditionalInfo() );
$post_meta->add( PostMeta\EventAddress::KEY, new PostMeta\EventAddress() );
$post_meta->add( PostMeta\EventAuthor::KEY, new PostMeta\EventAuthor() );
$post_meta->add( PostMeta\EventCity::KEY, new PostMeta\EventCity() );
$post_meta->add( PostMeta\EventCode::KEY, new PostMeta\EventCode() );
$post_meta->add( PostMeta\EventCreator::KEY, new PostMeta\EventCreator() );
$post_meta->add( PostMeta\EventDepartment::KEY, new PostMeta\EventDepartment() );
$post_meta->add( PostMeta\EventFeeInfoNoFees::KEY, new PostMeta\EventFeeInfoNoFees() );
$post_meta->add( PostMeta\EventFeeInfoFee::KEY, new PostMeta\EventFeeInfoFee() );
$post_meta->add( PostMeta\EventFeeInfoCurrency::KEY, new PostMeta\EventFeeInfoCurrency() );
$post_meta->add( PostMeta\EventFeeInfoDescription::KEY, new PostMeta\EventFeeInfoDescription() );
$post_meta->add( PostMeta\EventGuideDescr::KEY, new PostMeta\EventGuideDescr() );
$post_meta->add( PostMeta\EventGuideFirstname::KEY, new PostMeta\EventGuideFirstname() );
$post_meta->add( PostMeta\EventGuideLastname::KEY, new PostMeta\EventGuideLastname() );
$post_meta->add( PostMeta\EventHostCity::KEY, new PostMeta\EventHostCity() );
$post_meta->add( PostMeta\EventHostLastname::KEY, new PostMeta\EventHostLastname() );
$post_meta->add( PostMeta\EventHostRegion::KEY, new PostMeta\EventHostRegion() );
$post_meta->add( PostMeta\EventHostType::KEY, new PostMeta\EventHostType() );
$post_meta->add( PostMeta\EventHostZip::KEY, new PostMeta\EventHostZip() );
$post_meta->add( PostMeta\EventHostPhone::KEY, new PostMeta\EventHostPhone() );
$post_meta->add( PostMeta\EventHostMail::KEY, new PostMeta\EventHostMail() );
$post_meta->add( PostMeta\EventHostWebsite::KEY, new PostMeta\EventHostWebsite() );
$post_meta->add( PostMeta\EventLocation::KEY, new PostMeta\EventLocation() );
$post_meta->add( PostMeta\EventOrgDepartment::KEY, new PostMeta\EventOrgDepartment() );
$post_meta->add( PostMeta\EventRegion::KEY, new PostMeta\EventRegion() );
$post_meta->add( PostMeta\EventRegistrationLink::KEY, new PostMeta\EventRegistrationLink() );
$post_meta->add( PostMeta\EventRegistrationMail::KEY, new PostMeta\EventRegistrationMail() );
$post_meta->add( PostMeta\EventRegistrationName::KEY, new PostMeta\EventRegistrationName() );
$post_meta->add( PostMeta\EventHasRegistration::KEY, new PostMeta\EventHasRegistration() );
$post_meta->add( PostMeta\EventRegistrationPhone::KEY, new PostMeta\EventRegistrationPhone() );
$post_meta->add( PostMeta\EventSeatsMax::KEY, new PostMeta\EventSeatsMax() );
$post_meta->add( PostMeta\EventSeatsMin::KEY, new PostMeta\EventSeatsMin() );
$post_meta->add( PostMeta\EventSeatsAvailable::KEY, new PostMeta\EventSeatsAvailable() );
$post_meta->add( PostMeta\EventSpeakers::KEY, new PostMeta\EventSpeakers() );
$post_meta->add( PostMeta\EventUnid::KEY, new PostMeta\EventUnid() );
$post_meta->add( PostMeta\EventZip::KEY, new PostMeta\EventZip() );
$post_meta->add( PostMeta\EventDateStart::KEY, new PostMeta\EventDateStart() );
$post_meta->add( PostMeta\EventDateEnd::KEY, new PostMeta\EventDateEnd() );
$post_meta->add( PostMeta\EventDates::KEY, new PostMeta\EventDates() );
$post_meta->add( PostMeta\EventIsOnline::KEY, new PostMeta\EventIsOnline() );
$post_meta->add( PostMeta\EventTargetAudience::KEY, new PostMeta\EventTargetAudience() );
$post_meta->add( PostMeta\EventSwissdocIDs::KEY, new PostMeta\EventSwissdocIDs() );

$post_meta->add( PostMeta\SwissdocNumber::KEY, new PostMeta\SwissdocNumber() );

$post_meta->add( PostMeta\Zip::KEY, new PostMeta\Zip() );
$post_meta->add( PostMeta\City::KEY, new PostMeta\City() );
$post_meta->add( PostMeta\Lat::KEY, new PostMeta\Lat() );
$post_meta->add( PostMeta\Lng::KEY, new PostMeta\Lng() );

$post_meta->add( PostMeta\ProfessionSNI::KEY, new PostMeta\ProfessionSNI() );
$post_meta->add( PostMeta\ProfessionCompletedApprenticeshipContracts::KEY, new PostMeta\ProfessionCompletedApprenticeshipContracts() );
$post_meta->add( PostMeta\ProfessionVideoURLs::KEY, new PostMeta\ProfessionVideoURLs() );
$post_meta->add( PostMeta\ProfessionPodcastURLs::KEY, new PostMeta\ProfessionPodcastURLs() );
$post_meta->add( PostMeta\ProfessionSkipImport::KEY, new PostMeta\ProfessionSkipImport() );
$post_meta->add( PostMeta\ProfessionSchoolRequirementsURL::KEY, new PostMeta\ProfessionSchoolRequirementsURL() );
$post_meta->add( PostMeta\ProfessionHint::KEY, new PostMeta\ProfessionHint() );
$post_meta->add( PostMeta\ProfessionForeignLanguage::KEY, new PostMeta\ProfessionForeignLanguage() );

$post_meta->add( PostMeta\OrganizationLogoURL::KEY, new PostMeta\OrganizationLogoURL() );

$post_meta->bootstrap();
}

/**
* Registers custom taxonomies.
*/
function register_taxonomies(): void {
$taxonomies = new Container();

$taxonomies->add( ProfessionField::NAME, new ProfessionField() );
$taxonomies->add( ProfessionInterest::NAME, new ProfessionInterest() );
$taxonomies->add( ProfessionSector::NAME, new ProfessionSector() );
$taxonomies->add( ProfessionAlternativeTitle::NAME, new ProfessionAlternativeTitle() );
$taxonomies->add( ProfessionDuration::NAME, new ProfessionDuration() );
$taxonomies->add( ProfessionQualification::NAME, new ProfessionQualification() );
$taxonomies->add( ProfessionBilingualEducation::NAME, new ProfessionBilingualEducation() );
$taxonomies->add( EventSpeaker::NAME, new EventSpeaker() );
$taxonomies->add( EventAudience::NAME, new EventAudience() );
$taxonomies->add( EventTopic::NAME, new EventTopic() );
$taxonomies->add( EventStatus::NAME, new EventStatus() );
$taxonomies->add( Swissdoc::NAME, new Swissdoc() );
$taxonomies->add( ApprenticeshipOrganization::NAME, new ApprenticeshipOrganization() );
$taxonomies->add( UserNationality::NAME, new UserNationality() );
$taxonomies->add( UserLanguage::NAME, new UserLanguage() );
$taxonomies->add( ApprenticeshipYear::NAME, new ApprenticeshipYear() );
$taxonomies->add( LinkDistrictOrganizationApprenticeship::NAME, new LinkDistrictOrganizationApprenticeship() );
$taxonomies->add( LinkDistrictOrganizationTrialApprenticeship::NAME, new LinkDistrictOrganizationTrialApprenticeship() );
$taxonomies->add( LinkSwissdocOrganizationApprenticeship::NAME, new LinkSwissdocOrganizationApprenticeship() );
$taxonomies->add( LinkSwissdocOrganizationTrialApprenticeship::NAME, new LinkSwissdocOrganizationTrialApprenticeship() );
$taxonomies->add( OrganizationEmail::NAME, new OrganizationEmail() );

$district = new District();
$taxonomies->add( District::NAME, $district );

$meta_position = new TermMeta\Position();
$meta_position->register();
add_action(
'admin_init',
static function () use ( $district, $meta_position ): void {
$meta_position_ui = new Admin\PositionTermUI(
$district,
$meta_position
);
$meta_position_ui->register();
}
);

$meta_zip = new TermMeta\Zip();
$meta_zip->register();
add_action(
'admin_init',
static function () use ( $district, $meta_zip ): void {
$meta_zip_ui = new Admin\ZipTermUI(
$district,
$meta_zip
);
$meta_zip_ui->register();
}
);

$meta_city = new TermMeta\City();
$meta_city->register();
add_action(
'admin_init',
static function () use ( $district, $meta_city ): void {
$meta_city_ui = new Admin\CityTermUI(
$district,
$meta_city
);
$meta_city_ui->register();
}
);

$taxonomies->bootstrap();
}

/**
* Registers taxonomies for object types.
*/
function register_taxonomy_for_object_types(): void {
register_taxonomy_for_object_type( ProfessionField::NAME, PostType\Profession::NAME );
register_taxonomy_for_object_type( ProfessionField::NAME, PostType\Event::NAME );

register_taxonomy_for_object_type( ProfessionInterest::NAME, PostType\Profession::NAME );
register_taxonomy_for_object_type( ProfessionSector::NAME, PostType\Profession::NAME );
register_taxonomy_for_object_type( ProfessionAlternativeTitle::NAME, PostType\Profession::NAME );
register_taxonomy_for_object_type( ProfessionDuration::NAME, PostType\Profession::NAME );
register_taxonomy_for_object_type( ProfessionQualification::NAME, PostType\Profession::NAME );
register_taxonomy_for_object_type( ProfessionBilingualEducation::NAME, PostType\Profession::NAME );
register_taxonomy_for_object_type( EventSpeaker::NAME, PostType\Event::NAME );
register_taxonomy_for_object_type( EventAudience::NAME, PostType\Event::NAME );
register_taxonomy_for_object_type( EventTopic::NAME, PostType\Event::NAME );
register_taxonomy_for_object_type( EventStatus::NAME, PostType\Event::NAME );

register_taxonomy_for_object_type( District::NAME, PostType\School::NAME );
register_taxonomy_for_object_type( District::NAME, PostType\Office::NAME );
register_taxonomy_for_object_type( District::NAME, PostType\Apprenticeship::NAME );
register_taxonomy_for_object_type( District::NAME, PostType\TrialApprenticeship::NAME );
register_taxonomy_for_object_type( District::NAME, PostType\Event::NAME );
register_taxonomy_for_object_type( District::NAME, PostType\Organization::NAME );

register_taxonomy_for_object_type( Swissdoc::NAME, PostType\Profession::NAME );
register_taxonomy_for_object_type( Swissdoc::NAME, PostType\Apprenticeship::NAME );
register_taxonomy_for_object_type( Swissdoc::NAME, PostType\TrialApprenticeship::NAME );

register_taxonomy_for_object_type( ApprenticeshipOrganization::NAME, PostType\Apprenticeship::NAME );
register_taxonomy_for_object_type( ApprenticeshipOrganization::NAME, PostType\TrialApprenticeship::NAME );
register_taxonomy_for_object_type( ApprenticeshipOrganization::NAME, PostType\Organization::NAME );
register_taxonomy_for_object_type( ApprenticeshipOrganization::NAME, PostType\Event::NAME );

register_taxonomy_for_object_type( LinkDistrictOrganizationApprenticeship::NAME, PostType\Organization::NAME );
register_taxonomy_for_object_type( LinkDistrictOrganizationTrialApprenticeship::NAME, PostType\Organization::NAME );
register_taxonomy_for_object_type( LinkSwissdocOrganizationApprenticeship::NAME, PostType\Organization::NAME );
register_taxonomy_for_object_type( LinkSwissdocOrganizationTrialApprenticeship::NAME, PostType\Organization::NAME );

register_taxonomy_for_object_type( OrganizationEmail::NAME, PostType\Organization::NAME );

register_taxonomy_for_object_type( ApprenticeshipYear::NAME, PostType\Apprenticeship::NAME );

register_taxonomy_for_object_type( UserNationality::NAME, 'user' );
register_taxonomy_for_object_type( UserLanguage::NAME, 'user' );
}
```
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
}
},
"scripts": {
"analyze": "vendor/bin/phpstan analyze --no-progress"
"analyze": "vendor/bin/phpstan analyze --no-progress --memory-limit 1G"
}
}
8 changes: 5 additions & 3 deletions inc/Admin/AjaxAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @since 0.1.0
*/

declare( strict_types=1 );

namespace Required\Common\Admin;

use Required\Common\Contracts\Registrable;
Expand All @@ -16,7 +18,7 @@
*/
abstract class AjaxAction implements Registrable {

public const ACTION = 'ajax-action';
public const string ACTION = 'ajax-action';

/**
* Whether the Ajax action can be called unauthenticated.
Expand All @@ -32,7 +34,7 @@ abstract class AjaxAction implements Registrable {
*
* @param bool $allow Whether the Ajax action can be called unauthenticated.
*/
public function allow_unauthenticated( bool $allow ) {
public function allow_unauthenticated( bool $allow ): void {
$this->allow_unauthenticated = $allow;
}

Expand All @@ -41,7 +43,7 @@ public function allow_unauthenticated( bool $allow ) {
*
* @since 0.1.0
*/
abstract public function callback();
abstract public function callback(): void;

/**
* Registers the action.
Expand Down
Loading