Commit da3768ee authored by Kevin Stover's avatar Kevin Stover

Adding common extension functionality to core.

parent df983c1e
......@@ -459,6 +459,57 @@ function ninja_forms_import_list_options(){
add_action( 'wp_ajax_ninja_forms_import_list_options', 'ninja_forms_import_list_options' );
/*
*
* Function that outputs a list of terms so that the user can exclude terms from a list selector.
*
* @since 2.2.51
* @return void
*/
function ninja_forms_list_terms_checkboxes( $field_id = '', $tax_name = '' ){
if ( $field_id == '' AND isset ( $_POST['field_id'] ) ) {
$field_id = $_POST['field_id'];
}
if ( $tax_name == '' AND isset ( $_POST['tax_name'] ) ) {
$tax_name = $_POST['tax_name'];
}
if ( $field_id != '' AND $tax_name != '' ) {
$field = ninja_forms_get_field_by_id( $field_id );
if ( isset ( $field['data']['exclude_terms'] ) ) {
$exclude_terms = $field['data']['exclude_terms'];
} else {
$exclude_terms = '';
}
$terms = get_terms( $tax_name, array( 'hide_empty' => false ) );
if ( is_array ( $terms ) AND !empty ( $terms ) ) {
?>
<h4><?php _e( 'Do not show these terms', 'ninja-forms' );?>:</h4>
<input type="hidden" name="ninja_forms_field_<?php echo $field_id;?>[exclude_terms]" value="">
<?php
foreach ( $terms as $term ) {
?>
<div>
<label>
<input type="checkbox" <?php checked( in_array ( $term->term_id, $exclude_terms ), true );?> name="ninja_forms_field_<?php echo $field_id;?>[exclude_terms][]" value="<?php echo $term->term_id;?>">
<?php echo $term->name;?>
</label>
</div>
<?php
}
}
}
if ( isset ( $_POST['from_ajax'] ) AND $_POST['from_ajax'] == 1 ) {
die();
}
}
add_action( 'wp_ajax_ninja_forms_list_terms_checkboxes', 'ninja_forms_list_terms_checkboxes' );
/*
*
* Function that outputs a calculation row
......
......@@ -3,56 +3,71 @@
*
* Function to add a dropdown of terms to the list field.
*
* @since 0.7
* @since 2.2.51
* @returns void
*/
/*
function ninja_forms_edit_field_list_term( $field_id ){
$add_field = apply_filters( 'ninja_forms_use_post_fields', false );
if ( !$add_field )
return false;
$field_row = ninja_forms_get_field_by_id( $field_id );
$field_type = $field_row['type'];
$field_data = $field_row['data'];
if( isset( $field_data['populate_term'] ) ){
$populate_term = $field_data['populate_term'];
}else{
$populate_term = '';
}
$form_row = ninja_forms_get_form_by_field_id( $field_id );
// Make sure that this function isn't already defined.
if ( !function_exists ( 'ninja_forms_edit_field_list_term' ) ) {
function ninja_forms_edit_field_list_term( $field_id ){
$add_field = apply_filters( 'ninja_forms_use_post_fields', false );
if ( !$add_field )
return false;
if( isset( $form_row['data']['post_type'] ) ){
$post_type = $form_row['data']['post_type'];
}else{
$post_type = '';
}
$field_row = ninja_forms_get_field_by_id( $field_id );
$field_type = $field_row['type'];
$field_data = $field_row['data'];
if( isset( $field_data['populate_term'] ) ){
$populate_term = $field_data['populate_term'];
}else{
$populate_term = '';
}
if ( $populate_term != '' ) {
$display = '';
} else {
$display = 'style="display:none;"';
}
$form_row = ninja_forms_get_form_by_field_id( $field_id );
if( isset( $form_row['data']['post_type'] ) ){
$post_type = $form_row['data']['post_type'];
}else{
$post_type = '';
}
if( $field_type == '_list' AND $post_type != '' ){
?>
<div>
<label>
<?php _e( 'Populate this with the term: ', 'ninja-forms-post-creation' );?>
<select name="ninja_forms_field_<?php echo $field_id;?>[populate_term]">
<option value=""><?php _e( '- None', 'ninja-forms-post-creation' );?></option>
<?php
// Get a list of terms registered to the post type set above and loop through them.
foreach ( get_object_taxonomies( $post_type ) as $tax_name ) {
if( $tax_name != 'post_tag' AND $tax_name != 'post_status' ){
$tax = get_taxonomy( $tax_name );
?>
<option value="<?php echo $tax_name;?>" <?php selected( $populate_term, $tax_name );?>><?php echo $tax->labels->name;?></option>
<?php
if( $field_type == '_list' AND $post_type != '' ){
?>
<div>
<hr>
<label>
<?php _e( 'Populate this with the taxonomy', 'ninja-forms' );?>:
</label>
<select name="ninja_forms_field_<?php echo $field_id;?>[populate_term]" class="ninja-forms-list-populate-term" rel="<?php echo $field_id;?>">
<option value=""><?php _e( '- None', 'ninja-forms-post-creation' );?></option>
<?php
// Get a list of terms registered to the post type set above and loop through them.
foreach ( get_object_taxonomies( $post_type ) as $tax_name ) {
if( $tax_name != 'post_tag' AND $tax_name != 'post_status' AND $tax_name != 'post_format' ){
$tax = get_taxonomy( $tax_name );
?>
<option value="<?php echo $tax_name;?>" <?php selected( $populate_term, $tax_name );?>><?php echo $tax->labels->name;?></option>
<?php
}
}
}
?>
</select>
</div>
<?php
?>
</select>
<div id="ninja_forms_field_<?php echo $field_id;?>_exclude_terms" <?php echo $display;?>>
<?php ninja_forms_list_terms_checkboxes( $field_id, $populate_term ); ?>
</div>
<br />
<hr>
</div>
<?php
}
}
}
add_action('ninja_forms_edit_field_after_registered', 'ninja_forms_edit_field_list_term', 9);
*/
\ No newline at end of file
add_action('ninja_forms_edit_field_after_registered', 'ninja_forms_edit_field_list_term', 9);
}
\ No newline at end of file
<?php
/*
function ninja_forms_register_sidebar_post_fields(){
$add_field = apply_filters( 'ninja_forms_use_post_fields', false );
if ( !$add_field )
......@@ -42,5 +42,4 @@ function ninja_forms_register_sidebar_post_fields(){
}
}
add_action( 'admin_init', 'ninja_forms_register_sidebar_post_fields' );
*/
\ No newline at end of file
add_action( 'admin_init', 'ninja_forms_register_sidebar_post_fields' );
\ No newline at end of file
......@@ -37,7 +37,7 @@ function ninja_forms_admin_js(){
$date_format = ninja_forms_date_to_datepicker($date_format);
wp_enqueue_script('ninja-forms-admin',
NINJA_FORMS_URL .'/js/min/ninja-forms-admin.min.js',
NINJA_FORMS_URL .'/js/dev/ninja-forms-admin.js',
array('jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable'));
wp_localize_script( 'ninja-forms-admin', 'ninja_forms_settings', array('date_format' => $date_format));
......
......@@ -3,53 +3,70 @@
*
* Function to hook into our field filter and add the selected terms if the field is set to populate_term.
*
* @since 2.2.51
* @return void
*/
/*
function ninja_forms_field_filter_populate_term( $data, $field_id ){
global $post;
$add_field = apply_filters( 'ninja_forms_use_post_fields', false );
if ( !$add_field )
return $data;
// Make sure that this function isn't already defined.
if ( !function_exists ( 'ninja_forms_field_filter_populate_term' ) ) {
function ninja_forms_field_filter_populate_term( $data, $field_id ){
global $post;
$field_row = ninja_forms_get_field_by_id( $field_id );
$field_type = $field_row['type'];
$field_data = $field_row['data'];
$add_field = apply_filters( 'ninja_forms_use_post_fields', false );
if ( !$add_field )
return $data;
if( $field_type == '_list' AND isset( $field_data['populate_term'] ) AND $field_data['populate_term'] != '' ){
// Set the selected option if we are editing a post.
if( is_object( $post ) ){
$selected_terms = get_the_terms( $post->ID, $field_data['populate_term'] );
}else{
$selected_term = '';
}
$field_row = ninja_forms_get_field_by_id( $field_id );
$field_type = $field_row['type'];
$field_data = $field_row['data'];
if( is_array( $selected_terms ) ){
foreach( $selected_terms as $term ){
$selected_term = $term->term_id;
break;
}
if ( isset ( $field_data['exclude_terms'] ) ) {
$exclude_terms = $field_data['exclude_terms'];
} else {
$selected_term = '';
$exclude_terms = array();
}
$tmp_array = array( array( 'label' => '- Select One', 'value' => '' ) );
$populate_term = $field_data['populate_term'];
$taxonomies = array( $populate_term );
$args = array(
'hide_empty' => false,
);
foreach( get_terms( $taxonomies, $args ) as $term ){
if( $selected_term == $term->term_id ){
$data['default_value'] = $term->term_id;
if( $field_type == '_list' AND isset( $field_data['populate_term'] ) AND $field_data['populate_term'] != '' ){
// Set the selected option if we are editing a post.
if( is_object( $post ) ){
$selected_terms = get_the_terms( $post->ID, $field_data['populate_term'] );
}else{
$selected_term = '';
}
$tmp_array[] = array( 'label' => $term->name, 'value' => $term->term_id );
if( is_array( $selected_terms ) ){
foreach( $selected_terms as $term ){
$selected_term = $term->term_id;
break;
}
} else {
$selected_term = '';
}
if ( $field_data['list_type'] == 'dropdown' ) {
$tmp_array = array( array( 'label' => __( '- Select One', 'ninja-forms' ), 'value' => '' ) );
} else {
$tmp_array = array();
}
$populate_term = $field_data['populate_term'];
$taxonomies = array( $populate_term );
$args = array(
'hide_empty' => false,
);
foreach( get_terms( $taxonomies, $args ) as $term ){
if( $selected_term == $term->term_id ){
$data['default_value'] = $term->term_id;
}
if ( !in_array( $term->term_id, $exclude_terms ) ) {
$tmp_array[] = array( 'label' => $term->name, 'value' => $term->term_id );
}
}
$data['list']['options'] = apply_filters( 'ninja_forms_list_terms', $tmp_array, $field_id );
$data['list_show_value'] = 1;
}
$data['list']['options'] = apply_filters( 'ninja_forms_list_terms', $tmp_array, $field_id );
$data['list_show_value'] = 1;
return $data;
}
return $data;
}
add_filter( 'ninja_forms_field', 'ninja_forms_field_filter_populate_term', 11, 2 );
*/
\ No newline at end of file
add_filter( 'ninja_forms_field', 'ninja_forms_field_filter_populate_term', 11, 2 );
}
\ No newline at end of file
<?php
/*
*
* Function used to store the attachment IDs being uploaded into a $_SESSION variable.
*
* This should affect files being uploaded by the media manager popup on the front-end.
* Becuase the post hasn't technically been created yet, when you insert an image or media, it doesn't automatically attach it to the post id.
*
* @since 0.8
* @returns $data
*/
function ninja_forms_set_attachment_to_change( $data, $attachment_id ){
if ( !isset ( $data['ninja_forms_upload_field'] ) OR !$data['ninja_forms_upload_field'] ) {
if ( !isset( $_SESSION['ninja_forms_change_attachment'] ) OR !is_array( $_SESSION['ninja_forms_change_attachment'] ) ) {
$_SESSION['ninja_forms_change_attachment'] = array();
}
$_SESSION['ninja_forms_change_attachment'][] = $attachment_id;
}
return $data;
}
add_filter( 'wp_update_attachment_metadata', 'ninja_forms_set_attachment_to_change', 10, 2 );
/*
*
* Function used to attach media uploads to the newly created post when a post is updated or created.
*
* @since 0.8
* @returns void
*/
function ninja_forms_attach_media_uploads( $post_id ){
if ( isset( $_SESSION['ninja_forms_change_attachment'] ) AND is_array( $_SESSION['ninja_forms_change_attachment'] ) ) {
foreach ( $_SESSION['ninja_forms_change_attachment'] as $attachment_id ) {
$post = get_post( $attachment_id, ARRAY_A );
if ( is_array( $post ) ) {
wp_update_post( array( 'ID' => $attachment_id, 'post_type' => 'attachment', 'post_parent' => $post_id ) );
}
}
$_SESSION['ninja_forms_change_attachment'] = '';
}
}
add_action( 'ninja_forms_create_post', 'ninja_forms_attach_media_uploads' );
add_action( 'ninja_forms_update_post', 'ninja_forms_attach_media_uploads' );
\ No newline at end of file
......@@ -3,72 +3,76 @@
*
* Function to filter the term IDS and return the term names.
*
* @since 2.2.45
* @since 2.2.51
* @returns void
*/
/*
function ninja_forms_filter_term_ids_for_name( $val, $field_id ){
$add_field = apply_filters( 'ninja_forms_use_post_fields', false );
if ( !$add_field )
return $val;
// Make sure that this function isn't already defined.
if ( !function_exists ( 'ninja_forms_filter_term_ids_for_name' ) ) {
function ninja_forms_filter_term_ids_for_name( $val, $field_id ){
$field_row = ninja_forms_get_field_by_id( $field_id );
if ( $field_row['type'] == '_list' ) {
if ( isset( $field_row['data']['populate_term'] ) ) {
$tax = $field_row['data']['populate_term'];
if ( !is_array( $val ) ) {
if ( strpos( $val, "," ) !== false ) {
$val = explode( ",", $val );
}
}
$add_field = apply_filters( 'ninja_forms_use_post_fields', false );
if ( !$add_field )
return $val;
if ( is_array( $val ) ) {
$tmp = '';
$x = 0;
foreach ( $val as $v ) {
$term_obj = get_term( $v, $tax );
if ( $term_obj AND !is_wp_error( $term_obj ) ) {
if ( $x == 0 ) {
$tmp .= $term_obj->name;
} else {
$tmp .= ', '.$term_obj->name;
$field_row = ninja_forms_get_field_by_id( $field_id );
if ( $field_row['type'] == '_list' ) {
if ( isset( $field_row['data']['populate_term'] ) ) {
$tax = $field_row['data']['populate_term'];
if ( !is_array( $val ) ) {
if ( strpos( $val, "," ) !== false ) {
$val = explode( ",", $val );
}
}
if ( is_array( $val ) ) {
$tmp = '';
$x = 0;
foreach ( $val as $v ) {
$term_obj = get_term( $v, $tax );
if ( $term_obj AND !is_wp_error( $term_obj ) ) {
if ( $x == 0 ) {
$tmp .= $term_obj->name;
} else {
$tmp .= ', '.$term_obj->name;
}
$x++;
}
$x++;
}
$val = $tmp;
} else {
$term_obj = get_term( $val, $tax );
if ( $term_obj AND !is_wp_error( $term_obj ) ) {
$val = $term_obj->name;
}
}
$val = $tmp;
} else {
$term_obj = get_term( $val, $tax );
if ( $term_obj AND !is_wp_error( $term_obj ) ) {
$val = $term_obj->name;
}
}
}
}
}
return $val;
}
return $val;
add_filter( 'ninja_forms_email_user_value', 'ninja_forms_filter_term_ids_for_name', 10, 2 );
add_filter( 'ninja_forms_export_sub_value', 'ninja_forms_filter_term_ids_for_name', 10, 2 );
}
add_filter( 'ninja_forms_email_user_value', 'ninja_forms_filter_term_ids_for_name', 10, 2 );
add_filter( 'ninja_forms_export_sub_value', 'ninja_forms_filter_term_ids_for_name', 10, 2 );
/*
*
* Function to filter the term IDS and return the term names for the backend submission editor.
*
* @since 2.2.45
* @since 2.2.51
* @returns void
*/
/*
function ninja_forms_filter_term_ids_for_name_sub_td( $val, $field_id, $sub_id ){
$add_field = apply_filters( 'ninja_forms_use_post_fields', false );
if ( !$add_field )
return $val;
return ninja_forms_filter_term_ids_for_name( $val, $field_id );
}
// Make sure that this function isn't already defined.
if ( !function_exists ( 'ninja_forms_filter_term_ids_for_name_sub_td' ) ) {
function ninja_forms_filter_term_ids_for_name_sub_td( $val, $field_id, $sub_id ){
$add_field = apply_filters( 'ninja_forms_use_post_fields', false );
if ( !$add_field )
return $val;
add_filter( 'ninja_forms_view_sub_td', 'ninja_forms_filter_term_ids_for_name_sub_td', 10, 3 );
*/
\ No newline at end of file
return ninja_forms_filter_term_ids_for_name( $val, $field_id );
}
add_filter( 'ninja_forms_view_sub_td', 'ninja_forms_filter_term_ids_for_name_sub_td', 10, 3 );
}
\ No newline at end of file
......@@ -3,31 +3,35 @@
*
* Function to hook into the post creation/update that will change the term based upon the selected term(s)
*
* @since 2.2.51
* @return void
*/
/*
function ninja_forms_pre_process_populate_term( $form_id ){
global $ninja_forms_processing;
$add_field = apply_filters( 'ninja_forms_use_post_fields', false );
if ( !$add_field )
return false;
// Make sure that this function isn't already defined.
if ( !function_exists ( 'ninja_forms_pre_process_populate_term' ) ) {
function ninja_forms_pre_process_populate_term( $form_id ){
global $ninja_forms_processing;
$add_field = apply_filters( 'ninja_forms_use_post_fields', false );
if ( !$add_field )
return false;
// Loop through our fields and see if we have a list field. If we do, check for the 'populate_term' setting.
$field_values = $ninja_forms_processing->get_all_fields();
if( is_array( $field_values ) ){
foreach( $field_values as $field_id => $user_value ){
$field_row = $ninja_forms_processing->get_field_settings( $field_id );
$field_type = $field_row['type'];
$field_data = $field_row['data'];
if( $field_type == '_list' AND isset( $field_data['populate_term'] ) AND $field_data['populate_term'] != '' ){
if( !is_array( $user_value ) ){
$user_value = array( $user_value );
// Loop through our fields and see if we have a list field. If we do, check for the 'populate_term' setting.
$field_values = $ninja_forms_processing->get_all_fields();
if( is_array( $field_values ) ){
foreach( $field_values as $field_id => $user_value ){
$field_row = $ninja_forms_processing->get_field_settings( $field_id );
$field_type = $field_row['type'];
$field_data = $field_row['data'];
if( $field_type == '_list' AND isset( $field_data['populate_term'] ) AND $field_data['populate_term'] != '' ){
if( !is_array( $user_value ) ){
$user_value = array( $user_value );
}
$ninja_forms_processing->update_form_setting( $field_data['populate_term'].'_terms', $user_value );
}
$ninja_forms_processing->update_form_setting( $field_data['populate_term'].'_terms', $user_value );
}
}
}
}
add_action( 'ninja_forms_pre_process', 'ninja_forms_pre_process_populate_term' );
*/
\ No newline at end of file
add_action( 'ninja_forms_pre_process', 'ninja_forms_pre_process_populate_term' );
}
\ No newline at end of file
......@@ -201,7 +201,6 @@ function ninja_forms_display_js($form_id, $local_vars = ''){
$password_mismatch = esc_html(stripslashes($plugin_settings['password_mismatch']));
$msg_format = $plugin_settings['msg_format'];
$msg_format = 'inline';
wp_enqueue_script( 'ninja-forms-display',
NINJA_FORMS_URL .'/js/dev/ninja-forms-display.js',
array( 'jquery', 'jquery-form' ) );
......
<?php
function ninja_forms_register_field_post_content(){
$add_field = apply_filters( 'ninja_forms_use_post_fields', false );
if ( !$add_field )
return false;
$args = array(
'name' => 'Content',
'edit_options' => array(
array(
'type' => 'checkbox', //What type of input should this be?
'name' => 'content_rte', //What should it be named. This should always be a programmatic name, not a label.
'label' => __('Show Rich Text Editor?', 'ninja-forms'),
'width' => 'wide',
//'class' => 'widefat', //Additional classes to be added to the input element.
),
array(
'type' => 'rte', //What type of input should this be?
'name' => 'default_value', //What should it be named. This should always be a programmatic name, not a label.
'label' => __('Default Value', 'ninja-forms'),
'width' => 'wide',
'class' => 'widefat', //Additional classes to be added to the input element.
/*
*
* This field handles post content
*
* @since 2.2.51
* @return void
*/
// For backwards compatibilty, make sure that this function doesn't already exist.
if ( !function_exists ( 'ninja_forms_register_field_post_content') ) {
function ninja_forms_register_field_post_content(){
$add_field = apply_filters( 'ninja_forms_use_post_fields', false );
if ( !$add_field )
return false;
$args = array(
'name' => 'Content',
'edit_options' => array(
array(
'type' => 'checkbox', //What type of input should this be?
'name' => 'content_rte', //What should it be named. This should always be a programmatic name, not a label.
'label' => __('Show Rich Text Editor?', 'ninja-forms'),
'width' => 'wide',
//'class' => 'widefat', //Additional classes to be added to the input element.
),
array(
'type' => 'rte', //What type of input should this be?
'name' => 'default_value', //What should it be named. This should always be a programmatic name, not a label.
'label' => __('Default Value', 'ninja-forms'),
'width' => 'wide',
'class' => 'widefat', //Additional classes to be added to the input element.
),
),
),
'display_function' => 'ninja_forms_field_post_content_display',
'group' => 'create_post',
'edit_label' => true,
'edit_label_pos' => true,
'edit_req' => true,
'edit_custom_class' => true,
'edit_help' => true,
'edit_meta' => false,
'sidebar' => 'post_fields',
'edit_conditional' => true,
'conditional' => array(
'value' => array(
'type' => 'text',
'display_function' => 'ninja_forms_field_post_content_display',
'group' => 'create_post',
'edit_label' => true,
'edit_label_pos' => true,
'edit_req' => true,
'edit_custom_class' => true,
'edit_help' => true,
'edit_meta' => false,
'sidebar' => 'post_fields',
'edit_conditional' => true,
'conditional' => array(
'value' => array(
'type' => 'text',
),
),
),
'limit' => 1,
//'save_sub' => false,
'pre_process' => 'ninja_forms_field_post_content_pre_process',
);
if( function_exists( 'ninja_forms_register_field' ) ){
ninja_forms_register_field('_post_content', $args);
'limit' => 1,
//'save_sub' => false,
'pre_process' => 'ninja_forms_field_post_content_pre_process',
);
if( function_exists( 'ninja_forms_register_field' ) ){
ninja_forms_register_field('_post_content', $args);
}
add_action( 'ninja_forms_pre_process', 'ninja_forms_post_content_pre_process' , 9 );
add_action( 'ninja_forms_pre_process', 'ninja_forms_post_content_do_shortcode' , 20 );
}
add_action( 'ninja_forms_pre_process', 'ninja_forms_post_content_pre_process' , 9 );
add_action( 'ninja_forms_pre_process', 'ninja_forms_post_content_do_shortcode' , 20 );
}
add_action('init', 'ninja_forms_register_field_post_content');
add_action('init', 'ninja_forms_register_field_post_content');
function ninja_forms_field_post_content_display($field_id, $data){
if(isset($data['default_value'])){
$default_value = $data['default_value'];
}else{
$default_value = '';
}
function ninja_forms_field_post_content_display($field_id, $data){
if(isset($data['default_value'])){
$default_value = $data['default_value'];
}else{
$default_value = '';
}
$default_value = htmlspecialchars_decode( $default_value );
$default_value = htmlspecialchars_decode( $default_value );
if(isset($data['content_rte'])){
$content_rte = $data['content_rte'];
}else{
$content_rte = 0;
}
if(isset($data['class'])){
$class = $data['class'];
}else{
$class = '';
}
if(isset($data['content_rte'])){
$content_rte = $data['content_rte'];
}else{
$content_rte = 0;
}
if(isset($data['class'])){
$class = $data['class'];
}else{
$class = '';
}
if($content_rte == 1){
wp_editor( $default_value, 'ninja_forms_field_'.$field_id );
}else{
?>
<textarea name="ninja_forms_field_<?php echo $field_id;?>" id="ninja_forms_field_<?php echo $field_id;?>" class="<?php echo $class;?>" rel="<?php echo $field_id;?>" ><?php echo $default_value;?></textarea>
<?php
if($content_rte == 1){
wp_editor( $default_value, 'ninja_forms_field_'.$field_id );
}else{
?>
<textarea name="ninja_forms_field_<?php echo $field_id;?>" id="ninja_forms_field_<?php echo $field_id;?>" class="<?php echo $class;?>" rel="<?php echo $field_id;?>" ><?php echo $default_value;?></textarea>