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 @@ + + +