Advertisement
luisfcastilla

Ejemplo de plugin con Cron

Oct 26th, 2020
2,164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Plugin Name: P&P Filemaker Integration
  5.  * Description: Maneja la sincronización entre Filemaker y el perfil de los usuarios
  6.  * Version:     0.0.1
  7.  * Author:      Felipe Castilla
  8.  */
  9.  
  10. if ( ! defined( 'ABSPATH' ) ) {
  11.     exit; // Exit if accessed directly.
  12. }
  13.  
  14. // Define constants.
  15. define( 'FILEMAKER_INTEGRATION_PLUGIN_VERSION', '0.0.1' );
  16. define( 'FILEMAKER_INTEGRATION_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
  17.  
  18. // Include the main class.
  19. require FILEMAKER_INTEGRATION_PLUGIN_DIR . '/FileMaker.php';
  20.  
  21. // Main instance of plugin.
  22. function FileMakerInit() {
  23.     return \PyP\FileMaker\FileMaker::getInstance();
  24. }
  25.  
  26. /*
  27.  * Enqueue Scripts for user-edit page
  28.  */
  29. function enqueueUserEditScript($hook) {
  30.     if ('user-edit.php' !== $hook) {
  31.         return;
  32.     }
  33.     wp_enqueue_script('pyp-rut-validator', plugin_dir_url(__FILE__) . '/assets/rut.js', null,FILEMAKER_INTEGRATION_PLUGIN_VERSION,true);
  34.     wp_enqueue_script('pyp-user-edit', plugin_dir_url(__FILE__) . '/assets/user-edit.js', array('jquery'),FILEMAKER_INTEGRATION_PLUGIN_VERSION,true);
  35. }
  36. add_action('admin_enqueue_scripts', 'enqueueUserEditScript');
  37.  
  38.  
  39. /*
  40.  * On plugin activation schedule our bot
  41.  */
  42. register_activation_hook( __FILE__, 'scheduleBot' );
  43. function scheduleBot(){
  44.     $timestamp = wp_next_scheduled( 'pyp_scan_filemaker_files' );
  45.     if( $timestamp == false ){
  46.         wp_schedule_event( time(), 'each_hour', 'pyp_scan_filemaker_files' );
  47.     }
  48. }
  49. register_deactivation_hook( __FILE__, 'descheduleBot' );
  50. function descheduleBot(){
  51.     wp_clear_scheduled_hook( 'pyp_scan_filemaker_files' );
  52. }
  53.  
  54. /*
  55.  * To add a new schedule time interval (each hour)
  56.  */
  57. add_filter( 'cron_schedules', 'pyp_each_hour_schedule' );
  58. function pyp_each_hour_schedule( $schedules ) {
  59.     $schedules['each_hour'] = array(
  60.         'interval' => 60 * MINUTE_IN_SECONDS,
  61.         'display' => __( 'each hour', 'pyp-filemaker-integration-domain' )
  62.     );
  63.     return $schedules;
  64. }
  65.  
  66.  
  67. // Global for backwards compatibility.
  68. $GLOBALS['FileMaker'] = FileMakerInit();
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement