define_constants(); $this->includes(); $this->init_hooks(); } /** * Hook into actions and filters. * @since 1.0 */ private function init_hooks() { register_activation_hook( __FILE__, array( $this, 'admin_activation_notice' ) ); add_action( 'admin_notices', array( $this, 'admin_hook_notice' ) ); add_filter('acf/fields/flexible_content/layout_title', array( $this, 'acf_fclt' ), 10, 4); } /** * Define acf_fcl Constants. */ private function define_constants() { $this->define( 'FCL_ABSURL', plugins_url( '/', __FILE__ ) ); $this->define( 'FCL_ABSPATH', dirname( __FILE__ ) . '/' ); $this->define( 'FCL_VERSION', $this->version ); } /** * Define constant if not already set. * * @param string $name * @param string|bool $value */ private function define( $name, $value ) { if ( ! defined( $name ) ) { define( $name, $value ); } } /** * What type of request is this? * * @param string $type admin, ajax, cron or frontend. * @return bool */ private function is_request( $type ) { switch ( $type ) { case 'admin' : return is_admin(); case 'ajax' : return defined( 'DOING_AJAX' ); case 'cron' : return defined( 'DOING_CRON' ); case 'frontend' : return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ); } } /** * Include required core files used in admin. */ public function includes() { if ( $this->is_request( 'admin' ) ) { include_once( FCL_ABSPATH . 'includes/class-meta-boxes.php' ); include_once( FCL_ABSPATH . 'includes/class-menus.php' ); include_once( FCL_ABSPATH . 'includes/class-admin-page.php' ); } } /** * Add Notice if exist error when plugin activation. */ public function admin_activation_notice() { add_action( 'admin_notices', array( $this, 'admin_hook_notice' ) ); } /** * Add Notice if exist error. */ public function admin_hook_notice() { if ( ! function_exists('acf_get_field_groups') ) { global $pagenow; if ( $pagenow == 'plugins.php' ) : ?>

Error: Plugin ACF Flexible Content Layout Thumbnail can not work without plugin Advanced Custom Fields PRO.
Advanced Custom Fields PRO plugin is not active, please activate the plugin!', 'error' ); ?>

Advanced Custom Fields PRO plugin is not active, please activate the plugin!'; add_settings_error( 'acf_fcl_notice', 'acf_fcl_notice', $message, 'error' ); endif; } } /** * Check if there is a required function. */ public function check_exist_acf() { if ( ! function_exists('acf_get_field_groups') ) { return true; } return false; } /** * Adding data to the header flexible content section */ public function acf_fclt( $title, $field, $layout, $i ) { $layoutImages = acf_fcl_meta_boxes::get_data(); if ( array_key_exists( $layout['key'], $layoutImages ) ) { $image = wp_get_attachment_image_src( $layoutImages[$layout['key']], 'full' ); if ( isset( $image[0] ) && !empty( $image[0] ) ) { $title .= ''; $title .= ''; $title .= ''; } } return $title; } } endif; /** * Main instance of acf_fcl_instance. * * Returns the main instance of acf_fcl_instance to prevent the need to use globals. * * @since 1.0 * @return acf_fcl */ function acf_fcl_instance() { return acf_fcl::instance(); } // Global for backwards compatibility. $GLOBALS['acf_fcl'] = acf_fcl_instance();