Created
August 29, 2018 23:53
-
-
Save JMWebDevelopment/c49af73190f6033374c5ae8a3d19c5a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JM_Portfolio_Blocks { | |
protected $loader; | |
protected $directory_location; | |
public function __construct() { | |
$this->directory_location = str_replace( '/blocks/', '', dirname( __FILE__ ) ); | |
} | |
public function jm_portfolio_add_scripts() { | |
// Make paths variables so we don't write em twice ;) | |
$blockPath = 'js/editor.blocks.js'; | |
$editorStylePath = 'css/blocks.editor.css'; | |
$image_id = get_field( 'small_business_newsletter_photo', 'option' ); | |
$image_url = wp_get_attachment_url( $image_id ); | |
$image_alt_text = get_post_meta($image_id , '_wp_attachment_image_alt', true); | |
// Enqueue the bundled block JS file | |
wp_enqueue_script( | |
'jm-portfolio-blocks-js', | |
plugins_url( $blockPath, __FILE__ ), | |
[ 'wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-api' ], | |
filemtime( plugin_dir_path(__FILE__) . 'js/editor.blocks.js' ) | |
); | |
// Pass in REST URL | |
wp_localize_script( | |
'jm-portfolio-blocks-js', | |
'jm_portfolio_globals', | |
array( | |
'rest_url' => esc_url( rest_url() ), | |
'nonce' => wp_create_nonce( 'wp_rest' ), | |
'small_business_default_background' => array( | |
'image_url' => $image_url, | |
'image_id' => $image_id, | |
'image_alt' => $image_alt_text | |
) | |
)); | |
// Enqueue optional editor only styles | |
wp_enqueue_style( | |
'jsforwp-blocks-editor-css', | |
plugins_url( $editorStylePath, __FILE__), | |
[ 'wp-blocks' ], | |
filemtime( plugin_dir_path( __FILE__ ) . $editorStylePath ) | |
); | |
} | |
public function jm_enqueue_front_end_assets() { | |
$style_path = 'css/blocks.style.css'; | |
wp_enqueue_style( | |
'jsforwp-blocks', | |
plugins_url( $style_path, __FILE__ ), | |
[ 'wp-blocks' ], | |
filemtime( plugin_dir_path( __FILE__ ) . $style_path ) | |
); | |
} | |
public function jm_portfolio_add_blocks() { | |
register_block_type( 'jm-portfolio/small-business-newsletter-signup', [ | |
'render_callback' => array( $this, 'jm_small_business_newsletter_render' ), | |
] ); | |
register_block_type( 'jm-portfolio/web-development-newsletter-signup', [ | |
'render_callback' => array( $this, 'jm_web_development_newsletter_render' ), | |
] ); | |
register_block_type( 'jm-portfolio/featured-video', [ | |
'render_callback' => array( $this, 'jm_featured_video_render' ), | |
] ); | |
register_block_type( 'jm-portfolio/featured-item', [ | |
'render_callback' => array( $this, 'jm_featured_item_render' ), | |
] ); | |
} | |
public function jm_small_business_newsletter_render( $attributes ) { | |
$html = ''; | |
$image = get_field( 'small_business_newsletter_photo', 'option' ); | |
$image = wp_get_attachment_url( $image ); | |
$html .= '<div class="small-business-newsletter-sign-up row" style="background: -moz-linear-gradient(top, rgba(27,25,48,.85) 0%, rgba(27,25,48,.85) 100%), url(' . $image . '); background: -webkit-linear-gradient(top, rgba(27,25,48,.85) 0%, rgba(27,25,48,.85) 100%), url(' . $image . '); background: linear-gradient(to bottom, rgba(27,25,48,.85) 0%, rgba(27,25,48,.85) 100%), url(' . $image . '); background-color: #1B1930; background-position-x: center; background-position-y: center; background-repeat: no-repeat; background-size: cover;">'; | |
$html .= '<div class="large-12 columns">'; | |
$html .= '<h2 class="small-business-newsletter-sign-up-title">' . get_field( 'small_business_newsletter_title', 'option' ) . '</h2>'; | |
$html .= apply_filters( 'the_content', get_field( 'small_business_newsletter_description', 'option' ) ); | |
$html .= do_shortcode( '[gravityform id="' . get_field( 'small_business_newsletter_form', 'option' ) . '" title="false" description="false" ajax="true"]' ); | |
$html .= '</div>'; | |
$html .= '</div>'; | |
return $html; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment