* @license GPL-2.0+ * @link https://github.com/ronalfy/user-profile-picture * * @since 2.0.0 */ class Metronet_Profile_Picture_Gutenberg { /** * Class constructor. */ public function __construct() { if ( ! function_exists( 'register_block_type' ) ) { return; } add_action( 'init', array( $this, 'register_block' ) ); add_action( 'enqueue_block_assets', array( $this, 'add_gutenberg_styles' ) ); add_action( 'enqueue_block_editor_assets', array( $this, 'add_gutenberg_scripts' ) ); add_action( 'admin_footer', array( $this, 'load_gutenblock_svgs' ) ); } /** * Register the main User Profile Picture block. */ public function register_block() { register_block_type( 'mpp/user-profile', array( 'attributes' => array(), ) ); register_block_type( 'mpp/user-profile-enhanced', array( 'attributes' => array( 'profileName' => array( 'type' => 'string', 'default' => '', ), 'theme' => array( 'type' => 'string', 'default' => 'regular', ), 'profileTitle' => array( 'type' => 'string', 'default' => '', ), 'profileContent' => array( 'type' => 'string', 'default' => '', ), 'profileViewPosts' => array( 'type' => 'string', 'default' => __( 'View Posts', 'metronet-profile-picture' ), ), 'profileViewWebsite' => array( 'type' => 'string', 'default' => __( 'View Website', 'metronet-profile-picture' ), ), 'profileAlignment' => array( 'type' => 'string', 'default' => '', ), 'profileImgURL' => array( 'type' => 'string', 'default' => '', ), 'profileImgID' => array( 'type' => 'number', 'default' => '', ), 'profileURL' => array( 'type' => 'string', 'default' => '', ), 'padding' => array( 'type' => 'number', 'default' => 0, ), 'border' => array( 'type' => 'number', 'default' => 0, ), 'borderRounded' => array( 'type' => 'number', 'default' => 0, ), 'borderColor' => array( 'type' => 'string', 'default' => '#f2f2f2', ), 'profileBackgroundColor' => array( 'type' => 'string', 'default' => '#f2f2f2', ), 'profileTextColor' => array( 'type' => 'string', 'default' => '#32373c', ), 'profileViewPostsBackgroundColor' => array( 'type' => 'string', 'default' => '#cf6d38', ), 'profileViewPostsTextColor' => array( 'type' => 'string', 'default' => '#FFFFFF', ), 'profileWebsiteBackgroundColor' => array( 'type' => 'string', 'default' => '#000000', ), 'profileWebsiteTextColor' => array( 'type' => 'string', 'default' => '#FFFFFF', ), 'profileLinkColor' => array( 'type' => 'string', 'default' => 'inherit', ), 'headerFontSize' => array( 'type' => 'number', 'default' => 24, ), 'buttonFontSize' => array( 'type' => 'number', 'default' => 16, ), 'profileFontSize' => array( 'type' => 'number', 'default' => 18, ), 'profileAvatarShape' => array( 'type' => 'string', 'default' => 'square', ), 'showName' => array( 'type' => 'boolean', 'default' => true, ), 'showTitle' => array( 'type' => 'boolean', 'default' => true, ), 'showDescription' => array( 'type' => 'boolean', 'default' => true, ), 'showViewPosts' => array( 'type' => 'boolean', 'default' => true, ), 'showWebsite' => array( 'type' => 'boolean', 'default' => true, ), 'user_id' => array( 'type' => 'number', 'default' => 0, ), 'socialFacebook' => array( 'type' => 'string', 'default' => '', ), 'socialTwitter' => array( 'type' => 'string', 'default' => '', ), 'socialYouTube' => array( 'type' => 'string', 'default' => '', ), 'socialLinkedIn' => array( 'type' => 'string', 'default' => '', ), 'socialWordPress' => array( 'type' => 'string', 'default' => '', ), 'socialGitHub' => array( 'type' => 'string', 'default' => '', ), 'socialPinterest' => array( 'type' => 'string', 'default' => '', ), 'socialInstagram' => array( 'type' => 'string', 'default' => '', ), 'website' => array( 'type' => 'string', 'default' => '', ), 'socialMediaOptions' => array( 'type' => 'string', 'default' => 'colors', ), 'socialMediaColors' => array( 'type' => 'string', 'default' => '#000000', ), 'tabbedAuthorProfile' => array( 'type' => 'string', 'default' => __( 'Author Details', 'metronet-profile-picture' ), ), 'tabbedAuthorProfileHeading' => array( 'type' => 'string', 'default' => __( 'Author Details', 'metronet-profile-picture' ), ), 'tabbedAuthorLatestPosts' => array( 'type' => 'string', 'default' => __( 'Latest Posts', 'metronet-profile-picture' ), ), 'tabbedAuthorSubHeading' => array( 'type' => 'string', 'default' => '', ), 'tabbedAuthorProfileTitle' => array( 'type' => 'string', 'default' => '', ), 'profileTabHeadlineColor' => array( 'type' => 'string', 'default' => '#42737b', ), 'profileTabColor' => array( 'type' => 'string', 'default' => '#42737b', ), 'profileTabPostsColor' => array( 'type' => 'string', 'default' => '#30424b', ), 'profileTabHeadlineTextColor' => array( 'type' => 'string', 'default' => '#FFFFFF', ), 'profileTabTextColor' => array( 'type' => 'string', 'default' => '#FFFFFF', ), 'profileTabPostsTextColor' => array( 'type' => 'string', 'default' => '#FFFFFF', ), 'profileLatestPostsOptionsValue' => array( 'type' => 'string', 'default' => 'light', ), 'profileCompactAlignment' => array( 'type' => 'string', 'default' => 'center', ), 'showPostsWidth' => array( 'type' => 'string', 'default' => '', ), 'showSocialMedia' => array( 'type' => 'boolean', 'default' => true, ), 'profileName' => array( 'type' => 'string', 'default' => '', ), ), 'render_callback' => array( $this, 'display_frontend' ), 'editor_script' => 'mpp_gutenberg', ) ); } /** * Display the front-end for the Gutenberg block. * * @param array $attributes Array of block attributes. */ public function display_frontend( $attributes ) { if ( is_admin() ) { return; } ob_start(); if ( empty( $attributes['profileImgURL'] ) ) { $attributes['profileImgURL'] = wp_get_attachment_image_url( $attributes['profileImgID'], 'thumbnail', false, '' ); } ?>
avatar

