PHP code example of gebruederheitz / wp-easy-post-options
1. Go to this page and download the library: Download gebruederheitz/wp-easy-post-options library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gebruederheitz / wp-easy-post-options example snippets
use Gebruederheitz\Wordpress\PageOrPostOption\AbstractMetabox;
class SocialLinksMetabox extends AbstractMetabox
{
public function getKey(): string
{
// give this metabox a unique identifier
return 'ghwp-social-links';
}
public function getTitle(): string
{
// This title will be visible to the user
return 'Social Links';
}
}
use Gebruederheitz\Wordpress\PageOrPostOption\AbstractMetabox;
class SocialLinksMetabox extends AbstractMetabox
{
// Not available on pages, but on all regular posts and all posts of the
// custom "my-custom-post-type" type.
protected static $postTypes = ['post', 'my-custom-post-type'];
public function getKey(): string
{
return 'ghwp-social-links';
}
public function getTitle(): string
{
return 'Social Links';
}
}
use Gebruederheitz\Wordpress\PageOrPostOption\AbstractMetabox;
class SocialLinksMetabox extends AbstractMetabox
{
protected static $context = 'advanced';
public function getKey(): string
{
return 'ghwp-social-links';
}
public function getTitle(): string
{
return 'Social Links';
}
}
use Gebruederheitz\Wordpress\PageOrPostOption\AbstractPageOrPostOption;
class FacebookUrlPageOption extends AbstractPageOrPostOption
{
/**
* @var bool
* @optional
* You can set this to `true` to automatically have the "wp-link" script
* enqueued – otherwise you can leave it out.
*/
protected static $hasLinks = false;
/**
* @var string
* @ if you dont' plan to override the
* default render method.
*/
protected static $inputLabel = 'Facebook URL';
}
use Gebruederheitz\Wordpress\PageOrPostOption\NonceField;
$socialBox = new SocialLinksMetaBox();
new FacebookUrlPageOption($socialBox, NonceField::getInstance());
use Gebruederheitz\Wordpress\PageOrPostOption\AbstractPageOrPostOption;
use Gebruederheitz\Wordpress\MetaFields\MetaForms;
class BackgroundImagePageOption extends AbstractPageOrPostOption
{
protected static $key = 'ghwp-background-image';
// We define a second key for convenience
protected static $urlKey = 'ghwp-background-image-url';
protected static $inputLabel = 'Background image';
/**
* Called when the meta box is being rendered in WP admin
*/
public function render(WP_Post $post): void
{
// make sure you call the nonce field's render method at least once for
// every page containing page options
$this->nonceField->render();
// we retrieve the original value
$rawValue = $this->getValue($post->ID);
$value = is_string($rawValue)
? json_decode($rawValue)
: (object) ['id' => '', 'url' => ''];
// ...and then render our input field. You could use the MetaForms library
// from gebruederheitz/wp-meta-fields, output some raw HTML or
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.