Skip to content

Commit

Permalink
Actually add all the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwelcher committed Jun 13, 2024
1 parent 4ff7e8f commit 3a5161b
Show file tree
Hide file tree
Showing 8 changed files with 18,739 additions and 0 deletions.
18 changes: 18 additions & 0 deletions plugins/acf-pods-bindings/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.{yml,yaml}]
indent_style = space
indent_size = 2
113 changes: 113 additions & 0 deletions plugins/acf-pods-bindings/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* Plugin Name: ACF/PODS bindings
* Description: Examples on creating custom bindings for ACF and PODS.
* Requires at least: 6.5
* Requires Plugins: gutenberg
* Requires PHP: 7.0
* Version: 0.1.0
* Author: The WordPress Contributors
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: custom-bindings
*
* @package twitch-streams
*/

add_action( 'init', 'twitch_register_block_bindings' );

function twitch_register_block_bindings() {

// Register post meta to the post type of "post"
register_post_meta(
'post',
'string_binding',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'default' => 'Message from meta',
)
);


// Block binding for Pods
register_block_bindings_source(
'twitch/pods',
array(
'label' => __( 'PODS', 'custom-bindings' ),
'get_value_callback' => 'twitch_user_data_bindings',
'uses_context' => [ 'postId', 'postType' ],
)
);

register_block_bindings_source(
'twitch/acf',
array(
'label' => __( 'Advanced Custom Fields', 'custom-bindings' ),
'get_value_callback' => 'twitch_acf_data_bindings',
'uses_context' => [ 'postId', 'postType' ],
)
);
}


function twitch_user_data_bindings( $source_args, $block_instance ) {
$post_id = $block_instance->context['postId'];
$post_type = $block_instance->context['postType'];
// Get Pods stuff
$product_fields = pods( $post_type, $post_id );

// If there are no PODs bail.
if ( ! $product_fields ) {
return null;
}
// Return the data based on the key argument.
$data = $product_fields->display( $source_args['key'] );
return $data;


// switch ( $source_args['key'] ) {
// case 'price':
// $price = $product_fields->field( 'price', null, true );
// return '<p>' . $price . '</p>';
// case 'sale_price':
// return $product_fields->field( $source_args['key'] );
// case 'release_date':
// return $product_fields->field( $source_args['key'] );
// default:
// return $product_fields->field( $source_args['key'] );
// }
}

function twitch_acf_data_bindings( $source_args, $block_instance ) {
$post_id = $block_instance->context['postId'];
$post_type = $block_instance->context['postType'];

// Get the ACF field
$value = get_field( $source_args['key'] );

// Don't do this. Check for things and be better
return $value;

}


// Enqueue filename from a plugin
add_action(
'enqueue_block_editor_assets',
function() {
$assets_file = plugin_dir_path( __FILE__ ) . '/build/index.asset.php';

if ( file_exists( $assets_file ) ) {
$assets = include $assets_file;
wp_enqueue_script(
'script-handle',
plugin_dir_url( __FILE__ ) . '/build/index.js',
$assets['dependencies'],
$assets['version'],
true
);
}
}
);
Loading

0 comments on commit 3a5161b

Please sign in to comment.