Edit File by line
/home/barbar84/www/wp-conte.../plugins/ninja-fo.../includes/Admin
File: AddFormModal.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Add a button to tinyMCE editors when eidting posts/pages.
[2] Fix | Delete
*
[3] Fix | Delete
* @since 2.9.22
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
class NF_Admin_AddFormModal {
[7] Fix | Delete
[8] Fix | Delete
function __construct() {
[9] Fix | Delete
// Add a tinyMCE button to our post and page editor
[10] Fix | Delete
add_filter( 'media_buttons_context', array( $this, 'insert_form_tinymce_buttons' ) );
[11] Fix | Delete
}
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Output our tinyMCE field buttons
[15] Fix | Delete
*
[16] Fix | Delete
* @access public
[17] Fix | Delete
* @since 2.8
[18] Fix | Delete
* @return void
[19] Fix | Delete
*/
[20] Fix | Delete
public function insert_form_tinymce_buttons( $context ) {
[21] Fix | Delete
global $pagenow;
[22] Fix | Delete
[23] Fix | Delete
if( ! in_array( $pagenow, array( 'post.php', 'post-new.php' ) ) ){
[24] Fix | Delete
return $context;
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
$html = '<style>
[28] Fix | Delete
span.nf-insert-form {
[29] Fix | Delete
color:#888;
[30] Fix | Delete
font: 400 18px/1 dashicons;
[31] Fix | Delete
-webkit-font-smoothing: antialiased;
[32] Fix | Delete
-moz-osx-font-smoothing: grayscale;
[33] Fix | Delete
display: inline-block;
[34] Fix | Delete
width: 18px;
[35] Fix | Delete
height: 18px;
[36] Fix | Delete
vertical-align: text-top;
[37] Fix | Delete
margin: 0 2px 0 0;
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
.ui-autocomplete li {
[41] Fix | Delete
white-space: normal;
[42] Fix | Delete
}
[43] Fix | Delete
</style>';
[44] Fix | Delete
$html .= '<a href="#" class="button nf-insert-form"><span class="nf-insert-form dashicons dashicons-feedback"></span> ' . esc_html__( 'Add Form', 'ninja-forms' ) . '</a>';
[45] Fix | Delete
[46] Fix | Delete
wp_enqueue_script( 'nf-combobox', Ninja_Forms::$url . 'assets/js/lib/combobox.min.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-button', 'jquery-ui-autocomplete' ) );
[47] Fix | Delete
[48] Fix | Delete
wp_enqueue_script( 'jBox', Ninja_Forms::$url . 'assets/js/lib/jBox.min.js', array( 'jquery' ) );
[49] Fix | Delete
wp_enqueue_style( 'jBox', Ninja_Forms::$url . 'assets/css/jBox.css' );
[50] Fix | Delete
[51] Fix | Delete
// wp_enqueue_style( 'jquery-smoothness', NINJA_FORMS_URL .'css/smoothness/jquery-smoothness.css' );
[52] Fix | Delete
?>
[53] Fix | Delete
<div id="nf-insert-form-modal" style="display:none;">
[54] Fix | Delete
<p>
[55] Fix | Delete
<?php
[56] Fix | Delete
global $wpdb;
[57] Fix | Delete
$all_forms = $wpdb->get_results( 'SELECT id, title FROM `' . $wpdb->prefix
[58] Fix | Delete
. 'nf3_forms` ORDER BY title' );
[59] Fix | Delete
// $all_forms = Ninja_Forms()->form()->get_forms();
[60] Fix | Delete
// $first_option = __( 'Select a form or type to search', 'ninja-forms' );
[61] Fix | Delete
echo '<select class="nf-forms-combobox" id="nf-form-select" data-first-option="">';
[62] Fix | Delete
echo '<option value=""></option>';
[63] Fix | Delete
foreach( $all_forms as $form ) {
[64] Fix | Delete
$label = $form->title;
[65] Fix | Delete
$form_id = $form->id;
[66] Fix | Delete
if ( strlen( $label ) > 30 )
[67] Fix | Delete
$label = substr( $label, 0, 30 ) . '...';
[68] Fix | Delete
[69] Fix | Delete
echo '<option value="' . intval( $form_id ) . '">' . $label . ' - ID: ' . $form_id . '</option>';
[70] Fix | Delete
}
[71] Fix | Delete
echo '</select>';
[72] Fix | Delete
?>
[73] Fix | Delete
</p>
[74] Fix | Delete
<p>
[75] Fix | Delete
<input type="button" id="nf-insert-form" class="button-primary" value="<?php esc_attr_e( 'Insert', 'ninja-forms' )?>" />
[76] Fix | Delete
</p>
[77] Fix | Delete
</div>
[78] Fix | Delete
<?php
[79] Fix | Delete
add_action( 'admin_footer', array( $this, 'output_tinymce_button_js' ) );
[80] Fix | Delete
return $context . ' ' . $html;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Output our tinyMCE field buttons
[85] Fix | Delete
*
[86] Fix | Delete
* @access public
[87] Fix | Delete
* @since 2.8
[88] Fix | Delete
* @return void
[89] Fix | Delete
*/
[90] Fix | Delete
public function output_tinymce_button_js( $context ) {
[91] Fix | Delete
?>
[92] Fix | Delete
<script type="text/javascript">
[93] Fix | Delete
jQuery( document ).ready( function( $ ) {
[94] Fix | Delete
var jBox = jQuery( '.nf-insert-form' ).jBox( 'Modal', {
[95] Fix | Delete
title: '<?php esc_html_e( 'Insert Form', 'ninja-forms' )?>',
[96] Fix | Delete
position: {
[97] Fix | Delete
x: 'center',
[98] Fix | Delete
y: 'center'
[99] Fix | Delete
},
[100] Fix | Delete
closeButton: 'title',
[101] Fix | Delete
closeOnClick: 'overlay',
[102] Fix | Delete
closeOnEsc: true,
[103] Fix | Delete
// theme: 'TooltipBorder',
[104] Fix | Delete
content: jQuery( '#nf-insert-form-modal' ),
[105] Fix | Delete
onOpen: function() {
[106] Fix | Delete
jQuery( '.nf-forms-combobox' ).combobox();
[107] Fix | Delete
jQuery( this )[0].content.find( '.ui-autocomplete-input' ).attr( 'placeholder', '<?php esc_attr_e( 'Select a form or type to search', 'ninja-forms' )?>' )
[108] Fix | Delete
.css( 'margin-right', 0 );
[109] Fix | Delete
jQuery( this )[0].content.find( '.ui-combobox-button' ).css( 'position', 'relative' ).css( 'top', '-3px' );
[110] Fix | Delete
[111] Fix | Delete
jQuery( this )[0].content.find( 'ul.ui-autocomplete' ).css( 'max-height', '175px' ).css( 'overflow', 'scroll' );
[112] Fix | Delete
jQuery( this )[0].content.css( 'overflow', 'visible' );
[113] Fix | Delete
jQuery( this )[0].content.find( '.ui-icon-triangle-1-s' ).addClass( 'dashicons dashicons-arrow-down' ).css( 'margin-left', '-3px' );
[114] Fix | Delete
},
[115] Fix | Delete
onClose: function() {
[116] Fix | Delete
jQuery( '.nf-forms-combobox' ).combobox( 'destroy' );
[117] Fix | Delete
}
[118] Fix | Delete
});
[119] Fix | Delete
[120] Fix | Delete
jQuery( document ).on( 'click', '#nf-insert-form', function( e ) {
[121] Fix | Delete
e.preventDefault();
[122] Fix | Delete
var form_id = jQuery( '#nf-form-select' ).val();
[123] Fix | Delete
var shortcode = '[ninja_form id=' + form_id + ']';
[124] Fix | Delete
window.parent.send_to_editor( shortcode );
[125] Fix | Delete
jBox.close();
[126] Fix | Delete
jQuery( '#nf-form-select' ).val( '' );
[127] Fix | Delete
} );
[128] Fix | Delete
} );
[129] Fix | Delete
</script>
[130] Fix | Delete
[131] Fix | Delete
<?php
[132] Fix | Delete
}
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function