@@ -74,7 +74,7 @@ public static function create_tables() {
7474 * @return array
7575 */
7676 public static function customizer_default_values () {
77- $ my_bookmark_url = cbxwpbookmarks_mybookmark_page_url ();
77+ $ my_bookmark_url = cbxwpbookmarks_mybookmark_page_url ();
7878
7979 $ customizer_default = [
8080 'shortcodes ' => 'cbxwpbookmark-mycat,cbxwpbookmark ' ,
@@ -118,10 +118,10 @@ public static function customizer_default_values() {
118118 }//end customizer_default_values
119119
120120 /**
121- * Adjust customizer default values
122- *
123- * @param boolean $update
124- * @param boolean $return
121+ * Adjust customizer default values
122+ *
123+ * @param boolean $update
124+ * @param boolean $return
125125 *
126126 * @return array|void
127127 */
@@ -272,7 +272,7 @@ public static function show_cbxbookmark_btn( $object_id = 0, $object_type = null
272272
273273 $ settings = new CBXWPBookmark_Settings_API ();
274274
275- $ hide_for_guest = absint ( $ settings ->get_opt ( 'hide_for_guest ' , 'cbxwpbookmark_basics ' , 0 ) );
275+ $ hide_for_guest = absint ( $ settings ->get_field ( 'hide_for_guest ' , 'cbxwpbookmark_basics ' , 0 ) );
276276 if ( $ hide_for_guest && ! is_user_logged_in () ) {
277277 return '' ;
278278 }
@@ -760,7 +760,7 @@ public static function cbxbookmark_post_html( $instance ) {
760760 public static function cbxbookmark_most_html ( $ instance , $ attr = [] ) {
761761 global $ wpdb ;
762762 $ bookmark_table = $ wpdb ->prefix . 'cbxwpbookmark ' ;
763- $ settings = new CBXWPBookmark_Settings_API ();
763+ $ settings = new CBXWPBookmark_Settings_API ();
764764 $ allowed_object_types = cbxwpbookmarks_allowed_object_type ();
765765
766766 $ object_types = CBXWPBookmarkHelper::object_types ( true ); //get plain post type as array
@@ -1239,7 +1239,7 @@ public static function get_author_cbxwpbookmarks_url( $author_id = 0 ) {
12391239 * @return false|string
12401240 */
12411241 public static function cbxwpbookmarks_mybookmark_page_url () {
1242- $ settings = new CBXWPBookmark_Settings_API ();
1242+ $ settings = new CBXWPBookmark_Settings_API ();
12431243
12441244 $ my_bookmark_page_id = absint ( $ settings ->get_field ( 'mybookmark_pageid ' , 'cbxwpbookmark_basics ' , 0 ) );
12451245
@@ -2412,7 +2412,7 @@ public static function cbxwpbookmark_setting_fields() {
24122412
24132413 $ settings_builtin_fields =
24142414 [
2415- 'cbxwpbookmark_basics ' => [
2415+ 'cbxwpbookmark_basics ' => [
24162416 'basics_heading ' => [
24172417 'name ' => 'basics_heading ' ,
24182418 'label ' => esc_html__ ( 'General Settings ' , 'cbxwpbookmark ' ),
@@ -2642,7 +2642,7 @@ public static function cbxwpbookmark_setting_fields() {
26422642 ],
26432643
26442644 ],
2645- 'cbxwpbookmark_tools ' => [
2645+ 'cbxwpbookmark_tools ' => [
26462646 'tools_heading ' => [
26472647 'name ' => 'tools_heading ' ,
26482648 'label ' => esc_html__ ( 'Tools Settings ' , 'cbxwpbookmark ' ),
@@ -2979,8 +2979,8 @@ public static function cbxbookmark_create_page( $key = '', $slug = '', $page_tit
29792979 }//end cbxbookmark_create_page
29802980
29812981 /**
2982- * Get any plugin version number
2983- *
2982+ * Get any plugin version number
2983+ *
29842984 * @param $plugin_slug
29852985 *
29862986 * @return mixed|string
@@ -3006,4 +3006,49 @@ public static function get_any_plugin_version( $plugin_slug = '' ) {
30063006 // Return false if the plugin is not found
30073007 return '' ;
30083008 }//end method get_pro_addon_version
3009+
3010+ /**
3011+ * Returns codeboxr news feeds using transient cache
3012+ *
3013+ * @return false|mixed|\SimplePie\Item[]|null
3014+ */
3015+ public static function codeboxr_news_feed () {
3016+ $ cache_key = 'codeboxr_news_feed_cache ' ;
3017+ $ cached_feed = get_transient ( $ cache_key );
3018+
3019+ $ news = false ;
3020+
3021+ if ( false === $ cached_feed ) {
3022+ include_once ABSPATH . WPINC . '/feed.php ' ; // Ensure feed functions are available
3023+ $ feed = fetch_feed ( 'https://codeboxr.com/feed?post_type=post ' );
3024+
3025+ if ( is_wp_error ( $ feed ) ) {
3026+ return false ; // Return false if there's an error
3027+ }
3028+
3029+ $ feed ->init ();
3030+
3031+ $ feed ->set_output_encoding ( 'UTF-8 ' ); // this is the encoding parameter, and can be left unchanged in almost every case
3032+ $ feed ->handle_content_type (); // this double-checks the encoding type
3033+ $ feed ->set_cache_duration ( 21600 ); // 21,600 seconds is six hours
3034+ $ limit = $ feed ->get_item_quantity ( 10 ); // fetches the 18 most recent RSS feed stories
3035+ $ items = $ feed ->get_items ( 0 , $ limit );
3036+ $ blocks = array_slice ( $ items , 0 , 10 );
3037+
3038+ $ news = [];
3039+ foreach ( $ blocks as $ block ) {
3040+ $ url = $ block ->get_permalink ();
3041+ $ url = CBXWPBookmarkHelper::url_utmy ( esc_url ( $ url ) );
3042+ $ title = $ block ->get_title ();
3043+
3044+ $ news [] = ['url ' => $ url , 'title ' => $ title ];
3045+ }
3046+
3047+ set_transient ( $ cache_key , $ news , HOUR_IN_SECONDS * 6 ); // Cache for 6 hours
3048+ } else {
3049+ $ news = $ cached_feed ;
3050+ }
3051+
3052+ return $ news ;
3053+ }//end method codeboxr_news_feed
30093054}//end CBXWPBookmarkHelper
0 commit comments