0 ) : ?>

avatar

avatar
get_social_icons( $attributes ); // phpcs:ignore ?>
get_social_icons( $attributes ); // phpcs:ignore ?>
avatar
' . wp_kses_post( $attributes['tabbedAuthorProfileTitle'] ) . '
'; ?>

'post', 'post_status' => 'publish', 'author' => $user_id, 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => 5, ); $posts = get_posts( $args ); ?>
load_gutenblock_svgs(); return ob_get_clean(); } /** * Get the social icons for the block. * * @param array $attributes Gutenberg attributes. */ public function get_social_icons( $attributes ) { ob_start(); ?>
'; require $svg_icons; echo ''; } } } /** * Add Gutenberg scripts. */ public function add_gutenberg_scripts() { wp_enqueue_script( 'mpp_gutenberg', Metronet_Profile_Picture::get_plugin_url( 'dist/blocks.build.js' ), array( 'wp-blocks', 'wp-element' ), METRONET_PROFILE_PICTURE_VERSION, true ); /* For the Gutenberg plugin */ if ( function_exists( 'wp_set_script_translations' ) ) { wp_set_script_translations( 'mpp_gutenberg', 'metronet-profile-picture' ); } elseif ( function_exists( 'gutenberg_get_jed_locale_data' ) ) { $locale = gutenberg_get_jed_locale_data( 'metronet-profile-picture' ); $content = 'wp.i18n.setLocaleData( ' . wp_json_encode( $locale ) . ', "post-type-archive-mapping" );'; wp_script_add_data( 'mpp_gutenberg', 'data', $content ); } elseif ( function_exists( 'wp_get_jed_locale_data' ) ) { /* for 5.0 */ $locale = wp_get_jed_locale_data( 'metronet-profile-picture' ); $content = 'wp.i18n.setLocaleData( ' . $locale . ', "metronet-profile-picture" );'; wp_script_add_data( 'mpp_gutenberg', 'data', $content ); } // Pass in REST URL. wp_localize_script( 'mpp_gutenberg', 'mpp_gutenberg', array( 'rest_url' => esc_url( rest_url( 'mpp/v2' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'mystery_man' => Metronet_Profile_Picture::get_plugin_url( 'img/mystery.png' ), ) ); wp_enqueue_style( 'mpp_gutenberg', Metronet_Profile_Picture::get_plugin_url( '/dist/blocks.editor.build.css' ), array(), METRONET_PROFILE_PICTURE_VERSION, 'all' ); } /** * Add Gutenberg styles. */ public function add_gutenberg_styles() { if ( is_admin() ) { return; } // Ensure script debug allows non-minified scripts. wp_enqueue_style( 'mpp_gutenberg', Metronet_Profile_Picture::get_plugin_url( '/dist/blocks.style.build.css' ), array(), METRONET_PROFILE_PICTURE_VERSION, 'all' ); wp_enqueue_script( 'mpp_gutenberg_tabs', Metronet_Profile_Picture::get_plugin_url( 'js/mpp-frontend.js' ), array( 'jquery' ), METRONET_PROFILE_PICTURE_VERSION, true ); } }