Last active
August 29, 2015 14:12
-
-
Save kasparsb/e98f330dfd1518e5d0af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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