diff --git a/.gitignore b/.gitignore index 3f9c8036..d9ebf3d4 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 @@ -74,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 @@ -111,3 +109,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..52692743 --- /dev/null +++ b/wp-content/plugins/academy-africa/academy-africa.php @@ -0,0 +1,44 @@ +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']); + add_action('elementor/frontend/after_enqueue_styles', [$this, 'register_widget_styles']); + add_action('elementor/elements/categories_registered', [$this, 'add_elementor_widget_categories']); + } + + /** + * Include Widgets files + * + * Load widgets files + * + * @since 1.0.0 + * @access private + */ + public function register_widgets($widgets_manager) + { + // Include Widget files + require_once(__DIR__ . '/widgets/hero.php'); + require_once(__DIR__ . '/widgets/header.php'); + + // Register widget + $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') + ); + } + + /** + * 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 new file mode 100644 index 00000000..70f5acc3 --- /dev/null +++ b/wp-content/plugins/academy-africa/includes/widgets/header.php @@ -0,0 +1,173 @@ +name] = $menu->name; + } + return $menu_names; + } + + + protected function register_controls() + { + $this->start_controls_section( + 'section_header', + [ + 'label' => __('Header', 'academy-africa'), + ] + ); + // Select menu + $this->add_control( + 'select_menu', + [ + 'label' => __('Select Menu', 'academy-africa'), + 'type' => \Elementor\Controls_Manager::SELECT, + 'default' => 'primary', + 'options' => $this->get_menus(), + ] + ); + + // 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'); + } + + 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]; + } + + function get_menu_items($name) + { + $list = wp_get_nav_menu_items($name); + $menu_items = []; + foreach ($list as $item) { + $menu_items[] = [ + 'title' => $item->title, + 'url' => $item->url, + 'id' => $item->ID, + 'parent_id' => $item->menu_item_parent, + ]; + } + $menu = []; + foreach ($menu_items as $item) { + if ($item['parent_id'] == 0) { + $menu[$item['id']] = $item; + } else { + $menu[$item['parent_id']]['children'][] = $item; + } + } + return $menu; + } + + protected function render() + { + $settings = $this->get_settings_for_display(); + $selected_menu = $settings['select_menu']; + $menus = $selected_menu ? $this->get_menu_items($selected_menu) : []; + + $this->add_inline_editing_attributes('sign_in_button_text', 'none'); +?> + + + + +

Hello World

+ +