Skip to content

Instantly share code, notes, and snippets.

@kasparsb
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasparsb/e98f330dfd1518e5d0af to your computer and use it in GitHub Desktop.
Save kasparsb/e98f330dfd1518e5d0af to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Tavs plugins
*/
class Tavs_Plugins {
public static $ins;
/**
* Veidojam singletonu
*/
public static function init() {
if ( !isset( self::$ins ) ) {
$cn = __CLASS__;
self::$ins = new $cn;
}
return self::$ins;
}
public function __construct() {
// Definējam AJAX actions
// Šis action izpildīsies visiem
add_action( 'wp_ajax_getdata', array( $this, 'get_data' ) );
// Šis action izpildīsies tikai autorizētiem lietotājiem
add_action( 'wp_ajax_nopriv_getdata', array( $this, 'get_data' ) );
}
public function get_data() {
echo json_encode( array(
'param1': 'value1',
'param2': 'value2',
'param3': 'value3',
'param4': 'value4'
) );
exit; // !! Svarīgi taisīt exit
}
}
Tavs_Plugins::init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment