Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS hack: always mark the plugin as activated #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions plugins/apc-cache/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,43 @@
yourls_add_filter( 'activated_plugin', 'apc_cache_plugin_statechange' );
yourls_add_filter( 'deactivated_plugin', 'apc_cache_plugin_statechange' );
yourls_add_filter( 'edit_link', 'apc_cache_edit_link' );
yourls_add_action( 'html_footer', 'apc_cache_add_plugin_to_list' );

/**
* Inject plugin in the Plugins management table
*
* @param array $args context, as passed by action 'html_footer'
*/
function apc_cache_add_plugin_to_list( $args ){
// Check we're on the right page
if( $args[0] != 'plugins' )
return;

// Modify the plugin's row

$action_url = "javascript:alert(\"To deactivate, please delete or rename file \'/user/cache.php\'\")";
$action_anchor = yourls__( 'Deactivate' );

echo <<<SCRIPT
<script>
// Identify APC Cache row
$('#main_table tr').filter(function(index) {
if( $(this).find("td a").eq(0).html() == 'APC Cache' ) {
$(this).find("td a").eq(0).closest('tr').attr('id','apc_cache_hack');
return 1;
}
});

// Mark plugin as active, add message about deactivation
$('#apc_cache_hack').removeClass('inactive').addClass('active');
$('#apc_cache_hack td.plugin_actions a').attr('href', '$action_url').html( '$action_anchor' );

// Increment active plugin count
$('#plugin_summary strong+strong').html( parseInt( $('#plugin_summary strong+strong').html() )+1 );

</script>
SCRIPT;
}

/**
* Return cached options is available
Expand Down