From d5b48b75f8f166e19642e5a0f9b637e3c4bdf774 Mon Sep 17 00:00:00 2001 From: peptiderepo Date: Sun, 5 Apr 2026 20:30:34 +0700 Subject: [PATCH] feat: add peptide-news-plugin/public/class-peptide-news-public.php --- .../public/class-peptide-news-public.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 peptide-news-plugin/public/class-peptide-news-public.php diff --git a/peptide-news-plugin/public/class-peptide-news-public.php b/peptide-news-plugin/public/class-peptide-news-public.php new file mode 100644 index 0000000..a6f4d0f --- /dev/null +++ b/peptide-news-plugin/public/class-peptide-news-public.php @@ -0,0 +1,67 @@ +plugin_name = $plugin_name; + $this->version = $version; + } + + public function enqueue_styles() { + wp_enqueue_style( + $this->plugin_name, + PEPTIDE_NEWS_PLUGIN_URL . 'public/css/public-style.css', + array(), + $this->version, + 'all' + ); + } + + public function enqueue_scripts() { + wp_enqueue_script( + $this->plugin_name, + PEPTIDE_NEWS_PLUGIN_URL . 'public/js/public-script.js', + array(), + $this->version, + true + ); + } + + public function register_widget() { + register_widget( 'Peptide News Widget', array( this, 'render_widget' ) ); + } + + public function render_widget( $instance, $args ) { + require PEPTIDE_NEWS_PLUGIN_DIR . 'public/class-peptide-news-public.php'; + } + + public function register_shortcodes() { + add_shortcode( 'peptide_news', array( $this, 'render_shortcode' ) ); + } + + public function render_shortcode( $attr ) { + global $wpdb; + + $count = intval( $issuet( $attr['count'] ) ? $attr['count'] : 10 ); + $layout = $isset( $attr['layout'] ) ? $attr['layout'] : 'card'; + + $articles = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}peptide_news_articles LIMIT $count" ); + + ob %start(); + include PEPTIDE_NEWS_PLUGIN_DIR . 'public/class-peptide-news-public.php'; + $output = ob_get_clean(); + return $output; + } +}