From 70d42d160372f3982333619112d1aea4e78da30e Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 17 Oct 2023 18:10:24 +0300 Subject: [PATCH 1/9] Simple plugin setup --- .gitignore | 8 ++-- .../plugins/academy-africa/academy-africa.php | 37 +++++++++++++++++++ .../widgets/academy-africa-hero.php | 31 ++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 wp-content/plugins/academy-africa/academy-africa.php create mode 100644 wp-content/plugins/academy-africa/widgets/academy-africa-hero.php diff --git a/.gitignore b/.gitignore index 3f9c8036..7c5efc32 100644 --- a/.gitignore +++ b/.gitignore @@ -62,10 +62,7 @@ wp-content/mu-plugins/wpe-wp-sign-on-plugin* /wp-admin /wp-includes /wp-content/themes/* -!/wp-content/themes/academyAfrica -!/wp-content/themes/hello-elementor /wp-content/plugins/* -!/wp-content/plugins/index.php /wp-content/mu-plugins .htaccess apple-touch-icon-precomposed.png @@ -111,3 +108,8 @@ wordpress *.avi .env + +!/wp-content/themes/academyAfrica +!/wp-content/themes/hello-elementor +!/wp-content/plugins/index.php +!/wp-content/plugins/academy-africa diff --git a/wp-content/plugins/academy-africa/academy-africa.php b/wp-content/plugins/academy-africa/academy-africa.php new file mode 100644 index 00000000..15921c4f --- /dev/null +++ b/wp-content/plugins/academy-africa/academy-africa.php @@ -0,0 +1,37 @@ +register( new \Academy_Africa_Hero() ); + +} +add_action( 'elementor/widgets/register', 'register_academy_africa_widget' ); \ No newline at end of file diff --git a/wp-content/plugins/academy-africa/widgets/academy-africa-hero.php b/wp-content/plugins/academy-africa/widgets/academy-africa-hero.php new file mode 100644 index 00000000..a60eb68d --- /dev/null +++ b/wp-content/plugins/academy-africa/widgets/academy-africa-hero.php @@ -0,0 +1,31 @@ + + +

Hello World

+ + Date: Tue, 17 Oct 2023 19:02:57 +0300 Subject: [PATCH 2/9] Modularize plugin --- .../plugins/academy-africa/academy-africa.php | 19 +- .../academy-africa/includes/plugin.php | 219 ++++++++++++++++++ .../widgets/hero.php} | 0 3 files changed, 226 insertions(+), 12 deletions(-) create mode 100644 wp-content/plugins/academy-africa/includes/plugin.php rename wp-content/plugins/academy-africa/{widgets/academy-africa-hero.php => includes/widgets/hero.php} (100%) diff --git a/wp-content/plugins/academy-africa/academy-africa.php b/wp-content/plugins/academy-africa/academy-africa.php index 15921c4f..d06afb65 100644 --- a/wp-content/plugins/academy-africa/academy-africa.php +++ b/wp-content/plugins/academy-africa/academy-africa.php @@ -1,7 +1,7 @@ register( new \Academy_Africa_Hero() ); + // Run the plugin + \Academy_Africa\Plugin::instance(); } -add_action( 'elementor/widgets/register', 'register_academy_africa_widget' ); \ No newline at end of file +add_action( 'plugins_loaded', 'academy_africa_plugin' ); \ No newline at end of file diff --git a/wp-content/plugins/academy-africa/includes/plugin.php b/wp-content/plugins/academy-africa/includes/plugin.php new file mode 100644 index 00000000..c0ef9bc9 --- /dev/null +++ b/wp-content/plugins/academy-africa/includes/plugin.php @@ -0,0 +1,219 @@ +is_compatible()) { + add_action('elementor/init', [$this, 'init']); + } + } + + /** + * Compatibility Check + * + * Checks if the installed version of Elementor meets the plugin's minimum requirement. + * + * @since 1.0.0 + * @access public + */ + + public function is_compatible() + { + // Check if Elementor installed and activated + if (!did_action('elementor/loaded')) { + add_action('admin_notices', [$this, 'admin_notice_missing_main_plugin']); + return false; + } + + // Check if the installed version of Elementor meets the plugin's minimum requirement. + if (!version_compare(ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=')) { + add_action('admin_notices', [$this, 'admin_notice_minimum_elementor_version']); + return false; + } + + // Check if the installed version of PHP meets the plugin's minimum requirement. + if (!version_compare(PHP_VERSION, self::MINIMUM_PHP_VERSION, '>=')) { + add_action('admin_notices', [$this, 'admin_notice_minimum_php_version']); + return false; + } + + return true; + } + + /** + * Admin notice + * + * Warning when the site doesn't have Elementor installed or activated. + * + * @since 1.0.0 + * @access public + */ + public function admin_notice_missing_main_plugin() + { + if (isset($_GET['activate'])) unset($_GET['activate']); + + $message = sprintf( + /* translators: 1: Plugin name 2: Elementor */ + esc_html__('"%1$s" requires "%2$s" to be installed and activated.', 'academy-africa'), + '' . esc_html__('academyAfrica Elementor Addon', 'academy-africa') . '', + '' . esc_html__('Elementor', 'academy-africa') . '' + ); + + printf('

%1$s

', $message); + } + + /** + * Admin notice + * + * Warning when the site doesn't have a minimum required Elementor version. + * + * @since 1.0.0 + * @access public + */ + public function admin_notice_minimum_elementor_version() + { + if (isset($_GET['activate'])) unset($_GET['activate']); + + $message = sprintf( + /* translators: 1: Plugin name 2: Elementor 3: Required Elementor version */ + esc_html__('"%1$s" requires "%2$s" version %3$s or greater.', 'academy-africa'), + '' . esc_html__('academyAfrica Elementor Addon', 'academy-africa') . '', + '' . esc_html__('Elementor', 'academy-africa') . '', + self::MINIMUM_ELEMENTOR_VERSION + ); + + printf('

%1$s

', $message); + } + + /** + * Admin notice + * + * Warning when the site doesn't have a minimum required PHP version. + * + * @since 1.0.0 + * @access public + */ + public function admin_notice_minimum_php_version() + { + if (isset($_GET['activate'])) unset($_GET['activate']); + + $message = sprintf( + /* translators: 1: Plugin name 2: PHP 3: Required PHP version */ + esc_html__('"%1$s" requires "%2$s" version %3$s or greater.', 'academy-africa'), + '' . esc_html__('academyAfrica Elementor Addon', 'academy-africa') . '', + '' . esc_html__('PHP', 'academy-africa') . '', + self::MINIMUM_PHP_VERSION + ); + + printf('

%1$s

', $message); + } + + /** + * Initialize the plugin + * + * Load the plugin only after Elementor (and other plugins) are loaded. + * + * @since 1.0.0 + * @access public + */ + + public function init() + { + + add_action('elementor/widgets/register', [$this, 'register_widgets']); + } + + /** + * Include Widgets files + * + * Load widgets files + * + * @since 1.0.0 + * @access private + */ + public function register_widgets() + { + // Include Widget files + require_once(__DIR__ . '/widgets/hero.php'); + + // Register widget + $widgets_manager->register(new \Academy_Africa_Hero()); + } +} diff --git a/wp-content/plugins/academy-africa/widgets/academy-africa-hero.php b/wp-content/plugins/academy-africa/includes/widgets/hero.php similarity index 100% rename from wp-content/plugins/academy-africa/widgets/academy-africa-hero.php rename to wp-content/plugins/academy-africa/includes/widgets/hero.php From b780e82cde4d6743c29ff5cfc59747056373fa5a Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 17 Oct 2023 19:54:08 +0300 Subject: [PATCH 3/9] Fix plugin register --- wp-content/plugins/academy-africa/includes/plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-content/plugins/academy-africa/includes/plugin.php b/wp-content/plugins/academy-africa/includes/plugin.php index c0ef9bc9..4cbb40da 100644 --- a/wp-content/plugins/academy-africa/includes/plugin.php +++ b/wp-content/plugins/academy-africa/includes/plugin.php @@ -208,12 +208,12 @@ public function init() * @since 1.0.0 * @access private */ - public function register_widgets() + public function register_widgets($widgets_manager) { // Include Widget files require_once(__DIR__ . '/widgets/hero.php'); // Register widget - $widgets_manager->register(new \Academy_Africa_Hero()); + $widgets_manager->register( new \Academy_Africa_Hero() ); } } From 8d311731f8c355f080d00114a3c7986ec8fe2a3b Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Wed, 18 Oct 2023 14:42:33 +0300 Subject: [PATCH 4/9] Academy plugin assets Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- .gitignore | 1 + .../plugins/academy-africa/academy-africa.php | 22 ++++++-- .../includes/assets/css/academy-africa.css | 56 +++++++++++++++++++ .../includes/assets/css/header.css | 12 ++++ .../includes/assets/css/style.css | 9 +++ .../academy-africa/includes/plugin.php | 25 ++++++++- .../includes/widgets/header.php | 44 +++++++++++++++ .../academy-africa/includes/widgets/hero.php | 33 ++++++----- 8 files changed, 183 insertions(+), 19 deletions(-) create mode 100644 wp-content/plugins/academy-africa/includes/assets/css/academy-africa.css create mode 100644 wp-content/plugins/academy-africa/includes/assets/css/header.css create mode 100644 wp-content/plugins/academy-africa/includes/assets/css/style.css create mode 100644 wp-content/plugins/academy-africa/includes/widgets/header.php diff --git a/.gitignore b/.gitignore index 7c5efc32..d9ebf3d4 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,7 @@ favicon.ico wpe-deploy-status-academyafrica robots.txt wordpress +node_modules # large/disallowed file types # a CDN should be used for these diff --git a/wp-content/plugins/academy-africa/academy-africa.php b/wp-content/plugins/academy-africa/academy-africa.php index d06afb65..52692743 100644 --- a/wp-content/plugins/academy-africa/academy-africa.php +++ b/wp-content/plugins/academy-africa/academy-africa.php @@ -1,4 +1,5 @@ register( new \Academy_Africa_Hero() ); + $widgets_manager->register(new \Academy_Africa_Hero()); + $widgets_manager->register(new \Academy_Africa_Header()); + } + + public function register_widget_styles() + { + wp_enqueue_style( + 'academy-africa', + plugins_url('assets/css/academy-africa.css', __FILE__), + [], + [], + filemtime(plugin_dir_path(__FILE__) . 'assets/css/academy-africa.css.css') + ); + + wp_enqueue_style( + 'academy-africa-header', + plugins_url('assets/css/header.css', __FILE__), + [ + 'academy-africa' + ], + filemtime(plugin_dir_path(__FILE__) . 'assets/css/header.css') + ); } } diff --git a/wp-content/plugins/academy-africa/includes/widgets/header.php b/wp-content/plugins/academy-africa/includes/widgets/header.php new file mode 100644 index 00000000..f6a2fe6b --- /dev/null +++ b/wp-content/plugins/academy-africa/includes/widgets/header.php @@ -0,0 +1,44 @@ + +
+

Header

+
+ + + protected function render() + { +?>

Hello World

- Date: Wed, 18 Oct 2023 16:13:41 +0300 Subject: [PATCH 5/9] basic nav Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- .../includes/assets/css/header.css | 176 +++++++++++++++++- .../academy-africa/includes/plugin.php | 17 ++ .../includes/widgets/header.php | 56 +++++- .../academy-africa/includes/widgets/hero.php | 2 +- 4 files changed, 237 insertions(+), 14 deletions(-) diff --git a/wp-content/plugins/academy-africa/includes/assets/css/header.css b/wp-content/plugins/academy-africa/includes/assets/css/header.css index 353f3c74..4738c78d 100644 --- a/wp-content/plugins/academy-africa/includes/assets/css/header.css +++ b/wp-content/plugins/academy-africa/includes/assets/css/header.css @@ -1,12 +1,170 @@ -.academy-africa-header { - width: 100vw; - background-color: var(--color-primary); - height: 200px; +.nav { + display: flex; + width: 1440px; + height: 92px; + padding: 20px 40px; + justify-content: center; + align-items: center; + gap: 58px; + flex-shrink: 0; + background: #0C1A81; } -.academy-africa-header h1 { - color: var(--color-neutral50); - text-align: center; - padding-top: 50px; - font-size: large; +.nav .logo-section { + display: flex; + align-items: center; + gap: 20px; +} + +.nav .logo-section .logo { + width: 52px; + height: 52px; +} + +.nav .logo-section .page-title { + color: #FFFFFF; + font-family: Open Sans; + font-size: 18px; + font-style: normal; + font-weight: 600; + line-height: 28px; +} + +.navigation-section { + display: flex; + width: 1032px; + min-width: 880px; + max-width: 1032px; + justify-content: flex-end; + align-items: center; + gap: 100px; + flex-shrink: 0; +} + +.navigation-section .search-bar { + display: flex; + align-items: center; + flex: 1 0 0; +} + +.navigation-section .search-bar .search-input { + display: flex; + padding: 0px 9px; + align-items: flex-start; + gap: 10px; + flex: 1 0 0; + align-self: stretch; + border: none; + outline: none; +} + +.navigation-section .search-bar .search-input::placeholder { + display: flex; + flex-direction: column; + justify-content: center; + flex: 1 0 0; + align-self: stretch; + color: var(#767A94, #767A94); + font-family: Open Sans; + font-size: 14px; + font-style: italic; + font-weight: 400; + line-height: 18px; +} + +.navigation-section .search-bar .search-button { + display: flex; + padding: 12px 16px; + justify-content: center; + align-items: center; + gap: 8px; + border: none; + background: var(#EFF0FD, #EFF0FD); +} + +.navigation-section .search-bar .search-button img { + width: 16px; + height: 16px; +} + +.navigation-section .navigation-links { + display: flex; + justify-content: flex-end; + align-items: center; + gap: 10px; + height: 43px; + overflow: hidden; +} + +.navigation-section .navigation-links a { + text-decoration: none; +} + +.navigation-section .navigation-links .nav-link { + display: flex; + padding: 10px; + justify-content: center; + align-items: center; + gap: 6px; + background: #0C1A81; + text-decoration: none; +} + +.navigation-section .navigation-links .nav-link .nav-link-text { + color: #F7F9FD; + font-family: Open Sans; + font-size: 18px; + font-style: normal; + font-weight: 600; + line-height: 21.6px; +} + +.navigation-section .navigation-links .nav-link .arrow-down { + width: 16px; + height: 16px; + color: #fff; +} + +.navigation-section .navigation-links .nav-link.login-button { + display: flex; + padding: 12px 16px; + justify-content: center; + align-items: center; + gap: 8px; + background: #EFF0FD; +} + +.navigation-section .navigation-links .nav-link.login-button .nav-link-text { + color: #0C1A81; + font-family: Open Sans; + font-size: 16px; + font-style: normal; + font-weight: 800; + line-height: 19px; + letter-spacing: 1.6px; + text-transform: uppercase; +} + +.navigation-section .navigation-links .nav-link.lang-button { + display: flex; + max-height: 42px; + padding: 10px; + justify-content: center; + align-items: center; + gap: 6px; + background: #0C1A81; +} + +.navigation-section .navigation-links .nav-link.lang-button .language-icon { + width: 24px; + height: 24px; +} + +.navigation-section .navigation-links .nav-link.lang-button .arrow-down { + width: 16px; + height: 16px; +} + +.navigation-section .navigation-links .nav-link.lang-button .icon { + color: #fff; } \ No newline at end of file diff --git a/wp-content/plugins/academy-africa/includes/plugin.php b/wp-content/plugins/academy-africa/includes/plugin.php index 3519b0fd..d863f44b 100644 --- a/wp-content/plugins/academy-africa/includes/plugin.php +++ b/wp-content/plugins/academy-africa/includes/plugin.php @@ -199,6 +199,7 @@ public function init() add_action('elementor/widgets/register', [$this, 'register_widgets']); add_action('elementor/frontend/after_enqueue_styles', [$this, 'register_widget_styles']); + add_action('elementor/elements/categories_registered', [$this, 'add_elementor_widget_categories']); } /** @@ -239,4 +240,20 @@ public function register_widget_styles() filemtime(plugin_dir_path(__FILE__) . 'assets/css/header.css') ); } + + /** + * Add custom category + * + * @since 1.0.0 + * @access public + */ + public function add_elementor_widget_categories($elements_manager){ + $elements_manager->add_category( + 'academy-africa', + [ + 'title' => __('Academy Africa', 'academy-africa'), + 'icon' => 'fa fa-plug', + ] + ); + } } diff --git a/wp-content/plugins/academy-africa/includes/widgets/header.php b/wp-content/plugins/academy-africa/includes/widgets/header.php index f6a2fe6b..e7440905 100644 --- a/wp-content/plugins/academy-africa/includes/widgets/header.php +++ b/wp-content/plugins/academy-africa/includes/widgets/header.php @@ -2,6 +2,7 @@ class Academy_Africa_Header extends \Elementor\Widget_Base { + public function get_style_depends() { return ['academy-africa-header']; @@ -24,7 +25,7 @@ public function get_icon() public function get_categories() { - return ['basic']; + return ['academy-africa']; } public function get_keywords() @@ -32,12 +33,59 @@ public function get_keywords() return ['header', 'navigation']; } + function getSiteName() + { + return get_bloginfo('name'); + } + + function get_custom_logo_url() + { + $custom_logo_id = get_theme_mod('custom_logo'); + $image = wp_get_attachment_image_src($custom_logo_id, 'full'); + return $image[0]; + } + protected function render() { ?> -
-

Header

-
+ Date: Wed, 18 Oct 2023 17:05:20 +0300 Subject: [PATCH 6/9] basic controls Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- .../includes/assets/css/style.css | 9 --- .../includes/widgets/header.php | 55 +++++++++++++++++-- 2 files changed, 49 insertions(+), 15 deletions(-) delete mode 100644 wp-content/plugins/academy-africa/includes/assets/css/style.css diff --git a/wp-content/plugins/academy-africa/includes/assets/css/style.css b/wp-content/plugins/academy-africa/includes/assets/css/style.css deleted file mode 100644 index 0fb49f8b..00000000 --- a/wp-content/plugins/academy-africa/includes/assets/css/style.css +++ /dev/null @@ -1,9 +0,0 @@ -body { - background-color: #000; - color: #fff; - font-family: sans-serif; - font-size: 16px; - line-height: 1.5; - margin: 0; - padding: 0; -} \ No newline at end of file diff --git a/wp-content/plugins/academy-africa/includes/widgets/header.php b/wp-content/plugins/academy-africa/includes/widgets/header.php index e7440905..de4299e1 100644 --- a/wp-content/plugins/academy-africa/includes/widgets/header.php +++ b/wp-content/plugins/academy-africa/includes/widgets/header.php @@ -33,6 +33,43 @@ public function get_keywords() return ['header', 'navigation']; } + protected function register_controls() + { + $this->start_controls_section( + 'section_header', + [ + 'label' => __('Header', 'academy-africa'), + ] + ); + + // Sign in button text + $this->add_control( + 'sign_in_button_text', + [ + 'label' => __('Sign In Button Text', 'academy-africa'), + 'type' => \Elementor\Controls_Manager::TEXT, + 'default' => __('Sign In', 'academy-africa'), + 'placeholder' => __('Sign In', 'academy-africa'), + ] + ); + + // Search bar placeholder text + $this->add_control( + 'search_bar_placeholder_text', + [ + 'label' => __('Search Bar Placeholder Text', 'academy-africa'), + 'type' => \Elementor\Controls_Manager::TEXT, + 'default' => __('Search Courses', 'academy-africa'), + 'placeholder' => __('Search Courses', 'academy-africa'), + ] + ); + + + + + $this->end_controls_section(); + } + function getSiteName() { return get_bloginfo('name'); @@ -47,6 +84,10 @@ function get_custom_logo_url() protected function render() { + $settings = $this->get_settings_for_display(); + + // inline editing + $this->add_inline_editing_attributes('sign_in_button_text', 'none'); ?>