-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from joanrodas/repeatable
Repeatable
- Loading branch information
Showing
41 changed files
with
1,126 additions
and
1,105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace CPF\Endpoints; | ||
|
||
class Endpoints | ||
{ | ||
public function __construct() | ||
{ | ||
add_action('rest_api_init', [$this, 'register_endpoints']); | ||
} | ||
|
||
public function register_endpoints() | ||
{ | ||
register_rest_route('custom-product-fields/v1', '/getFields/(?P<product_id>\d+)', array( | ||
'methods' => 'GET', | ||
'callback' => [$this, 'get_section_fields'], | ||
'permission_callback' => '__return_true' //TODO: Permission | ||
)); | ||
} | ||
|
||
public function get_section_fields(\WP_REST_Request $request) | ||
{ | ||
global $wpdb; | ||
//$slug = $request->get_param('slug'); | ||
$product_id = $request->get_param('product_id'); | ||
// $results = $wpdb->get_results( | ||
// $wpdb->prepare("SELECT meta_key, meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key LIKE %s AND post_id = %d", [$slug . '%', $product_id]), | ||
// OBJECT_K | ||
// ); | ||
$results = get_post_meta($product_id); | ||
return [ | ||
'fields' => $results | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace CPF\Field; | ||
|
||
class AssociationField extends Field | ||
{ | ||
|
||
public function display($parent='') | ||
{ | ||
$key = $parent . '_' . $this->slug; | ||
$value = get_post_meta(get_the_ID(), '_' . $this->slug, true); | ||
if ($value == '') $value = $this->default_value; | ||
ob_start(); ?> | ||
<p class="form-field _<?= $this->type ?>_field "> | ||
<label for="_<?= $this->slug ?>"><?= $this->name ?></label> | ||
<input type="color" class="short" style="" name="_<?= $this->slug ?>" id="_<?= $this->slug ?>" value="<?= $value ?>" placeholder=""> | ||
</p> | ||
<?php echo ob_get_clean(); | ||
} | ||
|
||
public function display_complex($parent='') | ||
{ | ||
$key = $parent . '_' . $this->slug; | ||
ob_start(); ?> | ||
<p x-cloak class="form-field _<?= $this->type ?>_field "> | ||
<label for="_<?= $this->slug ?>"><?= $this->name ?></label> | ||
<input x-cloak type="color" class="short" style="" name="_<?= $this->slug . '[]' ?>" id="_<?= $this->slug ?>" :value="entries[tab] ? entries[tab]['<?= $this->slug ?>'] : '<?= $this->default_value ?>'" placeholder=""> | ||
</p> | ||
<?php echo ob_get_clean(); | ||
} | ||
|
||
public function save($product_id, $parent='') | ||
{ | ||
$key = $parent . '_' . $this->slug; | ||
if (isset($_POST[$key])) { // phpcs:ignore | ||
update_post_meta($product_id, $key, $_POST[$key]); // phpcs:ignore | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.