';
switch ( $state ) {
case 'install':
$nonce = wp_nonce_url(
add_query_arg(
array(
'action' => 'install-plugin',
'from' => 'import',
'plugin' => $slug,
),
network_admin_url( 'update.php' )
),
'install-plugin_' . $slug
);
$button .= '
' . __( 'Install and activate', 'lucia' ) . '';
break;
case 'activate':
if ( $slug == 'mailin' ) {
$plugin_link_suffix = $slug . '/sendinblue.php';
} else {
$plugin_link_suffix = $slug . '/' . $slug . '.php';
}
$nonce = add_query_arg(
array(
'action' => 'activate',
'plugin' => rawurlencode( $plugin_link_suffix ),
'plugin_status' => 'all',
'paged' => '1',
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin_link_suffix ),
), admin_url( 'plugins.php' )
);
$button .= '
' . __( 'Activate', 'lucia' ) . '';
break;
}// End switch().
$button .= '
';
}// End if().
return $button;
}
/**
* Check plugin state.
*
* @param string $slug plugin slug.
*
* @return bool
*/
public function check_plugin_state( $slug ) {
if ( file_exists( ABSPATH . 'wp-content/plugins/' . $slug . '/' . $slug . '.php' ) || file_exists( ABSPATH . 'wp-content/plugins/' . $slug . '/index.php' ) ) {
$needs = ( is_plugin_active( $slug . '/' . $slug . '.php' ) || is_plugin_active( $slug . '/index.php' ) || is_plugin_active( $slug . '/sendinblue.php' ) ) ? 'deactivate' : 'activate';
return $needs;
} else {
return 'install';
}
}
/**
* Enqueue Function.
*/
public static function enqueue_scripts() {
wp_enqueue_script( 'plugin-install' );
wp_enqueue_script( 'updates' );
wp_enqueue_script( 'lucia-plugin-install-helper', get_template_directory_uri() . '/inc/plugin-install/js/plugin-install.js', array( 'jquery' ), '', true );
wp_localize_script(
'lucia-plugin-install-helper', 'lucia_plugin_helper',
array(
'activating' => esc_html__( 'Activating ', 'lucia' ),
)
);
wp_localize_script(
'lucia-plugin-install-helper', 'pagenow',
array( 'import' )
);
}
}