Skip to content

Commit

Permalink
refactor: styles added to css file
Browse files Browse the repository at this point in the history
  • Loading branch information
julianramirez2 committed Aug 3, 2023
1 parent 5f5f277 commit ed76543
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 22 deletions.
29 changes: 28 additions & 1 deletion admin/css/openedx-woocommerce-plugin-admin.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
/**
* All of the CSS for your admin-specific functionality should be
* included in this file.
*/
*/

#namediv{
padding: 50px 20px 50px 20px;
}

.logs_box {
max-width: 100%;
max-height: 477px;
border: 1px solid #ccc;
padding: 10px;
white-space: pre-wrap;
word-wrap: break-word;
overflow: auto;
display: flex;
flex-direction: column-reverse;
}

.log_entry {
background-color: #f2f2f2;
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
}

.logs_box strong {
font-weight: bold;
}
23 changes: 2 additions & 21 deletions admin/views/Openedx_Woocommerce_Plugin_Enrollment_Info_Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function render_enrollment_info_form( $post ) {
}

?>
<div id="namediv" class="postbox" style="padding: 50px 20px 50px 20px;">
<div id="namediv" class="postbox">
<h2 class="">Open edX enrollment request</h2>
<fieldset>
<input type="hidden" name="new_enrollment" value="<?php echo( $new_enrollment ); ?>">
Expand Down Expand Up @@ -230,26 +230,7 @@ public function render_logs_box($post) {
?>

<style>
.logs_box {
max-width: 100%;
max-height: 477px;
border: 1px solid #ccc;
padding: 10px;
white-space: pre-wrap;
word-wrap: break-word;
overflow: auto;
display: flex;
flex-direction: column-reverse;
}
.log_entry {
background-color: #f2f2f2;
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
}
.logs_box strong {
font-weight: bold;
}

</style>
<div class="logs_box">
<?php echo $logs; ?>
Expand Down
1 change: 1 addition & 0 deletions includes/Openedx_Woocommerce_Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ private function define_admin_hooks() {
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
$this->loader->add_filter( 'gettext', $this, 'openedx_plugin_custom_post_message', 10, 3 );
$this->loader->wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . '../admin/css/openedx-woocommerce-plugin-admin.css', array(), $this->version, 'all' );

}

Expand Down
36 changes: 36 additions & 0 deletions includes/Openedx_Woocommerce_Plugin_Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Openedx_Woocommerce_Plugin_Loader {
*/
protected $filters;

protected $styles;

/**
* Initialize the collections used to maintain the actions and filters.
*
Expand All @@ -52,6 +54,7 @@ public function __construct() {

$this->actions = array();
$this->filters = array();
$this->styles = array();

}

Expand Down Expand Up @@ -83,6 +86,21 @@ public function add_filter( $hook, $component, $callback, $priority = 10, $accep
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
}

/**
* Add a new style to the collection to be registered with WordPress.
*
* @since 1.1.1
* @param string $handle Name of the stylesheet. Should be unique.
* @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
* @param array $deps An array of registered stylesheet handles this stylesheet depends on.
* @param string $ver String specifying the stylesheet version number, if it has one. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the stylesheet.
* @param string $media The media for which this stylesheet has been defined.
* @return array The collection of actions and filters registered with WordPress.
*/
public function wp_enqueue_style( $handle, $src, $deps, $ver, $media ) {
$this->styles = $this->add_style($handle, $src, $deps, $ver, $media);
}

/**
* A utility function that is used to register the actions and hooks into a single
* collection.
Expand Down Expand Up @@ -111,6 +129,20 @@ private function add( $hooks, $hook, $component, $callback, $priority, $accepted

}

private function add_style( $handle, $src, $deps, $ver, $media ) {

$hooks[] = array(
'handle' => $handle,
'src' => $src,
'deps' => $deps,
'ver' => $ver,
'media' => $media
);

return $hooks;

}

/**
* Register the filters and actions with WordPress.
*
Expand All @@ -126,6 +158,10 @@ public function run() {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}

foreach ( $this->styles as $hook ) {
wp_enqueue_style( $hook['handle'], $hook['src'], $hook['deps'], $hook['ver'], $hook['media'] );
}

}

}

0 comments on commit ed76543

Please sign in to comment.