diff --git a/admin/class-partnerexpo-core-admin.php b/admin/class-partnerexpo-core-admin.php index 5c3511d..c75911f 100644 --- a/admin/class-partnerexpo-core-admin.php +++ b/admin/class-partnerexpo-core-admin.php @@ -60,21 +60,7 @@ class Partnerexpo_Core_Admin { * @since 1.0.0 */ public function enqueue_styles() { - - /** - * This function is provided for demonstration purposes only. - * - * An instance of this class should be passed to the run() function - * defined in Partnerexpo_Core_Loader as all of the hooks are defined - * in that particular class. - * - * The Partnerexpo_Core_Loader will then create the relationship - * between the defined hooks and the functions defined in this - * class. - */ - - wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/partnerexpo-core-admin.css', array(), $this->version, 'all' ); - + wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/partnerexpo-core-business-page.css', [], $this->version, 'all' ); } /** @@ -83,21 +69,33 @@ class Partnerexpo_Core_Admin { * @since 1.0.0 */ public function enqueue_scripts() { - - /** - * This function is provided for demonstration purposes only. - * - * An instance of this class should be passed to the run() function - * defined in Partnerexpo_Core_Loader as all of the hooks are defined - * in that particular class. - * - * The Partnerexpo_Core_Loader will then create the relationship - * between the defined hooks and the functions defined in this - * class. - */ - - wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/partnerexpo-core-admin.js', array( 'jquery' ), $this->version, false ); + wp_enqueue_script( $this->plugin_name . '-business-page', plugin_dir_url( __FILE__ ) . 'js/partnerexpo-core-business-page.js', [ 'jquery' ], $this->version, true ); + wp_localize_script( + $this->plugin_name . '-business-page', + 'businessData', + [ + 'post_id' => get_user_meta( get_current_user_id(), 'company_logo_attachment_id', true ), + 'title' => esc_html__( 'Céges logó kiválasztása', 'partnerexpo-core' ), + 'button' => esc_html__( 'Kép használata', 'partnerexpo-core' ), + ] + ); } + public function display_business_data_page() { + include_once plugin_dir_path( __FILE__ ) . 'partials/partnerexpo-core-admin-business.php'; + } + + public function add_menu() { + add_menu_page( + esc_html__( 'Üzleti adatok', 'partnerexpo-core' ), + esc_html__( 'Üzleti adatok', 'partnerexpo-core' ), + 'manage_options', + 'pexpo-core-business-data', + [ $this, 'display_business_data_page' ], + 'dashicons-businessman', + 6 + ); + } + } diff --git a/admin/css/partnerexpo-core-admin.css b/admin/css/partnerexpo-core-business-page.css similarity index 100% rename from admin/css/partnerexpo-core-admin.css rename to admin/css/partnerexpo-core-business-page.css diff --git a/admin/js/partnerexpo-core-admin.js b/admin/js/partnerexpo-core-admin.js deleted file mode 100644 index b04717f..0000000 --- a/admin/js/partnerexpo-core-admin.js +++ /dev/null @@ -1,32 +0,0 @@ -(function( $ ) { - 'use strict'; - - /** - * All of the code for your admin-facing JavaScript source - * should reside in this file. - * - * Note: It has been assumed you will write jQuery code here, so the - * $ function reference has been prepared for usage within the scope - * of this function. - * - * This enables you to define handlers, for when the DOM is ready: - * - * $(function() { - * - * }); - * - * When the window is loaded: - * - * $( window ).load(function() { - * - * }); - * - * ...and/or other possibilities. - * - * Ideally, it is not considered best practise to attach more than a - * single DOM-ready or window-load handler for a particular page. - * Although scripts in the WordPress core, Plugins and Themes may be - * practising this, we should strive to set a better example in our own work. - */ - -})( jQuery ); diff --git a/admin/js/partnerexpo-core-business-page.js b/admin/js/partnerexpo-core-business-page.js new file mode 100644 index 0000000..9446195 --- /dev/null +++ b/admin/js/partnerexpo-core-business-page.js @@ -0,0 +1,57 @@ +jQuery( document ).ready( function( $ ) { + + // Uploading files + var file_frame; + var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id + + jQuery('#pexpo-core-upload-image-button').on('click', function( event ){ + + event.preventDefault(); + + // If the media frame already exists, reopen it. + if ( file_frame ) { + // Set the post ID to what we want + file_frame.uploader.uploader.param( 'post_id', businessData.post_id ); + // Open frame + file_frame.open(); + return; + } else { + // Set the wp.media post id so the uploader grabs the ID we want when initialised + wp.media.model.settings.post.id = businessData.post_id; + } + + // Create the media frame. + file_frame = wp.media.frames.file_frame = wp.media({ + title: businessData.title, + button: { + text: businessData.button, + }, + multiple: false // Set to true to allow multiple files to be selected + }); + + // When an image is selected, run a callback. + file_frame.on( 'select', function() { + // We set multiple to false so only get one image from the uploader + attachment = file_frame.state().get('selection').first().toJSON(); + + // Do something with attachment.id and/or attachment.url here + $( '#pexpo-core-business-logo-preview' ).attr( 'src', attachment.url ).css( 'width', 'auto' ); + $( '#pexpo-core-business-logo-attachment-id' ).val( attachment.id ); + + // Restore the main post ID + wp.media.model.settings.post.id = wp_media_post_id; + }); + + // Finally, open the modal + file_frame.open(); + }); + + // Restore the main ID when the add media button is pressed + jQuery( 'a.add_media' ).on( 'click', function() { + wp.media.model.settings.post.id = wp_media_post_id; + }); + + jQuery( '#pexpo-core-submit' ).on( 'click', function() { + $window.location.reload(); + }); +}); \ No newline at end of file diff --git a/admin/partials/partnerexpo-core-admin-business.php b/admin/partials/partnerexpo-core-admin-business.php new file mode 100644 index 0000000..b84c348 --- /dev/null +++ b/admin/partials/partnerexpo-core-admin-business.php @@ -0,0 +1,58 @@ + + +
+

+

+
+
+

+
+ +
+ + +
+
+

+ +
+ + +
+
\ No newline at end of file diff --git a/admin/partials/partnerexpo-core-admin-display.php b/admin/partials/partnerexpo-core-admin-display.php deleted file mode 100644 index 6cff65f..0000000 --- a/admin/partials/partnerexpo-core-admin-display.php +++ /dev/null @@ -1,16 +0,0 @@ - - - diff --git a/includes/class-partnerexpo-core-user-fields.php b/includes/class-partnerexpo-core-user-fields.php index 282a0f1..2d259b8 100644 --- a/includes/class-partnerexpo-core-user-fields.php +++ b/includes/class-partnerexpo-core-user-fields.php @@ -18,6 +18,7 @@ class Partnerexpo_Core_User_Fields extends Partnerexpo_Core { } private function activate_fields() { + $this->loader->add_action( 'load-profile.php', $this, 'remove_custom_user_fields' ); $this->loader->add_action( 'show_user_profile', $this, 'add_custom_user_fields' ); $this->loader->add_action( 'edit_user_profile', $this, 'add_custom_user_fields' ); $this->loader->add_action( 'personal_options_update', $this, 'save_custom_user_fields' ); @@ -26,8 +27,14 @@ class Partnerexpo_Core_User_Fields extends Partnerexpo_Core { $this->loader->add_action( 'register_form', $this, 'registration_form' ); $this->loader->add_filter( 'registration_errors', $this, 'registration_errors', 10, 3 ); $this->loader->add_filter( 'comment_post', $this, 'validate_comment' ); + } - + + public function remove_custom_user_fields() { + remove_all_actions('show_user_profile'); + remove_all_actions('edit_user_profile'); + } + public function add_custom_user_fields( $user ) { $company = get_user_meta( $user->ID, 'company', true ); ?> diff --git a/includes/class-partnerexpo-core.php b/includes/class-partnerexpo-core.php index 35a2690..f189ff4 100644 --- a/includes/class-partnerexpo-core.php +++ b/includes/class-partnerexpo-core.php @@ -165,6 +165,8 @@ class Partnerexpo_Core { $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_action( 'admin_menu', $plugin_admin, 'add_menu' ); } /** diff --git a/public/class-partnerexpo-core-public.php b/public/class-partnerexpo-core-public.php index 5158725..70331a8 100644 --- a/public/class-partnerexpo-core-public.php +++ b/public/class-partnerexpo-core-public.php @@ -43,6 +43,7 @@ class Partnerexpo_Core_Public { add_shortcode( 'partnerexpo_searchbox', [ $this, 'searchbox_shortcode' ] ); add_shortcode( 'partnerexpo_comment_section', [ $this, 'comments_shortcode' ] ); + add_shortcode( 'partnerexpo_company_head', [ $this, 'company_head_shortcode' ] ); } public function searchbox_shortcode() { @@ -67,6 +68,14 @@ class Partnerexpo_Core_Public { return ob_get_clean(); } + public function company_head_shortcode() { + wp_enqueue_style( $this->plugin_name . '-company-head-css' ); + + ob_start(); + include plugin_dir_path( __FILE__ ) . 'partials/partnerexpo-core-public-company-head.php'; + return ob_get_clean(); + } + public function register_endpoint() { register_rest_route('pexpo/v1', '/query', [ 'methods' => 'GET', @@ -208,6 +217,14 @@ class Partnerexpo_Core_Public { $this->version, 'all' ); + + wp_register_style( + $this->plugin_name . '-company-head-css', + plugin_dir_url( __FILE__ ) . 'css/company-head.css', + [], + $this->version, + 'all' + ); } /** diff --git a/public/css/company-head.css b/public/css/company-head.css new file mode 100644 index 0000000..97f609d --- /dev/null +++ b/public/css/company-head.css @@ -0,0 +1,28 @@ +.pexpo-core-company-head-wrapper { + display: flex; + align-items: left; + gap: 50px; + margin: 20px; + width: 100%; +} + +.pexpo-core-company-head-logo-wrapper { + flex-shrink: 0; + + & .pexpo-core-company-logo { + width: max-content; + height: 100px; + object-fit: contain; + } +} + +.pexpo-core-company-head-name-wrapper { + flex-grow: 1; + display: flex; + align-items: center; + + & .pexpo-core-company-name { + font-size: 2em; + margin: 0; + } +} \ No newline at end of file diff --git a/public/partials/partnerexpo-core-public-company-head.php b/public/partials/partnerexpo-core-public-company-head.php new file mode 100644 index 0000000..037b08a --- /dev/null +++ b/public/partials/partnerexpo-core-public-company-head.php @@ -0,0 +1,25 @@ + + +
+
+ +
+
+

+
+
\ No newline at end of file diff --git a/public/partials/partnerexpo-core-public-display.php b/public/partials/partnerexpo-core-public-display.php deleted file mode 100644 index ea7a639..0000000 --- a/public/partials/partnerexpo-core-public-display.php +++ /dev/null @@ -1,16 +0,0 @@ - - -