Changeset 2787827
- Timestamp:
- 09/20/2022 08:11:42 PM (4 years ago)
- Location:
- wp-trigger-github
- Files:
-
- 4 edited
- 1 copied
-
tags/1.3.0 (copied) (copied from wp-trigger-github/trunk)
-
tags/1.3.0/readme.txt (modified) (1 diff)
-
tags/1.3.0/wp-trigger-github.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/wp-trigger-github.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-trigger-github/tags/1.3.0/readme.txt
r2609892 r2787827 5 5 License URI: https://www.gnu.org/licenses/gpl-2.0.html 6 6 Stable tag: trunk 7 Tested up to: 5. 8.17 Tested up to: 5.9.4 8 8 9 9 == Description == -
wp-trigger-github/tags/1.3.0/wp-trigger-github.php
r2609892 r2787827 8 8 Plugin URI: https://github.com/gglukmann/wp-trigger-github 9 9 Description: Save or update action triggers Github repository_dispatch action 10 Version: 1. 2.410 Version: 1.3.0 11 11 Author: Gert Glükmann 12 12 Author URI: https://github.com/gglukmann … … 25 25 { 26 26 add_action('admin_init', [$this, 'generalSettingsSection']); 27 add_action(' save_post', [$this, 'runHook'], 10, 3);27 add_action('wp_after_insert_post', [$this, 'runHook'], 10, 3); 28 28 add_action('wp_dashboard_setup', [$this, 'buildDashboardWidget']); 29 29 } … … 33 33 flush_rewrite_rules(); 34 34 $this->generalSettingsSection(); 35 add_option('wp_trigger_github_last_triggered_timestamp'); 35 36 } 36 37 … … 38 39 { 39 40 flush_rewrite_rules(); 41 delete_option('wp_trigger_github_last_triggered_timestamp'); 42 } 43 44 function getLastTriggeredTimestamp(){ 45 return get_option('wp_trigger_github_last_triggered_timestamp'); 46 } 47 48 function triggerGithubRepositoryDispatch(){ 49 $github_token = get_option('ga_option_token'); 50 $github_username = get_option('ga_option_username'); 51 $github_repo = get_option('ga_option_repo'); 52 53 if ($github_token && $github_username && $github_repo) { 54 $url = 'https://api.github.com/repos/' . $github_username . '/' . $github_repo . '/dispatches'; 55 $args = array( 56 'method' => 'POST', 57 'body' => json_encode(array( 58 'event_type' => 'wordpress', 59 )), 60 'headers' => array( 61 'Accept' => 'application/vnd.github.v3+json', 62 'Content-Type' => 'application/json', 63 'Authorization' => 'token ' . $github_token 64 ), 65 ); 66 67 wp_remote_post($url, $args); 68 } 40 69 } 41 70 42 71 function runHook($post_id) 43 72 { 73 $post = get_post($post_id); 74 44 75 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; 45 76 if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) return; 46 77 47 $github_token = get_option('ga_option_token'); 48 $github_username = get_option('ga_option_username'); 49 $github_repo = get_option('ga_option_repo'); 50 51 if ($github_token && $github_username && $github_repo) { 52 $url = 'https://api.github.com/repos/' . $github_username . '/' . $github_repo . '/dispatches'; 53 $args = array( 54 'method' => 'POST', 55 'body' => json_encode(array( 56 'event_type' => 'wordpress' 57 )), 58 'headers' => array( 59 'Accept' => 'application/vnd.github.v3+json', 60 'Content-Type' => 'application/json', 61 'Authorization' => 'token ' . $github_token 62 ), 63 ); 64 65 wp_remote_post($url, $args); 78 if ($this->getLastTriggeredTimestamp() == false){ 79 update_option('wp_trigger_github_last_triggered_timestamp', $post->post_modified); 80 $this->triggerGithubRepositoryDispatch(); 81 } else { 82 try{ 83 $modified_at_time = new DateTime($post->post_modified); 84 $last_triggered_time = new DateTime($this->getLastTriggeredTimestamp()); 85 } catch(Exception $e){ 86 update_option('wp_trigger_github_last_triggered_timestamp', $post->post_modified); 87 $this->triggerGithubRepositoryDispatch(); 88 } 89 90 // time since last trigger in seconds 91 $duration_since_last_trigger = ($last_triggered_time->diff($modified_at_time, true))->s; 92 93 // only trigger GitHub action if it's been more than five seconds since the last one was triggered 94 if ($duration_since_last_trigger > 5){ 95 $this->triggerGithubRepositoryDispatch(); 96 update_option('wp_trigger_github_last_triggered_timestamp', $post->post_modified); 97 } 66 98 } 99 100 67 101 } 68 102 -
wp-trigger-github/trunk/readme.txt
r2609892 r2787827 5 5 License URI: https://www.gnu.org/licenses/gpl-2.0.html 6 6 Stable tag: trunk 7 Tested up to: 5. 8.17 Tested up to: 5.9.4 8 8 9 9 == Description == -
wp-trigger-github/trunk/wp-trigger-github.php
r2609892 r2787827 8 8 Plugin URI: https://github.com/gglukmann/wp-trigger-github 9 9 Description: Save or update action triggers Github repository_dispatch action 10 Version: 1. 2.410 Version: 1.3.0 11 11 Author: Gert Glükmann 12 12 Author URI: https://github.com/gglukmann … … 25 25 { 26 26 add_action('admin_init', [$this, 'generalSettingsSection']); 27 add_action(' save_post', [$this, 'runHook'], 10, 3);27 add_action('wp_after_insert_post', [$this, 'runHook'], 10, 3); 28 28 add_action('wp_dashboard_setup', [$this, 'buildDashboardWidget']); 29 29 } … … 33 33 flush_rewrite_rules(); 34 34 $this->generalSettingsSection(); 35 add_option('wp_trigger_github_last_triggered_timestamp'); 35 36 } 36 37 … … 38 39 { 39 40 flush_rewrite_rules(); 41 delete_option('wp_trigger_github_last_triggered_timestamp'); 42 } 43 44 function getLastTriggeredTimestamp(){ 45 return get_option('wp_trigger_github_last_triggered_timestamp'); 46 } 47 48 function triggerGithubRepositoryDispatch(){ 49 $github_token = get_option('ga_option_token'); 50 $github_username = get_option('ga_option_username'); 51 $github_repo = get_option('ga_option_repo'); 52 53 if ($github_token && $github_username && $github_repo) { 54 $url = 'https://api.github.com/repos/' . $github_username . '/' . $github_repo . '/dispatches'; 55 $args = array( 56 'method' => 'POST', 57 'body' => json_encode(array( 58 'event_type' => 'wordpress', 59 )), 60 'headers' => array( 61 'Accept' => 'application/vnd.github.v3+json', 62 'Content-Type' => 'application/json', 63 'Authorization' => 'token ' . $github_token 64 ), 65 ); 66 67 wp_remote_post($url, $args); 68 } 40 69 } 41 70 42 71 function runHook($post_id) 43 72 { 73 $post = get_post($post_id); 74 44 75 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; 45 76 if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) return; 46 77 47 $github_token = get_option('ga_option_token'); 48 $github_username = get_option('ga_option_username'); 49 $github_repo = get_option('ga_option_repo'); 50 51 if ($github_token && $github_username && $github_repo) { 52 $url = 'https://api.github.com/repos/' . $github_username . '/' . $github_repo . '/dispatches'; 53 $args = array( 54 'method' => 'POST', 55 'body' => json_encode(array( 56 'event_type' => 'wordpress' 57 )), 58 'headers' => array( 59 'Accept' => 'application/vnd.github.v3+json', 60 'Content-Type' => 'application/json', 61 'Authorization' => 'token ' . $github_token 62 ), 63 ); 64 65 wp_remote_post($url, $args); 78 if ($this->getLastTriggeredTimestamp() == false){ 79 update_option('wp_trigger_github_last_triggered_timestamp', $post->post_modified); 80 $this->triggerGithubRepositoryDispatch(); 81 } else { 82 try{ 83 $modified_at_time = new DateTime($post->post_modified); 84 $last_triggered_time = new DateTime($this->getLastTriggeredTimestamp()); 85 } catch(Exception $e){ 86 update_option('wp_trigger_github_last_triggered_timestamp', $post->post_modified); 87 $this->triggerGithubRepositoryDispatch(); 88 } 89 90 // time since last trigger in seconds 91 $duration_since_last_trigger = ($last_triggered_time->diff($modified_at_time, true))->s; 92 93 // only trigger GitHub action if it's been more than five seconds since the last one was triggered 94 if ($duration_since_last_trigger > 5){ 95 $this->triggerGithubRepositoryDispatch(); 96 update_option('wp_trigger_github_last_triggered_timestamp', $post->post_modified); 97 } 66 98 } 99 100 67 101 } 68 102
Note: See TracChangeset
for help on using the changeset viewer.