-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from miriamgoldman/plugins-add
Workflow Tweaks
- Loading branch information
Showing
941 changed files
with
3,970 additions
and
183,136 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,9 +72,6 @@ jobs: | |
deploy_to_pantheon: | ||
runs-on: ubuntu-latest | ||
needs: [ identify_sites, configure_env ] | ||
# strategy: | ||
# matrix: | ||
# site: ${{ fromJSON(needs.identify_sites.outputs.sites) }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
@@ -95,10 +92,13 @@ jobs: | |
|
||
- name: Determine target environment for deploy | ||
run: | | ||
# Identify environment based on branch name | ||
env=${{ github.ref_name }} | ||
if [ "$env" == "master" ]; then | ||
env="dev" | ||
# Determine the environment name based on the event type | ||
if [ "${{ github.event_name }}" = "pull_request" ]; then | ||
# Use the PR number as the environment name | ||
env=$(echo ${{ github.ref_name }} | sed 's|^\([0-9]*\)/.*|pr-\1|') | ||
else | ||
# Use the branch name as the environment name | ||
env=${{ github.ref_name }} | ||
fi | ||
# Ensure environment name is 11 characters or less and has no special characters | ||
|
@@ -112,25 +112,36 @@ jobs: | |
run: | | ||
# Create multidev environment if it doesn't exist | ||
if ! terminus env:list ${{ vars.SITE_NAME }} --field=ID | grep $env; then | ||
terminus env:create ${{ vars.SITE_NAME }}.dev $env | ||
terminus env:create ${{ vars.SITE_NAME }}.live $env | ||
fi | ||
# Ensure environment is in git mode | ||
terminus connection:set ${{ vars.SITE_NAME }}.$env git | ||
- name: Push branch to Pantheon | ||
run: | | ||
curr_branch=$( git branch --show-current ) | ||
# The dev environment is always based on the master branch | ||
branch=$( [ "$env" == "dev" ] && echo "master" || echo "$env" ) | ||
dest_branch=$( [ "$env" == "dev" ] && echo "master" || echo "$env" ) | ||
if [[ ${{ github.event_name }} == 'pull_request' ]]; then | ||
git checkout ${{ github.head_ref }} | ||
fi | ||
# Configure git to use the SSH key and avoid host key checking | ||
git config --local core.sshCommand 'ssh -i ~/.ssh/pantheon -o StrictHostKeyChecking=no' | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Actions" | ||
git remote add pantheon $(terminus connection:info ${{ vars.SITE_NAME }}.$env --field=git_url) | ||
git fetch --all | ||
git push pantheon ${{ github.ref_name }}:$branch --force | ||
git fetch pantheon | ||
git checkout -b $dest_branch | ||
git pull pantheon $dest_branch --rebase | ||
git status | ||
git push pantheon $dest_branch | ||
spin_down: | ||
name: Spin down environment | ||
name: Spin down | ||
needs: deploy_to_pantheon | ||
if: always() | ||
runs-on: ubuntu-latest | ||
|
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
wp-content/plugins/wp-native-php-sessions/assets/js/notices.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
jQuery(document).ready(function($) { | ||
$(document).on('click', '.notice-dismiss', function() { | ||
$.ajax({ | ||
url: ajaxurl, | ||
type: 'POST', | ||
data: { | ||
action: 'dismiss_notice' | ||
} | ||
}); | ||
}); | ||
}); |
138 changes: 138 additions & 0 deletions
138
wp-content/plugins/wp-native-php-sessions/inc/class-admin.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
/** | ||
* Controller for backend functionality. | ||
* | ||
* @package WPNPS | ||
*/ | ||
|
||
namespace Pantheon_Sessions; | ||
|
||
/** | ||
* Controller for backend functionality. | ||
*/ | ||
class Admin { | ||
|
||
/** | ||
* Copy of the singleton instance. | ||
* | ||
* @var object | ||
*/ | ||
private static $instance; | ||
|
||
/** | ||
* Name of capability required to perform actions. | ||
* | ||
* @var string | ||
*/ | ||
private static $capability = 'manage_options'; | ||
|
||
/** | ||
* Gets a copy of the singleton instance. | ||
* | ||
* @return object | ||
*/ | ||
public static function get_instance() { | ||
if ( ! isset( self::$instance ) ) { | ||
self::$instance = new Admin(); | ||
self::$instance->setup_actions(); | ||
} | ||
return self::$instance; | ||
} | ||
|
||
/** | ||
* Load admin actions | ||
*/ | ||
private function setup_actions() { | ||
|
||
add_action( 'admin_menu', [ $this, 'action_admin_menu' ] ); | ||
add_action( 'wp_ajax_pantheon_clear_session', [ $this, 'handle_clear_session' ] ); | ||
} | ||
|
||
/** | ||
* Register the admin menu | ||
*/ | ||
public function action_admin_menu() { | ||
|
||
add_management_page( __( 'Pantheon Sessions', 'wp-native-php-sessions' ), __( 'Sessions', 'wp-native-php-sessions' ), self::$capability, 'pantheon-sessions', [ $this, 'handle_page' ] ); | ||
} | ||
|
||
/** | ||
* Render the admin page | ||
*/ | ||
public function handle_page() { | ||
global $wpdb; | ||
|
||
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; | ||
require_once __DIR__ . '/class-list-table.php'; | ||
|
||
echo '<div class="wrap">'; | ||
|
||
echo '<div>'; | ||
$query_args = [ | ||
'action' => 'pantheon_clear_session', | ||
'nonce' => wp_create_nonce( 'pantheon_clear_session' ), | ||
'session' => 'all', | ||
]; | ||
if ( $wpdb->get_var( "SELECT COUNT(session_id) FROM $wpdb->pantheon_sessions" ) ) { | ||
echo '<a class="button pantheon-clear-all-sessions" style="float:right; margin-top: 9px;" href="' . esc_url( add_query_arg( $query_args, admin_url( 'admin-ajax.php' ) ) ) . '">' . esc_html__( 'Clear All', 'wp-native-php-sessions' ) . '</a>'; | ||
} | ||
echo '<h2>' . esc_html__( 'Pantheon Sessions', 'wp-native-php-sessions' ) . '</h2>'; | ||
if ( isset( $_GET['message'] ) && in_array( $_GET['message'], [ 'delete-all-session', 'delete-session' ], true ) ) { | ||
if ( 'delete-all-session' === $_GET['message'] ) { | ||
$message = __( 'Cleared all sessions.', 'wp-native-php-sessions' ); | ||
} elseif ( 'delete-session' === $_GET['message'] ) { | ||
$message = __( 'Session cleared.', 'wp-native-php-sessions' ); | ||
} | ||
echo '<div id="message" class="updated"><p>' . esc_html( $message ) . '</p></div>'; | ||
} | ||
echo '</div>'; | ||
|
||
$wp_list_table = new List_Table(); | ||
$wp_list_table->prepare_items(); | ||
$wp_list_table->display(); | ||
|
||
echo '</div>'; | ||
|
||
add_action( 'admin_footer', [ $this, 'action_admin_footer' ] ); | ||
} | ||
|
||
/** | ||
* Handle a request to clear all sessions | ||
*/ | ||
public function handle_clear_session() { | ||
global $wpdb; | ||
|
||
if ( ! current_user_can( self::$capability ) || ! wp_verify_nonce( $_GET['nonce'], 'pantheon_clear_session' ) ) { | ||
wp_die( esc_html__( "You don't have permission to do this.", 'wp-native-php-sessions' ) ); | ||
} | ||
|
||
if ( ! empty( $_GET['session'] ) && 'all' === $_GET['session'] ) { | ||
$wpdb->query( "DELETE FROM $wpdb->pantheon_sessions" ); | ||
$message = 'delete-all-session'; | ||
} else { | ||
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->pantheon_sessions WHERE session_id=%s", sanitize_text_field( $_GET['session'] ) ) ); | ||
$message = 'delete-session'; | ||
} | ||
wp_safe_redirect( add_query_arg( 'message', $message, wp_get_referer() ) ); | ||
exit; | ||
} | ||
|
||
/** | ||
* Stuff that needs to go in the footer | ||
*/ | ||
public function action_admin_footer() { | ||
?> | ||
<script> | ||
(function($){ | ||
$(document).ready(function(){ | ||
$('.pantheon-clear-all-sessions').on('click', function( e ){ | ||
if ( ! confirm( '<?php esc_html_e( 'Are you sure you want to clear all active sessions?', 'wp-native-php-sessions' ); ?>') ) { | ||
e.preventDefault(); | ||
} | ||
}); | ||
}); | ||
}(jQuery)) | ||
</script> | ||
<?php | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
wp-content/plugins/wp-native-php-sessions/inc/class-cli-command.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
/** | ||
* CLI interface to interact with Pantheon sessions. | ||
* | ||
* @package WPNPS | ||
*/ | ||
|
||
namespace Pantheon_Sessions; | ||
|
||
use WP_CLI; | ||
|
||
/** | ||
* Interact with Pantheon Sessions | ||
*/ | ||
class CLI_Command extends \WP_CLI_Command { | ||
|
||
/** | ||
* List all registered sessions. | ||
* | ||
* [--format=<format>] | ||
* : Accepted values: table, csv, json, count, ids. Default: table | ||
* | ||
* @subcommand list | ||
*/ | ||
public function list_( $args, $assoc_args ) { | ||
global $wpdb; | ||
|
||
if ( ! PANTHEON_SESSIONS_ENABLED ) { | ||
WP_CLI::error( 'Pantheon Sessions is currently disabled.' ); | ||
} | ||
|
||
$defaults = [ | ||
'format' => 'table', | ||
'fields' => 'session_id,user_id,datetime,ip_address,data', | ||
]; | ||
$assoc_args = array_merge( $defaults, $assoc_args ); | ||
|
||
$sessions = []; | ||
foreach ( new \WP_CLI\Iterators\Query( "SELECT * FROM {$wpdb->pantheon_sessions} ORDER BY datetime DESC" ) as $row ) { | ||
$sessions[] = $row; | ||
} | ||
|
||
\WP_CLI\Utils\Format_Items( $assoc_args['format'], $sessions, $assoc_args['fields'] ); | ||
} | ||
|
||
/** | ||
* Delete one or more sessions. | ||
* | ||
* [<session-id>...] | ||
* : One or more session IDs | ||
* | ||
* [--all] | ||
* : Delete all sessions. | ||
* | ||
* @subcommand delete | ||
*/ | ||
public function delete( $args, $assoc_args ) { | ||
global $wpdb; | ||
|
||
if ( ! PANTHEON_SESSIONS_ENABLED ) { | ||
WP_CLI::error( 'Pantheon Sessions is currently disabled.' ); | ||
} | ||
|
||
if ( isset( $assoc_args['all'] ) ) { | ||
$args = $wpdb->get_col( "SELECT session_id FROM {$wpdb->pantheon_sessions}" ); | ||
if ( empty( $args ) ) { | ||
WP_CLI::warning( 'No sessions to delete.' ); | ||
} | ||
} | ||
|
||
foreach ( $args as $session_id ) { | ||
$session = \Pantheon_Sessions\Session::get_by_sid( $session_id ); | ||
if ( $session ) { | ||
$session->destroy(); | ||
WP_CLI::log( sprintf( 'Session destroyed: %s', $session_id ) ); | ||
} else { | ||
WP_CLI::warning( sprintf( "Session doesn't exist: %s", $session_id ) ); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Set id as primary key in the Native PHP Sessions plugin table. | ||
* | ||
* @subcommand add-index | ||
*/ | ||
public function add_index( $args, $assoc_args ) { | ||
$pantheon_session = new \Pantheon_Sessions(); | ||
$resume_point = isset( $assoc_args['start_point'] ) ? $assoc_args['start_point'] : 0; | ||
$pantheon_session->add_index( $resume_point ); | ||
} | ||
|
||
/** | ||
* Finalizes the creation of a primary key by deleting the old data. | ||
* | ||
* @subcommand primary-key-finalize | ||
*/ | ||
public function primary_key_finalize( $args, $assoc_args ) { | ||
$pantheon_session = new \Pantheon_Sessions(); | ||
$resume_point = isset( $assoc_args['start_point'] ) ? $assoc_args['start_point'] : 0; | ||
$pantheon_session->primary_key_finalize( $resume_point ); | ||
} | ||
|
||
/** | ||
* Reverts addition of primary key. | ||
* | ||
* @subcommand primary-key-revert | ||
*/ | ||
public function primary_key_revert( $args, $assoc_args ) { | ||
$pantheon_session = new \Pantheon_Sessions(); | ||
$resume_point = isset( $assoc_args['start_point'] ) ? $assoc_args['start_point'] : 0; | ||
$pantheon_session->primary_key_revert( $resume_point ); | ||
} | ||
} | ||
|
||
\WP_CLI::add_command( 'pantheon session', '\Pantheon_Sessions\CLI_Command' ); |
Oops, something went wrong.