<?php
/**
 * @package Make Builder
 */

/**
 * Custom plugin row actions definitions.
 *
 * @since 1.0.0
 */
$plugin_actions = array(
	'upgrade' => array(
		'uri' => 'https://thethemefoundry.com/wordpress-plugins/make-builder/',
		'label' => 'Upgrade to Make Plus',
		'color' => '#46b450',
	),

	'help' => array(
		'uri' => 'https://thethemefoundry.com/docs/make-docs/',
		'label' => 'Help guide',
		'color' => '#0073aa',
	),
);

function make_builder_is_plus_active() {
	return defined( 'MAKEPLUS_VERSION' );
}

/**
 * Add the Help link to the plugin row.
 *
 * @since 1.0.0
 *
 * @hooked filter plugin_row_meta
 *
 * @return array           Modified plugin row meta.
 */
function make_builder_plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) {
	if ( make_get_plugin_basename() === $plugin_file ) {
		global $plugin_actions;
		extract( $plugin_actions['help'] );

		$plugin_meta[ count( $plugin_meta ) ] = '<a href="' . $uri . '" title="' . esc_attr__( $label, 'make-builder' ) . '" style="color:' . $color . ';" target="_blank">' . __( $label, 'make-builder' ) . '</a>';
	}

	return $plugin_meta;
}

add_filter( 'plugin_row_meta', 'make_builder_plugin_row_meta', 10, 4 );

/**
 * Add upgrade action to the plugin row.
 *
 * @since 1.0.0
 *
 * @hooked filter plugin_action_links
 *
 * @return array           Modified plugin row meta.
 */
function make_builder_plugin_action_links( $actions, $plugin_file ) {
	if ( make_get_plugin_basename() === $plugin_file && ! make_builder_is_plus_active() ) {
		global $plugin_actions;
		extract( $plugin_actions['upgrade'] );

		$actions[] = '<a href="' . $uri . '" title="' . esc_attr__( $label, 'make-builder' ) . '" style="color:' . $color . ';" target="_blank">' . __( $label, 'make-builder' ) . '</a>';
	}

	return $actions;
}

add_filter( 'plugin_action_links', 'make_builder_plugin_action_links', 10, 2 );
