Hej
Jeg er ved at flytte min side over på wordpress og har en funktion som jeg er ved at konvertere til et wordpress plugin, men jeg kan ikke få den til at overføre plugin stien til mit javascript(ajax) php kald.
selve pluginet
- <?php
- /*
- Plugin Name: Domain Checker
- Plugin URI: http://cube-it.dk
- Description: Whois search for domains.
- Version: 1.0
- Author: Jesper Have
- Author URI: http://Jdh.dk
- */
-
- error_reporting(E_ALL);
- add_action("widgets_init", array('domain_check', 'register'));
- class domain_check {
- function activate(){
- $data = array( 'title' => 'Domain seaech' /* ,'option2' => 55 */);
- if ( ! get_option('domain_check')){
- add_option('domain_check' , $data);
- } else {
- update_option('domain_check' , $data);
- }
- }
- function deactivate(){
- delete_option('domain_check');
- }
- function control(){
- $data = get_option('domain_check');
- ?>
- <p><label for="domain_check_title">Title:</label><input class="widefat" name="domain_check_title" type="text" value="<?php echo $data['title']; ?>" /></p>
- <?php
- if (isset($_POST['domain_check_title'])){
- $data['title'] = attribute_escape($_POST['domain_check_title']);
- update_option('domain_check', $data);
- }
- }
- function widget($args){
- function run_js(){
- // LOAD JS
- wp_enqueue_script('domain_check', plugins_url('jq-code.js', __FILE__));
- // ADD SOM JS VARIABLES
- wp_localize_script( 'domain_chec', 'domain_chec_params', array(
- plugins_url('process.php', __FILE__) => "url"
- ) );
- }
- add_action( 'domain_check', 'run_js' );
- $data = get_option('domain_check');
- echo $args['before_widget'];
- echo $args['before_title'] . $data['title'] . $args['after_title'];
- ?>
- <form method="post" action="" id="form">
- <div style="display:inline;">
- <input type="text" autocomplete="off" id="Search" class="text-input-domain" name="domain">
- <input type="submit" id="Check-submit" class="button-domain" value="Søg">
- </div>
- </form>
- <div id="loading" style="display: none">Vent venligst...<img src="<?php print plugins_url('img/load.gif', __FILE__); ?>"></img></div>
- <div id="results" align="left"></div>
- <?php
- echo $args['after_widget'];
- }
- function register(){
- register_sidebar_widget('Domain check', array('domain_check', 'widget'));
- register_widget_control('Domain check', array('domain_check', 'control'));
- }
- }
- ?>
min jq-code.js
- $(document).ready(function() {
-
- var loading;
- var results;
-
- var form = document.getElementById('form');
- var loading = document.getElementById('loading');
- var results = document.getElementById('results');
- var plugin_url = domain_chec_params.url;
-
- $('#form').submit( function() {
-
- if($('#Search').val() == "")
- {alert('Indtast venlist et domænenavn');return false;}
-
- results.style.display = 'none';
- $('#results').html('');
- loading.style.display = 'inline';
-
- $.post(plugin_url.'?domain=' + escape($('#Search').val()),{
- }, function(response){
-
- results.style.display = 'block';
- $('#results').html(unescape(response));
- loading.style.display = 'none';
- });
-
- return false;
- });
-
- });
Indlæg senest redigeret d. 05.06.2012 19:34 af Bruger #879