PHP code example of moderntribe / square1-object-meta
1. Go to this page and download the library: Download moderntribe/square1-object-meta 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/ */
moderntribe / square1-object-meta example snippets
namespace Tribe\Example\Object_Meta;
use Tribe\Libs\ACF;
class Example extends ACF\ACF_Meta_Group {
public const NAME = 'example_meta';
public const ONE = 'example_object_meta_one';
public const TWO = 'example_object_meta_two';
public function get_keys() {
return [
self::ONE,
self::TWO,
];
}
public function get_group_config() {
$group = new ACF\Group( self::NAME, $this->object_types );
$group->set( 'title', __( 'Example Object Meta', 'tribe' ) );
$group->add_field( $this->get_field_one() );
$group->add_field( $this->get_field_two() );
return $group->get_attributes();
}
private function get_field_one() {
$field = new ACF\Field( self::NAME . '_' . self::ONE );
$field->set_attributes( [
'label' => __( 'Example Object Meta #1', 'tribe' ),
'name' => self::ONE,
'type' => 'text',
] );
return $field;
}
private function get_field_two() {
$field = new ACF\Field( self::NAME . '_' . self::TWO );
$field->set_attributes( [
'label' => __( 'Example Object Meta #2', 'tribe' ),
'name' => self::TWO,
'type' => 'text',
] );
return $field;
}
}
declare( strict_types=1 );
namespace Tribe\Example\Object_Meta;
use DI;
use Psr\Container\ContainerInterface;
use Tribe\Libs\Container\Definer_Interface;
use Tribe\Example\Settings;
class Object_Meta_Definer implements Definer_Interface {
public const GROUPS = 'meta.groups';
public function define(): array {
return [
\Tribe\Libs\Object_Meta\Object_Meta_Definer::GROUPS => DI\add( [
DI\get( Example::class ),
] ),
Example::class => static function ( ContainerInterface $container ) {
return new Example( [ // use one or more of the following options
// can be added to post types
'post_types' => [ 'page', 'post' ],
// or can be added to taxonomies
'taxonomies' => [ 'category' ],
// or can be added to settings screens
'settings_pages' => [ $container->get( Settings\General::class )->get_slug() ],
// or can be added to user profiles
'users' => true,
] );
},
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.