register(); } /** * Whether ACF (free or Pro) or SCF is loaded. * * @return bool */ public static function fields_plugin_active(): bool { return function_exists( 'acf_get_field_group' ) && function_exists( 'acf_get_fields' ) && function_exists( 'acf_get_setting' ) && function_exists( 'get_field' ); } /** * Adds "Rate it" to the row of this plugin on the Plugins screens (plugin_row_meta). * * @param mixed $links Links under the description of the plugin. * @param string $file Plugin file, relative to the plugins folder. * @return mixed */ public static function row_meta( $links, $file ) { if ( ! is_array( $links ) || plugin_basename( PLUGIN_FILE ) !== $file ) { return $links; } $links[] = sprintf( '%2$s', esc_url( Field_Code_Box::REVIEW_URL ), esc_html__( 'Rate it', 'antwork-field-code' ) ); return $links; } /** * Hooks a notice on the Plugins screens. * * @param callable $callback Notice renderer. */ private static function add_notice( callable $callback ): void { $render = static function () use ( $callback ) { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || ! in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) ) { return; } if ( ! current_user_can( 'activate_plugins' ) ) { return; } call_user_func( $callback ); }; add_action( 'admin_notices', $render ); add_action( 'network_admin_notices', $render ); } /** * Notice: neither ACF nor SCF is active. */ public static function notice_missing_fields_plugin(): void { printf( '

%s

', esc_html__( 'Antwork Field Code needs Advanced Custom Fields (free or Pro) or Secure Custom Fields. Install and activate one of them: until then, it does nothing.', 'antwork-field-code' ) ); } }