Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Fixes empty dropdown in TinyMCE & updates from Wordpress directory #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: mailplus
Donate link: https://www.spotler.com/software
Tags: forms, mailplus
Requires at least: 3.9
Tested up to: 4.8
Requires at least: 3.3
Tested up to: 4.9
Stable tag: trunk
License: Modified BSD License

Expand Down
42 changes: 16 additions & 26 deletions mailplusforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,17 @@
add_action('init', 'mpforms_addbuttons');
add_action('admin_init', 'mpforms_admin_init');
add_action('send_headers', 'mpforms_handle_headers');
add_action('template_redirect', 'mpforms_get_forms');

add_shortcode('mailplusform', 'mpforms_shortcode');

add_filter( 'query_vars', 'add_query_vars_filter' );

function add_query_vars_filter( $vars ){
$vars[] = "mpforms_get_forms";
return $vars;
}

add_action('wp_ajax_mpforms_get_forms', 'mpforms_get_forms');

function mpforms_get_forms()
{
if (get_query_var('mpforms_get_forms') != 1) {
return;
}

if (!is_user_logged_in()){
if (!current_user_can('edit_posts') && !current_user_can('edit_pages')){
die('You must be logged in to access this script.');
}

header('Content-type: application/json');
$api = new mailplus_forms_api();
$forms = $api->get_forms();
Expand All @@ -80,7 +70,7 @@ function mpforms_get_forms()
}

echo json_encode($result);
exit;
wp_die();
}

function mpforms_plugin_menu() {
Expand Down Expand Up @@ -240,19 +230,19 @@ function mpforms_add_tinymce_plugin($plugins) {

function mp_forms_repair_post($data) {
// combine rawpost and $_POST ($data) to rebuild broken arrays in $_POST
$rawpost = "&".file_get_contents("php://input");
while(list($key,$value)= each($data)) {
$pos = preg_match_all("/&".$key."=([^&]*)/i",$rawpost, $regs, PREG_PATTERN_ORDER);
if((!is_array($value)) && ($pos > 1)) {
$qform[$key] = array();
for($i = 0; $i < $pos; $i++) {
$qform[$key][$i] = urldecode($regs[1][$i]);
}
} else {
$qform[$key] = $value;
$rawpost = "&".file_get_contents("php://input");
foreach ($data as $key => $value) {
$pos = preg_match_all("/&".$key."=([^&]*)/i",$rawpost, $regs, PREG_PATTERN_ORDER);
if((!is_array($value)) && ($pos > 1)) {
$qform[$key] = array();
for($i = 0; $i < $pos; $i++) {
$qform[$key][$i] = urldecode($regs[1][$i]);
}
} else {
$qform[$key] = $value;
}
return $qform;
}
return $qform;
}

function mpforms_get_post_url($formid) {
Expand Down Expand Up @@ -306,7 +296,7 @@ function mpforms_handle_headers()

/* SHORTCODE OPTIONS */
function mpforms_shortcode($atts) {
global $mpforms_data;
global $mpforms_data;
extract( shortcode_atts( array(
'formid' => '',
'ssl' => 'false',
Expand Down
9 changes: 5 additions & 4 deletions tinymce/editor_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ tinymce.PluginManager.add('mpforms', function(editor, url) {
});

var listbox = win.find('#mpforms_select')[0];
jQuery.getJSON('/?mpforms_get_forms=1', function(data) {
jQuery.getJSON(ajaxurl + '?action=mpforms_get_forms', function(data) {
listbox.menu = null;
jQuery.each(data, function(index, item){
listbox.settings.values.push({text: item.name, value: item.id});
});
listbox.settings.values.push({text: item.name, value: item.id});
});

});
});

function onSubmitForm() {
var data = win.toJSON();
Expand Down