+ + title ); ?> + +
+ ++ excerpt ); ?> +
+ + author ) ) : ?> + + + + categories ) ) : ?> + + +diff --git a/public/class-peptide-news-public.php b/public/class-peptide-news-public.php new file mode 100644 index 0000000..275af3a --- /dev/null +++ b/public/class-peptide-news-public.php @@ -0,0 +1,333 @@ +plugin_name = $plugin_name; + $this->version = $version; + } + + /** + * Register front-end CSS (enqueued on demand by the shortcode/widget). + */ + public function enqueue_styles() { + wp_register_style( + $this->plugin_name, + PEPTIDE_NEWS_PLUGIN_URL . 'public/css/public-style.css', + array(), + $this->version, + 'all' + ); + } + + /** + * Register front-end JS (enqueued on demand by the shortcode/widget). + */ + public function enqueue_scripts() { + wp_register_script( + $this->plugin_name, + PEPTIDE_NEWS_PLUGIN_URL . 'public/js/public-script.js', + array( 'jquery' ), + $this->version, + true + ); + + wp_localize_script( $this->plugin_name, 'peptideNewsPublic', array( + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'nonce' => wp_create_nonce( 'peptide_news_track' ), + 'session_id' => $this->get_or_create_session_id(), + ) ); + } + + /** + * Register the shortcode. + */ + public function register_shortcode() { + add_shortcode( 'peptide_news', array( $this, 'render_shortcode' ) ); + } + + /** + * Register the widget. + */ + public function register_widget() { + register_widget( 'Peptide_News_Widget' ); + } + + /** + * Render the [peptide_news] shortcode. + * + * @param array $atts Shortcode attributes. + * @return string HTML output. + */ + public function render_shortcode( $atts ) { + $atts = shortcode_atts( array( + 'count' => get_option( 'peptide_news_articles_count', 10 ), + 'layout' => 'card', // card | compact | list + ), $atts, 'peptide_news' ); + + $articles = $this->get_articles( absint( $atts['count'] ) ); + + if ( empty( $articles ) ) { + return '
' . esc_html__( 'No peptide news articles available yet. Check back soon!', 'peptide-news' ) . '
+ excerpt ); ?> +
+ + author ) ) : ?> + + + + categories ) ) : ?> + + ++ + +
++ + +
+