ap_get_addons()

Description #

Get all AnsPress add-ons data.

Changelog #

VersionDescription
4.1.8Introduced.

Source #

File: includes/functions.php

function ap_get_addons() {
	$cache  = wp_cache_get( 'addons', 'anspress' );
	$option = get_option( 'anspress_addons', array() );

	if ( false !== $cache ) {
		return $cache;
	}

	$all_files = array();
	foreach ( array( 'pro', 'free' ) as $folder ) {
		$path = ANSPRESS_ADDONS_DIR . DS . $folder;

		if ( file_exists( $path ) ) {
			$files = scandir( $path );

			foreach ( $files as $file ) {
				$ext = pathinfo( $file, PATHINFO_EXTENSION );

				if ( 'php' === $ext ) {
					$all_files[] = $folder . DS . $file;
				}
			}
		}
	}

	$addons = array(
		'email.php'             => array(
			'name'        => __( 'Emails', 'anspress-question-answer' ),
			'description' => __( 'Notifies users and admins by email for various events and activities.', 'anspress-question-answer' ),
		),
		'categories.php'        => array(
			'name'        => __( 'Categories', 'anspress-question-answer' ),
			'description' => __( 'Add category support in AnsPress questions.', 'anspress-question-answer' ),
		),
		'notifications.php'     => array(
			'name'        => __( 'Notifications', 'anspress-question-answer' ),
			'description' => __( 'Adds a fancy user notification dropdown like Facebook and Stackoverflow.', 'anspress-question-answer' ),
		),
		'tags.php'              => array(
			'name'        => __( 'Tags', 'anspress-question-answer' ),
			'description' => __( 'Add tag support in AnsPress questions.', 'anspress-question-answer' ),
		),
		'reputation.php'        => array(
			'name'        => __( 'Reputation', 'anspress-question-answer' ),
			'description' => __( 'Award points to user based on activities.', 'anspress-question-answer' ),
		),
		'buddypress.php'        => array(
			'name'        => __( 'BuddyPress', 'anspress-question-answer' ),
			'description' => __( 'Integrate AnsPress with BuddyPress.', 'anspress-question-answer' ),
		),
		'profile.php'           => array(
			'name'        => __( 'User Profile', 'anspress-question-answer' ),
			'description' => __( 'User profile for users.', 'anspress-question-answer' ),
		),
		'recaptcha.php'         => array(
			'name'        => __( 'reCaptcha', 'anspress-question-answer' ),
			'description' => __( 'Add reCaptcha verification in question, answer and comment forms.', 'anspress-question-answer' ),
		),
		'syntaxhighlighter.php' => array(
			'name'        => __( 'Syntax Highlighter', 'anspress-question-answer' ),
			'description' => __( 'Add syntax highlighter support.', 'anspress-question-answer' ),
		),
		'akismet.php'           => array(
			'name'        => __( 'Akismet Check', 'anspress-question-answer' ),
			'description' => __( 'Check for spam in post content.', 'anspress-question-answer' ),
		),
	);

	/**
	 * This hooks can be used to filter existing addons or for adding new addons.
	 *
	 * @since 4.1.8
	 */
	$addons = apply_filters( 'ap_addons', $addons );

	$valid_addons = array();
	foreach ( (array) $addons as $k => $addon ) {
		$path  = ANSPRESS_ADDONS_DIR . DS . basename( $k, '.php' ) . DS . $k;
		$path2 = ANSPRESS_ADDONS_DIR . DS . $k;

		$addons[ $k ]['path'] = '';

		if ( isset( $addon['path'] ) && file_exists( $addon['path'] ) ) {
			$addons[ $k ]['path'] = wp_normalize_path( $addon['path'] );
		} elseif ( file_exists( $path ) ) {
			$addons[ $k ]['path'] = wp_normalize_path( $path );
		} elseif ( file_exists( $path2 ) ) {
			$addons[ $k ]['path'] = wp_normalize_path( $path2 );
		}

		$addons[ $k ]['pro']    = isset( $addon['pro'] ) ? $addon['pro'] : false;
		$addons[ $k ]['active'] = isset( $option[ $k ] ) ? true : false;
		$addons[ $k ]['id']     = $k;
		$addons[ $k ]['class']  = sanitize_html_class( sanitize_title( str_replace( array( '/', '.php' ), array( '-', '' ), 'addon-' . $k ) ) );

		if ( ! empty( $addons[ $k ]['path'] ) && file_exists( $addons[ $k ]['path'] ) ) {
			$valid_addons[ $k ] = $addons[ $k ];
		}
	}

	wp_cache_set( 'addons', $valid_addons, 'anspress' );
	return $valid_addons;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment