Compare commits
No commits in common. "78e46c0ac4005ad374ea5edc60c57071e13601cf" and "eaa2f306af3d56a2a32a5baf2e20dbe2c9b7f45e" have entirely different histories.
78e46c0ac4
...
eaa2f306af
|
@ -1,67 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Plugin Name: Chykalophia Custom Select for Fluent Forms
|
|
||||||
* Description: An extension plugin for fluentforms that generates a dynamic select from specific custom post types.
|
|
||||||
* Source: https://fluentforms.com/docs/fluenform_rendering_field_data_select/
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The code that runs during plugin acivation and deactivation
|
|
||||||
*/
|
|
||||||
function cklph_ff_custom_select_activate_deactivate() {
|
|
||||||
flush_rewrite_rules();
|
|
||||||
}
|
|
||||||
|
|
||||||
register_activation_hook( __FILE__, 'cklph_ff_custom_select_activate_deactivate' );
|
|
||||||
register_deactivation_hook( __FILE__, 'cklph_ff_custom_select_activate_deactivate' );
|
|
||||||
|
|
||||||
/** A filter used in fluent forms to update a select field */
|
|
||||||
add_filter( 'fluentform_rendering_field_data_select', function ( $data, $form ) {
|
|
||||||
|
|
||||||
// Used to identify the form id for the dynamic select.
|
|
||||||
if ( $form->id != 7 ) {
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if the name attriibute of the select field in fluent forms is 'dynamic_dropdown'.
|
|
||||||
if ( \FluentForm\Framework\Helpers\ArrayHelper::get( $data, 'attributes.name' ) != 'dynamic_dropdown' ) {
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
$product_titles = get_product_titles();
|
|
||||||
$dropdown_data = array();
|
|
||||||
|
|
||||||
foreach ( $product_titles as $product_title ) {
|
|
||||||
$dropdown_data[] = array(
|
|
||||||
'label' => esc_attr( $product_title ),
|
|
||||||
'value' => esc_attr( $product_title ),
|
|
||||||
'calc_value' => '1',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// We are merging with existing options here.
|
|
||||||
$data['settings']['advanced_options'] = $dropdown_data;
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}, 10, 2);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom function to get the product titles of a CPT. For this example, gets product CPT's.
|
|
||||||
*
|
|
||||||
* @return String array of CPT titles
|
|
||||||
*/
|
|
||||||
function get_product_titles() {
|
|
||||||
$titles = array();
|
|
||||||
$args = array(
|
|
||||||
'post_type' => 'product',
|
|
||||||
'posts_per_page' => 10,
|
|
||||||
);
|
|
||||||
$loop = new WP_Query( $args );
|
|
||||||
while ( $loop->have_posts() ) {
|
|
||||||
$loop->the_post();
|
|
||||||
$titles[] = get_the_title();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $titles;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = apply_filters( 'fluentform_rendering_field_data_select', $data, $form );
|
|
Loading…
Reference in New Issue