plugin_path = $plugin_path; tribe_notice( plugin_basename( $plugin_path ), array( $this, 'show_inactive_plugins_alert' ) ); } /** * Add a required plugin to the notice * * @param string $name Name of the required plugin * @param null $thickbox_url Download or purchase URL for plugin from within /wp-admin/ thickbox * @param bool $is_active Indicates if the plugin is installed and active or not */ public function add_required_plugin( $name, $thickbox_url = null, $is_active = null ) { $this->plugins_required[ $name ] = array( 'name' => $name, 'thickbox_url' => $thickbox_url, 'is_active' => $is_active, ); } /** * Echoes the admin notice, attach to admin_notices */ public function show_inactive_plugins_alert() { if ( ! current_user_can( 'activate_plugins' ) ) { return; } $plugin_data = get_plugin_data( $this->plugin_path ); $req_plugins = array(); foreach ( $this->plugins_required as $req_plugin ) { $item = esc_html( $req_plugin['name'] ); if ( ! empty( $req_plugin['thickbox_url'] ) ) { $item = sprintf( '%3$s', esc_attr( $req_plugin['thickbox_url'] ), esc_attr( $req_plugin['name'] ), $item ); } if ( false === $req_plugin['is_active'] ) { $item = sprintf( '%1$s', $item ); } $req_plugins[] = $item; } printf( '

' . esc_html__( 'To begin using %1$s, please install and activate the latest version of %2$s.', 'tribe-common' ) . '

', $plugin_data['Name'], $this->implode_with_grammar( $req_plugins ) ); } /** * Implodes a list items using 'and' as the final separator and a comma everywhere else * * @param array $items List of items to implode * * @return string String of items */ public function implode_with_grammar( $items ) { $separator = _x( ', ', 'separator used in a list of items', 'tribe-common' ); $conjunction = _x( ' and ', 'the final separator in a list of two or more items', 'tribe-common' ); $output = $last_item = array_pop( $items ); if ( $items ) { $output = implode( $separator, $items ) . $conjunction . $last_item; } return $output; } }