ralfhortt/wp-meta-box-contact

A WordPress meta box for contact data

4.1 2020-11-23 20:07 UTC

This package is auto-updated.

Last update: 2024-04-24 03:35:00 UTC


README

Installation

composer require ralfhortt/wp-meta-box-contact

Usage

new MetaBoxContact(
    array $screen = [],
    string $context = 'advanced',
    string $priority = 'default'
)

Serviceloader

use RalfHortt\MetaBoxContact\MetaBoxContact;

PluginFactory::create()
    ->addService(MetaBoxContact::class, ['page'], 'advanced', 'default')
    ->boot();

Standalone

use RalfHortt\MetaBoxContact\MetaBoxContact;

(new MetaBoxContact(['page'], 'advanced', 'default' ))->register();

Fields

  • Phone
  • Fax
  • Mobile
  • E-Mail
  • URL
<?php
$phone = get_post_meta( $post->ID, 'contact-phone', TRUE );
$fax = get_post_meta( $post->ID, 'contact-fax', TRUE );
$mobile = get_post_meta( $post->ID, 'contact-mobile', TRUE );
$email = get_post_meta( $post->ID, 'contact-email', TRUE );
$url = get_post_meta( $post->ID, 'contact-url', TRUE );

Hooks

Filter

  • wp-meta-box-contact/identifier - Change meta box id
  • wp-meta-box-contact/label - Change meta box label
  • wp-meta-box-contact/phone-{$postType} - Hide phone field for $postType
  • wp-meta-box-contact/fax-{$postType} - Hide fax field for $postType
  • wp-meta-box-contact/mobile-{$postType} - Hide mobile field for $postType
  • wp-meta-box-contact/email-{$postType} - Hide email field for $postType
  • wp-meta-box-contact/url-{$postType} - Hide url field for $postType

Example

<?php
(new MetaBoxContact(['page'], 'advanced', 'default' ))->register();
add_filter('wp-meta-box-contact-url-page', '__return_false');

Action

  • wp-meta-contact/before - Add fields before the phone field
  • wp-meta-contact/after - Add fields after the url field
  • wp-meta-contact/save - Save custom fields

Changelog

v4.1 - 2020-11-23

  • Update dependency

v4.0 - 2020-11-06

  • Update dependency
  • Added translation

v3.0 - 2020-11-02

  • Updated dependency

v.2.0.0 - 2020-01-15

  • Changed: Namespac ed hooks
  • Changed: Removed redundant hooks
  • Fixed: Broke URL field

v1.0.0 - 2020-01-14

  • Initial release