how to execute some code after a post is published in WordPress [duplicate]

You’re looking for the save_post action. This allows you to add a function when a post is saved (updated). You can hook into it like this: function your_save_post_function( $post_id ) { } add_action( ‘save_post’, ‘your_save_post_function’ ); Remember to not change WordPress Core files, as these will be overwritten when WordPress is updated. You can put … Read more

dynamic name of the style for wp_enqueue_style

this syntax doesn’t seem right to me. First of all what is ABS_URL? If it’s a constant that you’ve defined earlier, then there is an ‘ missing before /includes/box.css’. The code should look like this: $name=”mystyle”; wp_enqueue_style( $name .’-style’, ABS_URL . ‘/includes/box.css’, false ); It works as it should, the output is: <link rel=”stylesheet” id=’mystyle-style-css’ … Read more

wp_redirect not working on plugin

You can also consider a Javascript solution by adding a portion of code that will redirect people to the page if not loggued in : <?php /* Plugin Name: Héroes y Pasta */ include_once(ABSPATH . ‘wp-admin/includes/plugin.php’); function iniciatodo() { if(is_user_logged_in()) { ?> <p>Hola tio</p> <?php } else { ?> <script>window.location.href=”http://gexy.es.cx/login/”;</script> <?php } } add_shortcode(“inicia_todo”, “iniciatodo”);

Override a Plugin Function

The following code is work around by using the filter in the code above and by returning an empty array. It is placed in functions.php of your theme. It’s not a ‘work around’. That’s the correct way to do it. But there is a shorter way to do the same thing. WordPress has a function … Read more

Asynchronous request in wordpress

Your AJAX URL varaible is different in your PHP and your JS. In your JS you refer to ajax_url: url: modallist.ajax_url, But the variable defined in PHP is ajaxurl: ‘ajaxurl’ => admin_url(‘admin-ajax.php’) , This is why you’re getting the full admin page as a response. Your request is going to the current page because there … Read more